Question

I have a program that is been implemented in C++ which I now want to add MPI support. There is an MPI binding for C++, with namespace MPI and everything.

In my case I have a specific object that is suitable to be the parallelized process into the cluster.

My questions are:

  • Has anyone done something like this before? Can I get some advices on how best to implement this?
  • How do I initialize MPI inside the constructor? After initializing MPI inside the constructor of the Class, will all the intermediate calls be parallelized too?

For example:

MyClass obj;

x = x; //this will be parallelized ?
onj.calc();

y = x++; //this will be parallelized ?

z = obj.result();
Was it helpful?

Solution

I would really recommend picking up the Gropp MPI Book, it really helps for basic MPI!

OTHER TIPS

MPI doesn't parallelize anything automatically, it only gives you an interface for sending data between nodes. Your code is written and runs as usual sequential code independently on each node and every once in a while you send data to some other node or try to receive data from some other node.

Chiming in on an old thread, I found OpenMPI and Boost::MPI nice to work with. The object oriented design of the library may be a bit bolted on, but I found it much nicer to work with than pure MPI, especially with auto-serialization of many types and a rather extendable interface for gather/reduce functions as well as serialization of user types.

As background information:

Most applications that use MPI are written in Fortran or C. Every major implementation of MPI is written in C.

Support for MPI C++ bindings is sketchy at best: Some of the MPI Datatypes are not available (e.g. MPI_DOUBLE), there are issues with I/O and the order that headers are included in the source files. There are issues of name mangling if the MPI library was built with C and the application is built with Fortran or C++. mpich2 FAQ has entries to help work through these issues. I am less familiar with Open MPI and it's particular behavior with Fortran and C++.

For your specific questions:

I think that you have a fundamental mis-understanding about what MPI is and is not, and how application code should interact with the MPI libraries.

Parallel Programming with MPI is an excellent reference for learning to program with MPI. The code examples are in C, and most of the MPI API's are shown in an example. I highly recommend that you work through this book to learn what parallel programing is and is not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top