Actual source code: launch.c
1: /*$Id: launch.c,v 1.15 2001/03/23 23:19:53 balay Exp $*/
2: /*
3: Usage: A = launch(programname,number processors);
4: Modified Sept 28, 2003 RFK: updated obsolete mx functions.
5: */
7: #include <stdio.h>
8: #include <errno.h>
9: extern int fork();
10: extern int system(const char *);
11: #include src/sys/src/viewer/impls/socket/socket.h
12: #include "mex.h"
13: #define ERROR(a) {fprintf(stdout,"LAUNCH: %s \n",a); return ;}
14: /*-----------------------------------------------------------------*/
15: /* */
16: /*-----------------------------------------------------------------*/
19: void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
20: {
21: int np,child;
22: char program[PETSC_MAX_PATH_LEN],executable[PETSC_MAX_PATH_LEN];
24: if (nlhs == 1) {
25: plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
26: *mxGetPr(plhs[0]) = 1;
27: }
29: /* check output parameters */
30: if (nlhs > 1) ERROR("Open requires at most one output argument.");
31: if (!nrhs) ERROR("Open requires at least one input argument.");
32: if (!mxIsChar(prhs[0])) ERROR("First arg must be string.");
34: if (nrhs == 1) np = 1;
35: else np = (int)*mxGetPr(prhs[1]);
37: /* attempt a fork */
38: child = fork();
39: if (child < 0) {
40: ERROR("Unable to fork.");
41: } else if (!child) { /* I am child, start up MPI program */
42: mxGetString(prhs[0],program,1000);
43: sprintf(executable,"mpirun -np %d %s",np,program);
44: printf("About to execute %s\n",executable);
45: system(executable);
46: printf("Completed subprocess\n");
47: fflush(stdout);
48: exit(0);
49: }
50:
52:
53: if (nlhs == 1) {
54: *mxGetPr(plhs[0]) = 0;
55: }
56: return;
57: }
59:
60: