Want more features on Pastebin? Sign Up, it's FREE!
Guest

MPI_Comm_spawn

By: a guest on Jun 16th, 2012  |  syntax: C  |  size: 1.10 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data