I am trying to configure a bunch of spawned processes into one internal group. I need to deploy individual processes to unique working directories, as these subprocesses will write out a bunch of files. After all the processes are generated, they want to combine them into one internal communicator. To try this, I installed a simple test program.
int main(int argc, const char * argv[]) { int rank, size; const int num_children = 5; int error_codes; MPI_Init(&argc, (char ***)&argv); MPI_Comm parentcomm; MPI_Comm childcomm; MPI_Comm intracomm; MPI_Comm_get_parent(&parentcomm); if (parentcomm == MPI_COMM_NULL) { printf("Current Command %s\n", argv[0]); for (size_t i = 0; i < num_children; i++) { MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 1, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &childcomm, &error_codes); MPI_Intercomm_merge(childcomm, 0, &intracomm); MPI_Barrier(childcomm); } } else { MPI_Intercomm_merge(parentcomm, 1, &intracomm); MPI_Barrier(parentcomm); } printf("Test\n"); MPI_Barrier(intracomm); printf("Test2\n"); MPI_Comm_rank(intracomm, &rank); MPI_Comm_size(intracomm, &size); printf("Rank %d of %d\n", rank + 1, size); MPI_Barrier(intracomm); MPI_Finalize(); return 0; }
When I run this, I get all 6 processes, but my inner intelligence speaks only between the parent and the last child spawned. Result obtained
Test Test Test Test Test Test Test2 Rank 1 of 2 Test2 Rank 2 of 2
Is there a way to combine several communicators into one communicator? Also note that I create these files at a time, since I need each subprocess to run in a unique working directory.
source share