~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/pvm/pvm_send.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 1997 by Inria Lorraine.  All Rights Reserved */
 
2
 
 
3
/***
 
4
   NAME
 
5
     pvm_send
 
6
   PURPOSE
 
7
     pvm_send envoie une var scilab 
 
8
   NOTES
 
9
     Pour chaque variable on envoie:
 
10
        - n: size of the pack array
 
11
        - p: pack array vect: (real,int)+
 
12
        - v: the variable.
 
13
   HISTORY
 
14
     fleury - Nov 19, 1997: Created.
 
15
     $Id: pvm_send.c,v 1.12 1998/04/03 11:41:02 fleury Exp $
 
16
***/
 
17
#include <stdio.h>
 
18
#include <stdlib.h>
 
19
#include <string.h>
 
20
#include "pvm3.h"
 
21
#include "../machine.h"
 
22
#include "../stack-c.h"
 
23
 
 
24
#include "../calelm/sci_tools.h"
 
25
 
 
26
#ifdef __STDC__
 
27
void 
 
28
C2F(scipvmsend)(int *tids, int *p, 
 
29
                int *pack, int *n, 
 
30
                double *buff,
 
31
                int *msgtag, int *res)
 
32
#else
 
33
void 
 
34
C2F(scipvmsend)(tids, p, pack, n, buff, msgtag, res)
 
35
  int *tids;
 
36
  int *p;
 
37
  int *pack;
 
38
  int *n;
 
39
  double *buff;
 
40
  int *msgtag;
 
41
  int *res;
 
42
#endif 
 
43
 
 
44
{
 
45
  int info, bufid;
 
46
  double *ptr_double;
 
47
  int *ptr_int;
 
48
  int i;
 
49
 
 
50
#ifdef DEBUG
 
51
  (void) fprintf(stdout, "SEND: %d:%d:%d:%d:%d:%d:%p:%f:%f:%f:%f:%f:%f:%f\n", 
 
52
                 *tids, *p, *n, *msgtag, pack[0], pack[1], buff, 
 
53
                 buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6]);
 
54
  
 
55
  (void) fprintf(stderr, "SEND:");
 
56
  for (i = 0; i < *n; ++i) {
 
57
    (void) fprintf(stderr, "%3d:", pack[i]);
 
58
  }
 
59
  (void) fprintf(stderr, "\n");
 
60
#endif /* DEBUG */
 
61
 
 
62
  bufid = pvm_initsend(PvmDataDefault);
 
63
  if (bufid < 0) {
 
64
    (void) fprintf(stderr, "Error pvm_send - init: %d\n", bufid);
 
65
    *res = bufid;
 
66
    return;
 
67
  }
 
68
  /* Pack the size of the packing vector */
 
69
  info = pvm_pkint(n, 1, 1);
 
70
  if (info < 0) {
 
71
    (void) fprintf(stderr, "Error pvm_send: -pack- %d\n", info);
 
72
    pvm_freebuf(bufid);
 
73
    *res = info;
 
74
    return;
 
75
  }
 
76
  /* Pack the packing vector */
 
77
  info = pvm_pkint(pack, *n, 1);
 
78
  if (info < 0) {
 
79
    (void) fprintf(stderr, "Error pvm_send: -pack- %d\n", info);
 
80
    pvm_freebuf(bufid);
 
81
    *res = info;
 
82
    return;
 
83
  }
 
84
  
 
85
  /* Pack the msg using the packing vector info */
 
86
  ptr_double = buff;
 
87
  ptr_int = (int*) buff;
 
88
 
 
89
  for (i = 0; i < *n; i+=2) {
 
90
    if (pack[i] > 0) {          /* have to pack some int */
 
91
      info = pvm_pkint(ptr_int, pack[i], 1);
 
92
      if (info < 0) {
 
93
        (void) fprintf(stderr, "Error pvm_send: -pack- %d\n", info);
 
94
        pvm_freebuf(bufid);
 
95
        *res = info;
 
96
        return;
 
97
      }
 
98
 
 
99
#ifdef DEBUG
 
100
      {
 
101
        int tmp_i;
 
102
        for (tmp_i = 0; tmp_i < pack[i]; ++tmp_i) {
 
103
          (void) fprintf(stderr, "%d:", ptr_int[tmp_i]);
 
104
        }
 
105
      }
 
106
#endif /* DEBUG */
 
107
 
 
108
      ptr_int += pack[i] + (pack[i] % 2);
 
109
      ptr_double += ((pack[i]-1)/2 + 1);
 
110
    }
 
111
    if (pack[i+1] > 0) {        /* have to pack some double */
 
112
      info = pvm_pkdouble(ptr_double, pack[i+1], 1);
 
113
      if (info < 0) {
 
114
        (void) fprintf(stderr, "Error pvm_send: -pack- %d\n", info);
 
115
        pvm_freebuf(bufid);
 
116
        *res = info;
 
117
        return;
 
118
      }
 
119
 
 
120
#ifdef DEBUG
 
121
      {
 
122
        int tmp_i;
 
123
        for (tmp_i = 0; tmp_i < pack[i+1]; ++tmp_i) {
 
124
          (void) fprintf(stderr, "%f:", ptr_double[tmp_i]);
 
125
        }
 
126
      }
 
127
#endif /* DEBUG */
 
128
 
 
129
      ptr_int += (pack[i+1]*2);
 
130
      ptr_double += pack[i+1];
 
131
    }
 
132
  }
 
133
 
 
134
#ifdef DEBUG
 
135
  (void) fprintf(stderr, "\n");
 
136
#endif /* DEBUG */
 
137
 
 
138
  if (*p == 1) {
 
139
    *res = pvm_send(tids[0], *msgtag);
 
140
  }
 
141
  else
 
142
    *res = pvm_mcast(tids, *p, *msgtag);
 
143
} /* scipvmsend */
 
144
 
 
145
 
 
146
 
 
147
#ifdef __STDC__
 
148
void 
 
149
C2F(scipvmsendvar)(int *tids, int *p, char *buff, 
 
150
                   int *msgtag, int *res)
 
151
#else
 
152
void 
 
153
C2F(scipvmsendvar)(tids, p, buff, msgtag, res)
 
154
  int *tids;
 
155
  int *p;
 
156
  char *buff;
 
157
  int *msgtag;
 
158
  int *res;
 
159
#endif 
 
160
{
 
161
  int info, bufid, type;
 
162
  int mx, nx, type_x, ptr_x;
 
163
 
 
164
 
 
165
  F2C(mycmatptr)(buff, &mx, &nx, &type_x, &ptr_x);
 
166
 
 
167
  bufid = pvm_initsend(PvmDataDefault);
 
168
  if (bufid < 0) {
 
169
    (void) fprintf(stderr, "Error pvm_send_var - init: %d\n", bufid);
 
170
    pvm_freebuf(bufid);
 
171
    *res = bufid;
 
172
    return;
 
173
  }
 
174
  info = pvm_pkint(&mx, 1, 1);
 
175
  if (info < 0) {
 
176
    (void) fprintf(stderr, "Error pvm_send_var: -pack- %d\n", info);
 
177
    pvm_freebuf(bufid);
 
178
    *res = info;
 
179
    return;
 
180
  }
 
181
  info = pvm_pkint(&nx, 1, 1);
 
182
  if (info < 0) {
 
183
    (void) fprintf(stderr, "Error pvm_send_var: -pack- %d\n", info);
 
184
    pvm_freebuf(bufid);
 
185
    *res = info;
 
186
    return;
 
187
  }
 
188
  if (type_x == TYPE_COMPLEX) {
 
189
    type = TYPE_COMPLEX;
 
190
    info = pvm_pkint(&type, 1, 1);
 
191
    if (info < 0) {
 
192
      (void) fprintf(stderr, "Error pvm_send_var: -pack- %d\n", info);
 
193
      pvm_freebuf(bufid);
 
194
      *res = info;
 
195
      return;
 
196
    }
 
197
    info = pvm_pkdcplx(stk(ptr_x), mx * nx, 1);
 
198
    if (info < 0) {
 
199
      (void) fprintf(stderr, "Error pvm_send_var: -pack- %d\n", info);
 
200
      pvm_freebuf(bufid);
 
201
      *res = info;
 
202
      return;
 
203
    }
 
204
  } else {    
 
205
    type = TYPE_DOUBLE;
 
206
    info = pvm_pkint(&type, 1, 1);
 
207
    if (info < 0) {
 
208
      (void) fprintf(stderr, "Error pvm_send_var: -pack- %d\n", info);
 
209
      pvm_freebuf(bufid);
 
210
      *res = info;
 
211
      return;
 
212
    }
 
213
    info = pvm_pkdouble(stk(ptr_x), mx * nx, 1);
 
214
    if (info < 0) {
 
215
      (void) fprintf(stderr, "Error pvm_send_var: -pack- %d\n", info);
 
216
      pvm_freebuf(bufid);
 
217
      *res = info;
 
218
      return;
 
219
    }
 
220
  }
 
221
  
 
222
  if (*p == 1)
 
223
    *res = pvm_send(tids[0], *msgtag);
 
224
  else
 
225
    *res = pvm_mcast(tids, *p, *msgtag);
 
226
} /* scipvmsendvar */