Now, after some modifications in the same code, finally I have
the desired output (all processes received their argument), but the rank
0 executed 8 times the same thing.
#include <stdio.h>
#include <mpi.h>
int slave ();
int main(int argc,char *argv[])
{
int myrank;
double starttime,endtime;
MPI_Init(&argc, &argv);
starttime = MPI_Wtime();
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
switch(myrank) {
case 0:
slave(1);
break;
case 1:
slave(7);
break;
case 2:
slave(11);
break;
case 3:
slave(13);
break;
case 4:
slave(17);
break;
case 5:
slave(19);
break;
case 6:
slave(23);
break;
case 7:
slave(29);
break;
}
endtime = MPI_Wtime();
printf("time: %1.15f\n", endtime-starttime);
MPI_Finalize();
exit(0);
}
int slave (unsigned long int argument)
{
char command[] = "Program";
char **argv;
int errcode;
int err,mon_rang;
MPI_Comm nouveau_monde;
mon_rang=MPI_Comm_rank(MPI_COMM_WORLD, &mon_rang);
argv=(char **)malloc(2*sizeof(char *));
argv[0]=(char*)malloc(100*sizeof(char));
sprintf(argv[0],"%ld",argument);
argv[1] = NULL;
MPI_Comm_set_errhandler(MPI_COMM_WORLD,MPI_ERRORS_RETURN);
err=MPI_Comm_spawn(command,argv,8,MPI_INFO_NULL,mon_rang,MPI_COMM_SELF,&nouveau_monde,&errcode);
return(0);
}
Thanks again,
Gabriel Paillard
|