On Thu, 5 Jun 2003, Sherif Abd El-Momen wrote:
> [snipped]
> I want to have a global Intra-communicator. That should be initialized
> in the beginning to MPI_COMM_WORLD. After spawning a new process and
> merging it to the parent group, I want to assign the new
> intra-communicator to that global communicator. I have tried the
> following but it seems it is not working, please correct me and advise.
This code does not exactly *assign* communicators. Remember that
MPI_Comm's are simply handles to underlying objects in the MPI
implemenation. So if you do something like:
MPI_Comm foo = MPI_COMM_WORLD;
then both foo and MPI_COMM_WORLD refer to the same underlying
communicator. When you do:
MPI_Comm_dup(MPI_COMM_WORLD, &foo);
then foo is a *new* communicator that has exactly the same process members
and ordering as MPI_COMM_WORLD. But it's a different communicator than
MPI_COMM_WORLD -- for example, if you send a message on foo, you cannot
receive it on MPI_COMM_WORLD.
See my comments below.
> /* initialization */
> MPI_Comm_dup(MPI_COMM_WORLD,&MainComm);
>
> /* Creating new process */
>
> MPI_Comm_spawn(worker_sim1,MPI_ARGV_NULL,1 ,
> MPI_INFO_NULL, 0, MainComm, &Comm_1,
> ierr);
There is no ierr in the C API functions. ierr is only in fortran.
> /* Merge */
> MPI_Intercomm_merge(Comm_1,0, &Comm_2);
>
> /* Reassign */
> MPI_Comm_dup(Comm_2,&MainComm);
Also note that the code above is creating a whole bunch of communicators
and then de-referencing them, even though they still exist (somewhat akin
to memory leaks, such as dereferencing malloc'ed memory).
Try something like the following (typed off the top of my head -- may not
be exactly correct):
MPI_Comm everyone, worker_inter, worker_intra;
MPI_Comm_dup(MPI_COMM_WORLD, &everyone);
while (!done) {
/* do whatever setup is necessary */
MPI_Comm_spawn(..., everyone, &worker_inter).
MPI_Intercomm_merge(worker_inter, &worker_intra);
MPI_Comm_free(&worker_inter);
MPI_Comm_free(&everyone);
everyone = worker_intra;
/* do some work */
}
Hope that helps.
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|