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:
#include "mpi.h"
#include <stdlib.h>
#include <iostream>
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(&argc, &argv);
// Rank of parent process
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
// Spawn application
MPI_Comm_spawn(script, MPI_ARGV_NULL, maxProcs, MPI_INFO_NULL, myRank, MPI_COMM_SELF, &childComm, spawnError);
// Finalize
MPI_Finalize();
return EXIT_SUCCESS;
}
If I insert
sleep(10);
right before
MPI_Finalize ();
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!