MuscularBeaverWhoosh
MuscularBeaverWhoosh

Reputation: 41

Adding MPI support to a C++ program

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:

For example:

MyClass obj;

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

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

z = obj.result();

Upvotes: 3

Views: 4974

Answers (4)

Xorlev
Xorlev

Reputation: 8643

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.

Upvotes: 6

Stan Graves
Stan Graves

Reputation: 6955

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.

Upvotes: 2

sharptooth
sharptooth

Reputation: 170499

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.

Upvotes: 6

Ed James
Ed James

Reputation: 10607

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

Upvotes: 6

Related Questions