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-04-14 16:11:22


Hi!
Can any one send me an example or direct me to a location that have examples
on using C++ bindings in general. I also have an master that spawn several
slaves in C, I would like to us the C++ binding MPI::Intracomm::Spawn. But I
realy don't know how.
/***************************************/
int main(int argc, char **argv)
{
   float *a_ptr,*b_ptr, a,b;

  int n;
  MPI_Datatype mytype;
  double flag_buffer =100;
  MPI_Request Reqs[3];
  int rank,i,j;
   int world_size, universe_size, *universe_sizep, flag;
   MPI_Comm everyone; /* intercommunicator */
   char *worker_program;
   MPI_Status status;

   a_ptr = new float [10];
   b_ptr = new float [10];

  MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &world_size);
   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
Build_derived_type(a_ptr,b_ptr,&n,&mytype);
if (world_size != 1)
  // perror("Top heavy with management");

   MPI_Attr_get(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE,
                &universe_sizep, &flag);
   flag =0;
if (!flag)
     {
        cout << "This MPI does not support UNIVERSE_SIZE. How many\n
processes total?";
        cin >> universe_size;

     }
   else
     universe_size = *universe_sizep;
// printf("Universe_size = %d ",universe_size);
   if (universe_size == 1)
     // perror("No room to start workers");

/*
    * 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);*/
   strcpy( worker_program, "/home/abdelmss/MPI/slave" );
   /* MPI_Comm_spawn(worker_program, MPI_ARGV_NULL, universe_size-1,
             MPI_INFO_NULL, 0, MPI_COMM_SELF, &everyone,
             MPI_ERRCODES_IGNORE); */

MPI::Intercomm
MPI::Intracomm::spawn(worker_program,MPI_ARGV_NULL,universe_size -1,
MPI_INFO_NULL,0,MPI_ERRCODES_IGNORE);
   /*
    * Parallel code here. The communicator "everyone" can be used
    * to communicate with the spawned processes, which have ranks 0,..
    * MPI_UNIVERSE_SIZE-1 in the remote group of the intercommunicator
    * "everyone".
    */
   // i=MPIL_Signal(everyone,0,7);
for (i=0; i<= universe_size; i++){
     flag_buffer+=i;
   MPI_Isend(a_ptr, sizeof(mytype),mytype,i,1,everyone,&Reqs[i]);
   }
   for ( j=0;j < universe_size;j++){
   MPI_Wait(&Reqs[i],&status);
   }
   cout << "my rank is " << rank;

   MPI_Comm_free(&everyone);
   MPI_Finalize();

   return 0;
}

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail