File: pvm_proc_ctrl.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 (474 lines) | stat: -rw-r--r-- 13,165 bytes parent folder | download | duplicates (2)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
  
/* Copyright (c) 1997 by LIP ENS-LYON.  All Rights Reserved */

/***
   NAME
     pvm_proc_ctrl
   PURPOSE
     PVM Control process
   NOTES
     
   HISTORY
     fleury - Nov 6, 1997: Created.
     $Log: pvm_proc_ctrl.c,v $
     Revision 1.20  2005/10/22 18:53:10  cornet
     update memory management under Windows
     use HeapAlloc and VirtualAlloc (for scilab stack)
     Correction Bug 1576
     n=10000
     xbasc();
     plot2d([0,1],[0,n],0)
     xpols=[zeros(1,n); ones(2,n); zeros(1,n)];
     ypols=[2:n+1; 2:n+1; 1:n; 1:n];
     xfpolys(xpols,ypols,modulo((1:n),32))

     and for windows on PC with 256 mo
     stacksize(5000000*20)
     a=rand(9999,9999)

     Revision 1.19  2005/08/01 11:30:37  cornet
     Remove ABSOFT reference

     Revision 1.18  2005/07/03 18:16:15  cornet
     optimisation des MALLOC pour Windows ( A tester avec attention ) --> VirtualAlloc

     Revision 1.17  2005/07/01 07:08:13  cornet
     replace malloc, free, calloc & realloc by MALLOC,FREE,CALLOC & REALLOC defined in SCI/routines/sci_mem_alloc.h

     Revision 1.16  2005/06/01 09:18:36  chancelier
     error messages

     Revision 1.15  2005/06/01 09:17:24  chancelier
     arguments returned by reduce are not the proper ones

     Revision 1.14  2005/05/27 13:52:29  chancelier
     headers added for Unix

     Revision 1.13  2005/01/07 20:49:25  cornet
     update for compilation via makefiles (windows)

     Revision 1.12  2004/02/28 13:50:09  cornet
     Corrections Warnings

     Revision 1.11  2003/11/04 09:36:06  steer
     back to previous version

     Revision 1.9  2003/10/22 09:03:27  steer
     ifdef added for intel compiler

     Revision 1.8  2002/09/12 12:24:47  chanceli
     updates

     Revision 1.7  2002/07/31 11:35:08  chanceli
     scilex-> scilab for gtk

     Revision 1.6  2002/07/31 06:58:39  chanceli
     changes to spawn scilab and not scilex + fprintf -> sciprint

     Revision 1.5  2002/07/29 14:37:49  chanceli
     vc++

     Revision 1.4  2002/07/25 08:42:44  chanceli
     updates

     Revision 1.3  2002/03/18 12:15:17  steer
     modif Jean-Sebastien Roy pour FreeBSD

     Revision 1.2  2002/02/08 10:27:33  steer
      modifs de mcmahill@mtl.mit.edu

     Revision 1.1.1.1  2001/04/26 07:49:01  scilab
     Imported sources

     Revision 1.16  1999/07/08 21:43:13  fleury
     Modifs relative a pvm_start([hostfile])

     Revision 1.11  1998/04/06 15:29:13  fleury
     ajout de pvm_error

     Revision 1.10  1998/04/03 11:40:59  fleury
     Ajout des commandes pvm_start et pvm_halt
     Correction d'erreurs en version non ANSI
     teste sur alpha et sun
     PBM de link en dynamique sur hpux9

     Revision 1.9  1998/03/27 12:20:12  fleury
     Version pvm OK.
     TODO: faire des tests de compil sur plateforme separee (POPC0
     TODO: commenter source (-;
     TODO: faire un peu de netoyage

     Revision 1.8  1998/03/26 12:33:01  fleury
     Version OK.
     TODO: faire un clean des .c
     TODO: enlever les _ ds les noms de fonctions (f77 compliant)
     TODO: faire des tests et un jeux de tests

     Revision 1.7  1998/03/13 13:57:03  fleury
     Version send/recv avec pack. A tester.
     TODO: ajouter les listes + BROADCAST
     TODO: faire un clean du dir et des fichiers...

     Revision 1.6  1997/12/01 11:08:05  fleury
     Spawn march een version reduite. Ajout de fct
     ds info et control

     Revision 1.5  1997/11/27 14:27:24  fleury
     Version de spawn pas encore au point tant que l on a pas
     scilex -nw -f <script>

     Revision 1.4  1997/11/26 09:51:27  fleury
     Nettoyage des code. LA version marche avec PVM.
     TODO: mettre le spawn de facon elegante !

     Revision 1.3  1997/11/25 11:15:52  fleury
     Ajout des command pvm pour la gestion des groupes.
     Tjs le pbm de TID multiples

     Revision 1.2  1997/11/21 13:59:49  fleury
     Ajout de nouveau fichier pour l'interface Scilab PVM
     modification du Makefile et des variables d'environnement

     Revision 1.1  1997/11/10 15:23:48  fleury
     Premier commit pour les control process PVM

***/

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

#if defined(__EDG__)
#include <time.h>
#endif
#include <sys/stat.h>
#include <signal.h>
#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 "sci_pvm.h"

#ifndef WIN32 
#include <unistd.h>
#endif 


#ifdef WIN32 
#include <sys/utime.h>
#else 
#include <sys/time.h>
#endif /** WIN32 **/

/* stat function */
#if (defined __MSC__) || defined(__MINGW32__) 
#define stat _stat 
#endif 

#include <stdarg.h> 
extern void sciprint_nd (char *fmt,...);
extern void sciprint (char *fmt,...);
extern int pvmendtask(void);

typedef char *strings;

static strings Scipvm_error[]= { 
      "OK",
      "bad parameter",
      "Barrier count mismatch",
      "read past end of buffer",
      "no such host",
      "No such executable",
      "can not get memory",
      "can not decode received msg",
      "daemond pvmd is not responding",
      "no current buffer",
      "bad message id",
      "null group name is illegal",
      "already in group",
      "no group with that name",
      "not in group",
      "no such instance in group",
      "host failed",
      "no parent task",
      "function not implemented",
      "pvmd system error",
      "pvmd-pvmd protocol mismatch",
      "out of ressources",
      "host already configured",
      "failed to exec new slave pvmd",
      "already oing operation",
      "no such task",
      "no such (group,instance)",
      "(group,instance) already exists",
      "Unknow error",
};

/*--------------------------------------------------
 * get error message 
 *--------------------------------------------------*/


extern char *pvm_errlist[];
extern int pvm_nerr;

char *
pvm_geterror(int n)
{
  return (n <= 0 && n > -pvm_nerr ? pvm_errlist[-n] : "Unknown Error");
}

char *scipvm_error_msg(int err)
{
  switch (err)
    {
    case PvmOk:          return Scipvm_error[0];     break;
    case PvmBadParam:    return Scipvm_error[1];     break;
    case PvmMismatch:    return Scipvm_error[2];     break;
    case PvmNoData:      return Scipvm_error[3];     break;
    case PvmNoHost:      return Scipvm_error[4];     break;
    case PvmNoFile:      return Scipvm_error[5];     break;
    case PvmNoMem:       return Scipvm_error[6];     break;
    case PvmBadMsg:      return Scipvm_error[7];     break;
    case PvmSysErr:      return Scipvm_error[8];     break;
    case PvmNoBuf:       return Scipvm_error[9];     break;
    case PvmNoSuchBuf:   return Scipvm_error[10];     break;
    case PvmNullGroup:   return Scipvm_error[11];     break;
    case PvmDupGroup:    return Scipvm_error[12];     break;
    case PvmNoGroup:     return Scipvm_error[13];     break;
    case PvmNotInGroup:  return Scipvm_error[14];     break;
    case PvmNoInst:      return Scipvm_error[15];     break;
    case PvmHostFail:    return Scipvm_error[16];     break;
    case PvmNoParent:    return Scipvm_error[17];     break;
    case PvmNotImpl:     return Scipvm_error[18];     break;
    case PvmDSysErr:     return Scipvm_error[19];     break;
    case PvmBadVersion:  return Scipvm_error[20];     break;
    case PvmOutOfRes:    return Scipvm_error[21];     break;
    case PvmDupHost:     return Scipvm_error[22];     break;
    case PvmCantStart:   return Scipvm_error[23];     break;
    case PvmAlready:     return Scipvm_error[24];     break;
    case PvmNoTask:      return Scipvm_error[25];     break;
#ifdef PVM_MAJOR_VERSION 
    case PvmNotFound:    return Scipvm_error[26];     break;
    case PvmExists:      return Scipvm_error[27];     break;
#else
    case PvmNoEntry:     return Scipvm_error[26];     break;
    case PvmDupEntry:    return Scipvm_error[27];     break;
#endif
    default:             return Scipvm_error[28]; break;
    }
}



/*------------------------------------------------------------------------
 * start pvm 
 *------------------------------------------------------------------------*/


void C2F(scipvmstart)(int *res, char *hostfile, int *l)
{
  struct stat buf;
  char *rd = 0;
  char *ro = 0;
  char *path = NULL;
  int argc = 0;
  char *argv[2];

  argv[0] = "";
  argv[1] = (char*)0;
  if (!strcmp(hostfile, "null")) 
    {
      /* on ne spcifie pas de hostfile */
      /* on essaye de prendre
       * $HOME/.pvmd.conf, puis
       * $SCI/.pvmd.conf sinon on laisse
       *	 faire pvmd...
       */ 
      if (!argc && (ro = getenv("PVM_ROOT")) && (rd = getenv("HOME"))){
	if ((path = (char *) MALLOC(strlen(rd)+12)) == NULL) {
	  (void) fprintf(stderr, "Error MALLOC in pvm_error\n");
	  *res = PvmNoMem;
	  return;
	}
	strcpy(path, rd);
	strcat(path, "/.pvmd.conf"); 
	if (stat(path, &buf) == 0){
	  argc = 1;
	  argv[0] = path;
	  sciprint_nd("The configuration file\n %s\nis used.\n", path);
	} else {
	  sciprint_nd("Warning: PVM_ROOT is set to %s\r\n",ro);
	  sciprint_nd("\tbut there exists no configuration file:\r\n");
	  sciprint_nd("\t%s\r\n", path);
	  FREE(path);
	}
      } /* PVM_ROOT + HOME */
      if (!argc && (rd = getenv("SCI"))){
	if ((path = (char *) MALLOC(strlen(rd)+12)) == NULL) {
	  (void) fprintf(stderr, "Error malloc in pvm_error\n");
	  *res = PvmNoMem;
	  return;
	}
	strcpy(path, rd);
	strcat(path, "/.pvmd.conf"); 
	if (stat(path, &buf) == 0){
	  sciprint_nd("The standard configuration file $SCI/.pvmd.conf will be used.\r\n");
	  sciprint_nd("\tWith SCI=%s\r\n",rd);
	  sciprint_nd("\tSCI will have to be set on remote hosts \r\n");
	  sciprint_nd("\tin order to spawn scilab\r\n",rd);
	  argc = 1;
	  argv[0] = path;
	} else {
	  FREE(path);
	  sciprint_nd("Warning: The standard configuration file $SCI/.pvmd.conf was not found.\r\n");
	  sciprint_nd("\tWe supposed that PVM and scilab are in standard place on your net\r\n");
	  sciprint_nd("\t (Cf. man pvmd3)\r\n");
	}
      } /* SCI */
    } else {
      if (stat(hostfile, &buf) == -1){
	sciprint("%s: No such file or directory\r\n", hostfile);
      } else {
	argv[0] = hostfile;
	argc = 1;
      }
    }
  *res = pvm_start_pvmd(argc, argv, 1);
} 



/*------------------------------------------------------------------------
 * halt pvm 
 *------------------------------------------------------------------------*/

void C2F(scipvmhalt)(int *res)
{
  /* Catch the SIGTERM */
  if (SIG_ERR == signal(SIGTERM,SIG_IGN)){
    (void) fprintf(stderr, "Error pvm_halt - signal\n");
    *res = -1;
    return;
  }
  *res =  pvm_halt(); 
  if (*res == 0) {
    *res = pvmendtask();
  }
  /* Catch the SIGPIPE and deflect SIGTERM */
#ifdef SIGPIPE
  if (SIG_ERR == signal(SIGPIPE,SIG_IGN)){
    (void) fprintf(stderr, "Error pvm_halt - signal\n");
    *res = -1;
    return;
  }
#endif 
  if (SIG_ERR == signal(SIGTERM,SIG_DFL)){
    (void) fprintf(stderr, "Error pvm_halt - signal\n");
    *res = -1;
    return;
  }         
} 


/*------------------------------------------------------------------------
 * timer 
 *------------------------------------------------------------------------*/

static struct timeval t1;

void C2F(scipvmsettimer)(int *res)
{
  *res = gettimeofday(&t1, NULL);
} 

void C2F(scipvmgettimer)(double *res)
{
  struct timeval t2;
  *res = gettimeofday(&t2, NULL);
  if (*res != -1){
    *res = (double)(t2.tv_sec-t1.tv_sec)*1000000.+(double)(t2.tv_usec-t1.tv_usec);
    t1 = t2;
  }
} 


/*------------------------------------------------------------------------
 * spawn a scilab 
 *------------------------------------------------------------------------*/

void C2F(scipvmspawn)(char *task,  int *l1, 
		      char *win,   int *l2,
		      char *where, int *l3, 
		      int *ntask,  int *tids, int *res)
{
  
  int flag = PvmTaskDefault;
  char cmd[256];
  char *arg[4];
  int nargs= -1;
    
  arg[0] = NULL;
   
  cmd[0] = 0;

  if ( !strcmp(where, "null") )
    where = NULL;
  else
    flag = PvmTaskHost;
#if (defined __MSC__)  || defined(__MINGW32__) 
  strcpy(cmd, "scilex.exe");
#else
  /* I really need scilab here for gtk -version */
  strcpy(cmd, "scilab");
#endif 
#if (defined __MSC__) || defined(__MINGW32__) 
  if ( _stricmp(task,"null") != 0) 
#else 
  if (strcasecmp(task, "null")) 
#endif
    {
      arg[++nargs] = "-f";
      arg[++nargs] = task;
    }
  
  if ( strcmp(win, "nw") == 0 )  arg[++nargs] = "-nw";
  arg[++nargs]=NULL;
  /* 
  sciprint("cmd=[%s]\r\n",cmd) ;
  nargs = 0; 
  for ( i = 0 ; arg[i] != NULL ; i++) 
    sciprint("arg %d =[%s]\r\n",i,arg[i]) ;
  */
  *res = pvm_spawn(cmd, arg, flag, where, *ntask, tids);
}

/*------------------------------------------------------------------------
 * spawn 
 *------------------------------------------------------------------------*/
  
void C2F(scipvmspawnindependent)(char *task,  int *l1, 
				 int *ntask,
				 char *where, int *l3, 
				 int *tids, int *res)
{
  int flag = PvmTaskDefault;

  if (!strcmp(where,"null"))
    where = NULL;
  else
    flag = PvmTaskHost;

  *res = pvm_spawn(task, NULL, flag, where, *ntask, tids);
}