Thank you very much for your answer, unfortunately I yet have some
doubts concerning the MPI_Comm_spawn function.
> > I would like to know, if we can invoke the MPI_Comm_spawn function,
> > just as a root process ?
>
> Not quite sure what you mean here by "just as a root process"...?
If I really well understood, the function MPI_Comm_spawn can be
invoked by only one process in a Communicator (the root process) ? But
every process in the communicator has to call the MPI_Comm_spawn
with the same arguments ?
>
> The MPI_COMM_SPAWN call is collective over all processes in the
> communicator. Hence, every process in the communicator must call
> COMM_SPAWN.
>
I'm putting a piece of a program (see below), where
I have eights processes, and each one try to execute another program
with differents arguments. But the output give just the answer
concerning the slave 1 (my_rank = 1).
>
> > And if not, how can we proceed to call
> > MPI_Comm_spawn from every rank of a group with differents arguments ?
>
> As per MPI-2 p84, the command, argv, maxprocs, and info arguments to
> MPI_COMM_SPAWN are only significant in the root process. The root and
> comm arguments must be the same across all processes in the
> communicator. The intercomm and array_of_errorcodes arguments will be
> filled by MPI upon return from MPI_COMM_SPAWN in all processes in the
> communicator.
Here is the program, thank you again for your help.
Gabriel
#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 valeur_processus)
{
char command[] = "Program";
char **argv;
int errcode;
int mon_rang,ntasks,err;
unsigned long int arguments;
MPI_Comm intercomm;
arguments = 30;
mon_rang=MPI_Comm_rank(MPI_COMM_WORLD, &mon_rang);
argv=(char **)malloc(2*sizeof(char *));
argv[0]=(char*)malloc(10*sizeof(char));
sprintf(argv[0],"%ld",arguments);
argv[1] = NULL;
MPI_Comm_set_errhandler(MPI_COMM_WORLD,MPI_ERRORS_RETURN);
err=MPI_Comm_spawn(command,argv,1,MPI_INFO_NULL,mon_rang,MPI_COMM_WORLD,&intercomm,&errcode);
return(0);
}
The code for Program:
#include <stdio.h>
#include <mpi.h>
int main(int argc,char *argv[])
{
unsigned long int number;
MPI_Comm parent;
MPI_Init(&argc, &argv);
MPI_Comm_get_parent(&parent);
printf("%s\n",argv[1]);
.....
.....
.....
exit(0);
}
|