Advertisement
Guest User

MPI_Comm_spawn

a guest
Jun 16th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. //Roland Schulz roland at utk dot edu
  2. #include <stdio.h>
  3. #include <mpi.h>
  4. #include <unistd.h>
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.     MPI_Init(&argc, &argv);
  9.     MPI_Comm parent;
  10.     MPI_Comm_get_parent(&parent);
  11.     if (parent==MPI_COMM_NULL) /*this is the parent*/
  12.     {
  13.         MPI_Comm children;
  14.         MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 2, MPI_INFO_NULL, 0, MPI_COMM_WORLD,
  15.                &children, MPI_ERRCODES_IGNORE);
  16.         printf("Parent done spawning\n");
  17.         MPI_Comm_disconnect(&children);
  18.         MPI_Finalize();
  19.         printf("Parent finalized\n");
  20.         //sleep(2);                                                                                                                                                                              
  21.     }
  22.     else
  23.     {
  24.         MPI_Comm_disconnect(&parent);
  25.         int rank,size;
  26.         MPI_Comm_size(MPI_COMM_WORLD, &size);
  27.         MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  28.         printf("Hi from %d of %d\n", rank, size);
  29.         sleep(1);
  30.         MPI_Finalize();
  31.         printf("Child finalized\n");
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement