* @brief Illustrates how to find the parent communicator of an MPI process.
int main(int argc, char* argv)
if(parent == MPI_COMM_NULL)
// We have no parent communicator so we have been spawned directly by the user
printf("We are processes spawned directly by you, we now spawn a new instance of an MPI application.\n");
MPI_Comm_spawn(argv, MPI_ARGV_NULL, 1, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &child, &spawn_error);
// We have been spawned by another MPI process
printf("I have been spawned by MPI processes.\n");