File: pvm_recv.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (234 lines) | stat: -rw-r--r-- 5,486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* Copyright (c) 1997 by Inria Lorraine.  All Rights Reserved */

/***
   NAME
     pvm_recv
   PURPOSE
     
   NOTES
     
   HISTORY
     fleury - Nov 19, 1997: Created.
     $Id: pvm_recv.c,v 1.8 2005/10/22 18:53:10 cornet Exp $
***/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
  #include "../../pvm3/include/pvm3.h"
#else
  #include "pvm3.h"
#endif
#include "../machine.h"
#include "../stack-c.h"
#include "../calelm/sci_tools.h"
#include "sci_pvm.h"

#ifdef WIN32
#include "../os_specific/win_mem_alloc.h" /* MALLOC */
#else
#include "../os_specific/sci_mem_alloc.h" /* MALLOC */
#endif

void C2F(scipvmrecv)(double *beginvar, int *maxsize, int *size,
		     int *tid,  int *tag, int *res)
{
  int bufid;
  int info;
  int msgbyte, msgtag, msgtid, buffsize;
  int i;
  int n;
  int *pack;
  int *ptr_int;
  double *ptr_double;

#ifdef DEBUG
  printf("pvm_recv: %f:%d:%d:%d\n", beginvar[0], *maxsize, *tid, *tag);  
#endif /* DEBUG */

  bufid = pvm_recv(*tid, *tag);
  if (bufid < 0) {
    (void) fprintf(stderr, "Error pvm_recv: %d\n", bufid);
    *res = bufid;
    return;
  }
  info = pvm_bufinfo(bufid, &msgbyte, &msgtag, &msgtid);
  if (info < 0) {
    (void) fprintf(stderr, "Error pvm_recv: -bufinfo- %d\n", info);
    pvm_freebuf(bufid);
    *res = info;
    return;
  }

#ifdef DEBUG
  (void) fprintf(stderr, "RECV: %d:%d:%d\n", msgbyte, msgtag, msgtid);
#endif /* DEBUG */

  /* unpack the size of the packing vector */
  info = pvm_upkint(&n, 1, 1);
  if (info < 0) {
    (void) fprintf(stderr, "Error pvm_recv: -pack- %d\n", info);
    pvm_freebuf(bufid);
    *res = info;
    return;
  }

#ifdef DEBUG
  (void) fprintf(stderr, "n=%d\n", n);
#endif /* DEBUG */

  /* unpack the packing vector */
  if ((pack = (int *) MALLOC(n * sizeof(int))) == NULL) {
    (void) fprintf(stderr, "Error malloc in pvm_recv\n");
    pvm_freebuf(bufid);
    *res = PvmNoMem;
    return;
  }
  info = pvm_upkint(pack, n, 1);
  if (info < 0) {
    (void) fprintf(stderr, "Error pvm_recv: -pack- %d\n", info);
    pvm_freebuf(bufid);
    *res = info;
    return;
  }

#ifdef DEBUG
  (void) fprintf(stderr, "RECV:");
  for (i = 0; i < n; ++i) {
    (void) fprintf(stderr, "%3d:", pack[i]);
  }
  (void) fprintf(stderr, "\n");
#endif /* DEBUG */

  msgbyte -= (n + 1)  * sizeof(int); /* on ne tient pas compte de la taille
					du vecteur de pack et de sa
					taille */
  if (msgbyte % sizeof(double)) {
    (void) fprintf(stderr, "Error pvm_recv: not double\n");
    pvm_freebuf(bufid);
    *res = PvmBadMsg;
    return;
  }
  
  buffsize = msgbyte/sizeof(double);

  *size = buffsize;
  if (*size > *maxsize) {
    (void) fprintf(stderr, "Error pvm_recv: Not enough memory: available=%d:needed=%d\n", *maxsize, *size);
    pvm_freebuf(bufid);
    *res = PvmNoMem;
    return;
  }

  /* UnPack the msg using the pack vect info */
  ptr_double = beginvar;
  ptr_int = (int*) beginvar;
  for (i = 0; i < n; i+=2) {
    if (pack[i] > 0) {		/* have to unpack some int */
      info = pvm_upkint(ptr_int, pack[i], 1);
      if (info < 0) {
	(void) fprintf(stderr, "Error pvm_send: -pack- %d\n", info);
	pvm_freebuf(bufid);
	*res = info;
	return;
      }
      ptr_int += pack[i] + (pack[i] % 2);
      ptr_double += ((pack[i]-1)/2 + 1);
    }
    if (pack[i+1] > 0) {	/* have to pack some double */
      info = pvm_upkdouble(ptr_double, pack[i+1], 1);
      if (info < 0) {
	(void) fprintf(stderr, "Error pvm_send: -pack- %d\n", info);
	pvm_freebuf(bufid);
	*res = info;
	return;
      }
      ptr_int += (pack[i+1]*2);
      ptr_double += pack[i+1];
    }
  }
  *res = info;
  *tag = msgtag;
  *tid = msgtid;
  FREE(pack);
} /* scipvmrecv */


void 
#ifdef __STDC__
C2F(scipvmrecvvar)(int *tid,  int *tag, char *buff, int *res)
#else
C2F(scipvmrecvvar)(tid, tag, buff, res)
  int *tid; 
  int *tag;
  char *buff;
  int *res;
#endif 
{
  int bufid;
  int info;
  int msgbyte, msgtag, msgtid;
  int type;
  int mx, nx, type_x, ptr_x, size_x;
  int m, n;

  F2C(mycmatptr)(buff, &mx, &nx, &type_x, &ptr_x);
  
  switch (type_x) 
    {
    case TYPE_DOUBLE :
      size_x = mx * nx * sizeof(double);
      break;
    case TYPE_COMPLEX :
      size_x = mx * nx * sizeof(complex16);
    break;
    default :
      size_x = -1;
      (void) fprintf(stderr, "Error pvm_recv_var: Not scalar type\n");
      *res = PvmBadMsg;
      return;
    }
  bufid = pvm_recv(*tid, *tag);
  if (bufid < 0) {
    (void) fprintf(stderr, "Error pvm_recv: %d\n", bufid);
    *res = bufid;
    return;
  }
  info = pvm_bufinfo(bufid, &msgbyte, &msgtag, &msgtid);
  if (info < 0) {
    (void) fprintf(stderr, "Error pvm_recv: %d\n", info);
    *res = info;
    return;
  }

  msgbyte -= 3 * sizeof(int);   /* on ne tient pas compte de m,n,type */
  
  if (msgbyte != size_x) {
    (void) fprintf(stderr, "Error pvm_recv: size of %s != size of msg\n", 
		   buff);
    pvm_freebuf(bufid);
    *res = PvmNoMem;
    return;
  }
  *res = pvm_upkint(&m, 1, 1);
  *res = pvm_upkint(&n, 1, 1);
  *res = pvm_upkint(&type, 1, 1);
  SET_NB_ROW(stk(ptr_x),m);
  SET_NB_COL(stk(ptr_x),n);
  switch (type) 
    {
    case TYPE_DOUBLE :
      SET_TYPE_DOUBLE(stk(ptr_x));
      *res = pvm_upkdouble(stk(ptr_x), m*n, 1);
      break;
    case TYPE_COMPLEX :
      SET_TYPE_COMPLEX(stk(ptr_x));
      *res = pvm_upkdcplx(stk(ptr_x), m*n, 1);
      break;
    default :
      (void) fprintf(stderr, "Error pvm_recv_var: Not scalar type\n");
      *res = PvmBadMsg;
      return;
    }
} /* scipvmrecvvar */