Newsgroups: comp.parallel.mpi
From: Yon Han CHONG <Y.H.Chong@cranfield.ac.uk>
Subject: Re: information on MPI_Spawn and MPIL_Spawn
Organization: Cranfield University
Date: Fri, 29 May 1998 16:21:12 +0200
Mime-Version: 1.0
Content-Type: text/plain; charset=EUC-KR
Content-Transfer-Encoding: 7bit
Message-ID: <356EC458.B680E98D@cranfield.ac.uk>

Aric Lambert wrote:
> 
> Does anyone know a good web source to fined information on the lam MPI_Spawn
> and MPIL_Spawn call other than the man pages?   Does anyone have an example
> they are willing to share?
> 
I have saved following e-mail because I am interested in MPI_Spawn as
well.
I am sure Nichoas Nevin would not mind me forwarding his e-mail.

---------- Forwarded message ----------
Date: Thu, 14 May 1998 09:09:09 -0400 (EDT)
From: Nicholas Nevin <nevin@gis.net>
To: mjz115@psu.edu
Cc: raja@tbag.rsn.hp.com, lam-chops@osc.edu
Subject: Re: MPI_Spawn; MPI_Comm_free; MPI_Spawn problem
Resent-Date: Thu, 14 May 1998 09:14:32 -0400 (EDT)
Resent-From: lam-chops@osc.edu


Hi Michael. In regards to your spawn problems. I have included parent
and child test codes which try to duplicate what you say you are
doing. Perhaps you could try them out and see if they work for
you. They work fine for me as you can see from the output (at end of
mail) from a trial run on a 4 node LAM. BTW what patchlevel of LAM6.1
are you running?  lamboot -V will tell you.

-nick.


parent.c
--------

#include <mpi.h>

#define NSPAWNS         4
#define NCHILD          3

int
main(int argc, char **argv)
{
    MPI_Comm    children;
    int         errors[32];
    int         me;
    int         i;
    int         j;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &me);
             
    for (j = 0; j < NSPAWNS; j++) {
        MPI_Spawn("child", 0, NCHILD, MPI_INFO_NULL, 0, MPI_COMM_WORLD,
                        &children, errors);
    
        if (me == 0) {
            printf("spawned children sending them the die message\n");

            for (i = 0; i < 3; i++) {
                MPI_Send(MPI_BOTTOM, 0, MPI_BYTE, i, 99, children);
            }
        } else {
            printf("spawned children\n");
        }
    
        MPI_Comm_free(&children);
    }  

    printf("parent %d done\n", me);  
                
    MPI_Finalize();
    return(0);  
}
         
    
child.c
-------

#include <mpi.h>
                
int
main(int argc, char **argv)   
{
    MPI_Comm    parent;
    MPI_Status  status;
    int         me;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &me);
                
    printf("started child %d\n", me);
    MPIL_Comm_parent(&parent);
 
    MPI_Recv(MPI_BOTTOM, 0, MPI_BYTE, 0, 99, parent, &status);
    printf("child %d received die message\n", me);
    
    MPI_Finalize();
    return(0);
}
                
    
    
% mpirun -c 4 -w  parent
spawned children
spawned children
spawned children
started child 1
spawned children sending them the die message
started child 0
started child 2
child 0 received die message
child 1 received die message
child 2 received die message
spawned children
spawned children
spawned children
started child 0
spawned children sending them the die message
started child 1
started child 2
child 0 received die message
child 1 received die message
child 2 received die message
spawned children
spawned children
spawned children
started child 0
spawned children sending them the die message
started child 1
started child 2
child 0 received die message
child 1 received die message
child 2 received die message
spawned children
parent 1 done
spawned children
parent 2 done
spawned children
parent 3 done
started child 0
spawned children sending them the die message
started child 1
started child 2
child 0 received die message
child 1 received die message
parent 0 done
child 2 received die message



----------------------------------------------------------------------
Yon Han Chong                     |
Flow Control and Prediction Group | Tel: + 44 1234 750 111 ext. 5420
Cranfield College of Aeronautics  | E-mail: Y.H.Chong@cranfield.ac.uk
Cranfield University              | Fax: + 44 1234 752 149
United Kingdom                    | Mobile: + 44 958 381 395
----------------------------------------------------------------------

