title: Block execution until children called via MPI_Comm_spawn have finished
body: <p>I'm in the process of modifying an existing application, where I would like to spawn a dynamically created bash script. I created a simple wrapper routine which takes the name of the bash script as an argument. In the wrapper, the script is spawned by MPI_Comm_spawn. Directly after, the wrapper calls MPI_Finalize, which is executed before the scripts have finished:</p>
  
  <pre><code>#include "mpi.h"
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main(int argc, char *argv[])
  {
      char *script = argv[1];
      int maxProcs = 2, myRank;
      MPI_Comm childComm;
      int spawnError[maxProcs];
  
      // Initialize
      argv[1] = NULL;
      MPI_Init(&amp;argc, &amp;argv);
  
      // Rank of parent process
      MPI_Comm_rank(MPI_COMM_WORLD, &amp;myRank);    
  
      // Spawn application    
      MPI_Comm_spawn(script, MPI_ARGV_NULL, maxProcs, MPI_INFO_NULL, myRank, MPI_COMM_SELF, &amp;childComm, spawnError);
  
      // Finalize
      MPI_Finalize();
  
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>If I insert</p>
  
  <pre><code>    sleep(10);
  </code></pre>
  
  <p>right before </p>
  
  <pre><code>    MPI_Finalize ();
  </code></pre>
  
  <p>everything works fine. Now my question is if it is possible to block execution in the wrapper until the bash script is finished? Also, it would be nice to obtain the return value of the script. 
  Unfortunately, it is not an option to create another wrapper for the script, which communicates with the parent wrapper and executes the bash scripts via a system call because I need to access MPI environment variables from within the script. I hope, I have made things clear enough. Any help would be greatly appreciated!</p>