LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2004-12-06 09:05:16


On Dec 6, 2004, at 7:19 AM, Gabriel Antoine Louis Paillard wrote:

> 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 ?

It's implementation-dependent as to which ranks will actually do the
spawning. LAM only uses the root rank for spawning, but it is
permissable to use others as well (e.g., where scalability may be an
issue). The standard says that the some of the arguments are only
relevant at the root -- that's all you can know.

More specifically: all ranks in the communicator must call
MPI_COMM_SPAWN. The total number of processes spawned will be the
value of the maxprocs argument at the root.

So it's *ok* to pass the same argument values on all ranks in the
communicator (there is certainly no harm in this), but it's only
*required* to pass the same values for *some* of the arguments. From
the implementation's standpoint, LAM only assumes that the required
arguments are the same on all ranks.

>> 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).

If you want to launch N processes, each with different arguments, then
you need to use either multiple calls to MPI_COMM_SPAWN (i.e., each one
with a different argv), or MPI_COMM_SPAWN_MULTIPLE, where you can
specify an array of argv.

> #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);
> }

This code will launch one child process with an argv[0] of "30".

-- 
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/