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 (17 years, 11 months 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

# Content
1 #include "mpi.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <dirent.h>
6 #include <sys/types.h>
7 #include "getfile.h"
8
9
10
11 int main(int argc, char *argv[]){
12
13 int myid,numprocs,rank,i;
14 int nrst_files;
15 int error;
16 char * dirname = ".";
17 char *fname;
18 //char *fname;
19 extern char **environ;
20 char *newargv[] ={
21 "/bin/echo",
22 "Filename",
23 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 // 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 printf("Number of files nrst_files %d\n",nrst_files);
36 for (i=0;i<nrst_files;i++){
37 fname = getfilename(i);
38 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 }
48 MPI_Finalize();
49 return(0);
50 }