ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/runParallel/runParallel.c
Revision: 2956
Committed: Wed Jul 19 16:08:12 2006 UTC (18 years, 1 month ago) by chuckv
Content type: text/plain
File size: 1028 byte(s)
Log Message:
Added fork() and wait() so we can loop through multiple jobs.

File Contents

# User Rev Content
1 chuckv 2929 #include "mpi.h"
2     #include <stdio.h>
3     #include <stdlib.h>
4     #include <unistd.h>
5     #include <dirent.h>
6 chuckv 2956 #include <sys/types.h>
7 chuckv 2933 #include "getfile.h"
8 chuckv 2929
9    
10    
11     int main(int argc, char *argv[]){
12    
13 chuckv 2933 int myid,numprocs,rank,i;
14     int nrst_files;
15 chuckv 2956 int error;
16 chuckv 2943 char * dirname = ".";
17     char *fname;
18     //char *fname;
19 chuckv 2929 extern char **environ;
20     char *newargv[] ={
21     "/bin/echo",
22 chuckv 2956 "Filename",
23 chuckv 2929 NULL
24     };
25     MPI_Init(&argc,&argv);
26     MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
27     MPI_Comm_rank(MPI_COMM_WORLD,&myid);
28    
29 chuckv 2933 // for (rank = 0;rank<numprocs;rank++){
30     // if (rank == myid){
31     // execve(argv[0],newargv,environ);
32     // }
33     // }
34     nrst_files = nfiles(&dirname,myid);
35 chuckv 2943 printf("Number of files nrst_files %d\n",nrst_files);
36 chuckv 2933 for (i=0;i<nrst_files;i++){
37 chuckv 2943 fname = getfilename(i);
38 chuckv 2956 printf("Returned file name on loop %d %s\n",i,fname);
39     newargv[1] = fname;
40     if (fork() == 0){
41     error = execv(newargv[0],newargv);
42     perror("Steve needs a mojito now");
43     exit(1);
44     } else {
45     wait(&error);
46     }
47 chuckv 2933 }
48 chuckv 2929 MPI_Finalize();
49 chuckv 2933 return(0);
50 chuckv 2929 }