LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Sherif Abd El-Momen (sherif_samir75_at_[hidden])
Date: 2003-05-29 16:16:12


Hi!
  I want a group of process to spawn one processes at a time an merge it
into their comm. here is my program. but what happend is that every process
in the main group creats a process. so how can I fix that so as all of them
share in creating 1 process - or one group- so what I am doing wrong.
another question:
how can I merge two different intracomm in one intracomm, both have the same
master.
Please advise
Best Regards
Sherif

#include <stdio.h>
#include <string.h>
/* manager */
#include "mpi.h"
#define CMDSIZE 80

int main(int argc, char *argv[])
{
  char * myargv[6];
char processor_name[MPI_MAX_PROCESSOR_NAME],controlmsg[CMDSIZE];
   int namelen,rank, world_size, universe_size, *universe_sizep, flag;
   MPI_Comm everyone; /* intercommunicator */
   MPI_Comm Simulation;
   int size;
   char worker_program[100];
        MPI_Init(&argc, &argv);

/*
    * Now spawn the workers. Note that there is a run-time determination
    * of what type of worker to spawn, and presumably this calculation must
    * be done at run time and cannot be calculated before starting
    * the program. If everything is known when the application is
    * first started, it is generally better to start them all at once
    * in a single MPI_COMM_WORLD.
    */

   /* choose_worker_program(worker_program);*/
   MPI_Comm_rank( MPI_COMM_WORLD, &rank );

   strcpy( worker_program, "/home/abdelmss/MPI/slave" );

   MPI_Comm_rank( MPI_COMM_WORLD, &rank );

   MPI_Comm_spawn(worker_program,MPI_ARGV_NULL, 3,
             MPI_INFO_NULL, 0, MPI_COMM_SELF, &everyone,
             MPI_ERRCODES_IGNORE);
   MPI_Barrier(MPI_COMM_WORLD);
   printf ("the process have been created\n");
   MPI_Intercomm_merge(everyone,0,&Simulation);
   MPI_Barrier(Simulation);
        MPI_Comm_size( Simulation, &size );
        printf ("size %d \n ",size);
        printf ("the master exit\n");
           MPI_Finalize();
   return 0;
}

/* worker */

#include "mpi.h"
#define CMDSIZE 80
#include <lam_ksignal.h>

int main(int argc, char *argv[])
{ int namelen,i;
        char processor_name[MPI_MAX_PROCESSOR_NAME];
   int size,rank;
   MPI_Comm parent;
   MPI_Comm Simulation;
   char worker_program[100];
   MPI_Init(&argc, &argv);

                MPI_Comm_get_parent(&parent);
          MPI_Intercomm_merge(parent,1,&Simulation);
          MPI_Barrier(Simulation);
          MPI_Comm_size(Simulation, &size);
      MPI_Comm_rank( Simulation, &rank );

/*
    * Parallel code here.
    * The manager is represented as the process with rank 0 in (the remote
    * group of) MPI_COMM_PARENT. If the workers need to communicate among
    * themselves, they can use MPI_COMM_WORLD.
    */

printf ("the slave are exiting, my rank %d \n",rank);
   MPI_Finalize();
   return 0;
}

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail