[mpich-discuss] mpi_comm_spawn problem

Umit umitcanyilmaz at gmail.com
Thu Feb 23 05:13:45 CST 2012


@Rajeev Thakur
Thank you. It worked.

But now as I am spawning the new processes all processes are blocked. Is
there any other way to spawn new processes without blocking all processes.
And then I want to add all processes in a new communicator and give them
new ranks.

For example I want to spawn new processes with only one process and then
add all the processes to a new communicator and give them new ranks.

Thanks in advance,


On 22 February 2012 20:00, Rajeev Thakur <thakur at mcs.anl.gov> wrote:

> I meant pass comm as the input communicator instead of COMM_WORLD. Use
> something else as the output communicator.
>
> On Feb 22, 2012, at 12:57 PM, Umit wrote:
>
> > Hello All,
> >
> > Thank you Rajeev for your e-mail.
> >
> > My question is how to call mpi_spawn with a specific communicator. I
> dont know how to call it with comm? and I am not sure if it is possible.
> >
> > If you mean changeing the parameter "&intercomm" with "&comm" in
> mpi_comm_spawn. It doesnt help. This parameter is not the name of calling
> communicator. It is the intercommunicator between original group and the
> newly spawned group.I have to change the name of original group.
> >
> > I even tried it and it did not help. Please tell me if I am doing
> something wrong. Here is the new code and output:
> >
> > #include "mpi.h"
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <stdint.h>
> >
> > #define NUM_SPAWNS 4
> >     MPI_Comm comm, comm1;
> >     MPI_Comm parentcomm, intercomm;
> >     int np = NUM_SPAWNS;
> >     int errcodes[4];
> >     char argv[1];
> >     int rank;
> > int main( int argc, char *argv[] )
> > {
> >     MPI_Init( &argc, &argv );
> >     MPI_Comm_get_parent( &parentcomm );
> >     int i = atoi(argv[1]);
> >
> >     if (i==2){
> >     MPI_Intercomm_merge( parentcomm, 1, &comm1 );
> >      goto jump; ///Here secondly spawned processes jump.
> >     }
> >
> >     if (parentcomm == MPI_COMM_NULL)
> >     {
> >        argv[0] = "1";
> >         MPI_Comm_spawn( "/home/umit/Desktop/merge/./a.out", argv, np,
> MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, errcodes );
> >     MPI_Intercomm_merge( intercomm, 0, &comm );
> >     }
> >     else
> >     {
> >     MPI_Intercomm_merge( parentcomm, 1, &comm );
> >     }
> >     argv[0] = "2";
> >     MPI_Comm_spawn( "/home/umit/Desktop/merge/./a.out", argv, np,
> MPI_INFO_NULL, 0, MPI_COMM_WORLD, &comm, errcodes );
> >     MPI_Intercomm_merge( comm, 0, &comm1 );
> >
> >     jump:
> >     MPI_Comm_rank (comm1, &rank);
> >     printf("I created at %d. call my rank is %d \n", i, rank);
> >
> >     MPI_Finalize();
> >     return 0;
> > }
> >
> > output:
> > umit at ubuntu:~/Desktop/merge$ mpirun -np 4 ./a.out 0
> > I created at 2. call my rank is 4
> > I created at 0. call my rank is 0
> > I created at 2. call my rank is 6
> > I created at 0. call my rank is 2
> > I created at 2. call my rank is 5
> > I created at 2. call my rank is 7
> > I created at 0. call my rank is 3
> > I created at 0. call my rank is 1
> > I created at 1. call my rank is 3
> > I created at 2. call my rank is 4
> > I created at 1. call my rank is 1
> > I created at 1. call my rank is 0
> > I created at 2. call my rank is 7
> > I created at 2. call my rank is 6
> > I created at 1. call my rank is 2
> > I created at 2. call my rank is 5
> >
> > Best Regards,
> >
> >
> >
> >
> >
> >
> > On 22 February 2012 19:22, Rajeev Thakur <thakur at mcs.anl.gov> wrote:
> > You need to call the second spawn with comm instead of intercomm.
> >
> > On Feb 22, 2012, at 12:05 PM, Umit wrote:
> >
> > > Hello All,
> > >
> > >
> > >
> > > I am running a mpi program with 4 processes and I am spawning 4 more
> processes and adding them in a new intracommunicator with
> mpi_intercomm_merge and having a intracommunicator with 8 processes. I am
> successful until this point.
> > >
> > > And then I want to call with these 8 processes 4 new processes and add
> them in a new communicator and get 12 processes in my intracommunicator.
> But I couldn’t spawn the new processes with these 8 processes.
> > >
> > > Spawned processes and other processes are calling mpi_comm_spawn
> separately. At first 4 processes are calling mpi_comm_spawn and then first
> spawned processes are calling mpi_comm_spawn and I am getting two
> intracommunicatiors each with 8 processes.
> > >
> > > How can I make mpi_comm_spawn to call the new processes with new
> crated intracommunicator? Is this possible?
> > >
> > >
> > >
> > > Here is my code and the output of my program:
> > >
> > >
> > >
> > > Code:
> > >
> > > #include "mpi.h"
> > >
> > > #include <stdio.h>
> > >
> > > #include <stdlib.h>
> > >
> > > #include <string.h>
> > >
> > > #include <stdint.h>
> > >
> > >
> > > #define NUM_SPAWNS 4
> > >
> > >     MPI_Comm comm;
> > >
> > >     MPI_Comm parentcomm, intercomm;
> > >
> > >     int np = NUM_SPAWNS;
> > >
> > >     int errcodes[4];
> > >
> > >     char argv[1];
> > >
> > >     int rank;
> > >
> > > int main( int argc, char *argv[] )
> > >
> > > {
> > >
> > >     MPI_Init( &argc, &argv );
> > >
> > >     MPI_Comm_get_parent( &parentcomm );
> > >
> > >     int i = atoi(argv[1]);
> > >
> > >     if (parentcomm == MPI_COMM_NULL)
> > >
> > >     {
> > >
> > >        argv[0] = "1";
> > >
> > >         MPI_Comm_spawn( "/home/umit/Desktop/merge/./a.out", argv, np,
> MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, errcodes );
> > >
> > >                 MPI_Intercomm_merge( intercomm, 0, &comm );
> > >
> > >                 MPI_Comm_rank (comm, &rank);
> > >
> > >                 printf("I am not spawned my rank is %d \n", rank);
> > >
> > >     }
> > >
> > >     else
> > >
> > >     {
> > >
> > >                 MPI_Intercomm_merge( parentcomm, 1, &comm );
> > >
> > >                 MPI_Comm_rank (comm, &rank);
> > >
> > >                 printf("I am spawned at %d. call my rank is %d \n", i,
> rank);
> > >
> > >
> > >                 if (i==2) goto jump; ///Here secondly spawned
> processes jump.
> > >
> > >     }
> > >
> > >     argv[0] = "2";
> > >
> > >     MPI_Comm_spawn( "/home/umit/Desktop/merge/./a.out", argv, np,
> MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, errcodes );
> > >
> > >     MPI_Intercomm_merge( intercomm, 0, &comm );
> > >
> > >     MPI_Comm_rank (comm, &rank);
> > >
> > >     jump:
> > >
> > >     MPI_Finalize();
> > >
> > >     return 0;
> > >
> > > }
> > >
> > >
> > > Output is:
> > >
> > > umit at ubuntu:~/Desktop/merge$ mpirun -np 4 ./a.out 0
> > >
> > > I am spawned at 1. call my rank is 7
> > >
> > > I am not spawned my rank is 3
> > >
> > > I am spawned at 1. call my rank is 5
> > >
> > > I am not spawned my rank is 1
> > >
> > > I am spawned at 1. call my rank is 4
> > >
> > > I am not spawned my rank is 2
> > >
> > > I am spawned at 1. call my rank is 6
> > >
> > > I am not spawned my rank is 0
> > >
> > > I am spawned at 2. call my rank is 4
> > >
> > > I am spawned at 2. call my rank is 6
> > >
> > > I am spawned at 2. call my rank is 7
> > >
> > > I am spawned at 2. call my rank is 5
> > >
> > > I am spawned at 2. call my rank is 5
> > >
> > > I am spawned at 2. call my rank is 4
> > >
> > > I am spawned at 2. call my rank is 6
> > >
> > > I am spawned at 2. call my rank is 7
> > >
> > >
> > >
> > >
> > > Best Regards,
> > >
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> > > To manage subscription options or unsubscribe:
> > > https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
> >
> > _______________________________________________
> > mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> > To manage subscription options or unsubscribe:
> > https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
> >
> > _______________________________________________
> > mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> > To manage subscription options or unsubscribe:
> > https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120223/9dc99510/attachment.htm>


More information about the mpich-discuss mailing list