This is a simple C++ class to help to easily make programs for MPMD running.
It is contained in a single .hpp
file for ease of use.
The class can be used as a global static, or just as a local variable in main. Either way, you need to only initialize it after you initialize MPI:
MPMDHelper MPMD;
MPI_Init(&argc, &argv);
MPMD.Init(MPI_COMM_WORLD, "my program");
Then, you can communicate within a single program through MPMD.local
communicator, and with other programs with MPMD["other program"].local
inter-communicator.
Additionaly, one can exclude some of the processes from the communication, which would be common in MPI programs with master-workers architecture.
You can use the library to combine programs both by running them simultaniously, and by dynamic spawning of processes:
You initialize the helper object with name of the program:
MPMD.Init(MPI_COMM_WORLD, "my program");
The name is used to split the common world communicator into smaller communicators. You can use the name of the executable as the name:
MPMD.Init(MPI_COMM_WORLD, argv[0]);
If your program has a master-workers architecture, you can create a subgrup, by excluding the master process (for instance 0):
std::vector<int> excl;
excl.push_back(0);
MPMD.Init(MPI_COMM_WORLD, "my program with workers", excl);
After initialization, you can use:
MPMD.world
- the originalMPI_COMM_WORLD
MPMD.local
- the communicator for the single program (the processes which declared the samename
)MPMD.work
- the communicator for the workers (all processes excludingexcl
)
You can communicate with other program (let's say B
) with:
MPMD["B"].local
- inter-communicator with the wholeB
programMPMD["B"].work
- inter-communicator with the worker processes ofB
You can also dynamically spawn processes:
MPMD.Spawn("./slave", MPI_ARGV_NULL, N, MPI_INFO_NULL);
After you do, you can access inter-communicators the same way as above
The simplest way to run MPMD program with OpenMPI is:
mpirun -np 2 ./program_A : -np 3 ./program_B