The Object Oriented Message Passing Interface (OOMPI) is a CeePlusPlus language layer which can sit on top of the MessagePassingInterface (MPI) and provide in an object based way the functionality of MPI.
Home page: http://www.osl.iu.edu/research/oompi/
I have found this to be very easy to use when compared to the MessagePassingInterface itself, where both the CeeLanguage and FortranLanguage interfaces need a lot of parameters in the function calls to explain what is going on. With OOMPI this is simplified in many cases using overloading of member functions. -- JohnFletcher
OOMPI strategy
The OOMPI strategy is to wrap up the definition of the processes running into an object OOMPI_COMM_WORLD. The Size() member is the number of processes and the Rank() member tells each process which one it is.
OOMPI_COMM_WORLD has ports numbered from 0 to size-1 which can be used for InterProcessCommunication. OperatorOverloading allows statements such as
port << variable; port >> variable;to be used to pass information. It is important that each send and receive are correctly matched.
It is possible for any process to send output to std::cout but this is not very helpful as it will come out all mixed up between different processes. So it is helpful to organise the code so that only one process communicates with std::cout. The convention is to use rank 0 for this. Then the question arises as to what to do with the output from the other tasks. One solution is to use an object of type std::ostringstream in each of the other tasks to collect the output, and then send the strings back to the output task. There is one problem with this, which is that OOMPI does not as supplied include the transport of objects of type std::string. It can send objects of fixed size, and also arrays of objects, but not a string. The solution to this is to build a class on top of OOMPI to transfer strings. See OompiStringExample.
Example program where every process with rank > 0 sends its rank to rank 0 which outputs each value. A copy of the program is run on each process using the MessagePassingInterface to run it. Note the way in which knowledge of the rank of the process is the key to getting different process to do different tasks.
// OOMPI basic shell program #include <iostream> #include "oompi.h" using namespace std; int main(int argc, char *argv[]) { OOMPI_COMM_WORLD.Init(argc, argv); int i, j; int rank = OOMPI_COMM_WORLD.Rank(); int size = OOMPI_COMM_WORLD.Size(); OOMPI_Port to = OOMPI_COMM_WORLD[0]; if (rank == 0) { cout << "=================================================" << endl; cout << "OOMPI Test Program for ideas." << endl; cout << "running on " << size << " processes." << endl; cout << "This program collects the messages in rank order." <<endl; cout << "=================================================" << endl; cout << "I am process " << rank << " collecting messages." << endl; // This collects a message from each other process in order. for (i = 1; i < size; i++ ) { OOMPI_COMM_WORLD[i] >> j; cout << "Process " << j << " reporting." << endl; } } else { to << rank; } OOMPI_COMM_WORLD.Finalize(); return 0; }
See also ParallelProgrammingModel MessagePassingInterface