LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Brian Barrett (brbarret_at_[hidden])
Date: 2007-09-29 23:58:38


On Sep 29, 2007, at 12:36 PM, XMATX_at_[hidden] wrote:

> i'm still very new to MPI. I want to use it within my C++ code.
> I'm wondering why for example the Send(..) or Recv(..) routines in
> C do have an bool return value
> and in C++ are void.
>
> Now how should i do this in C++?
>
> Perhaps something like that?
> try
> {
> MPI::COMM_WORLD.Recv(&n, 1, MPI::INT, MPI::ANY_SOURCE,
> MPI::ANY_TAG, status);
> }
> catch(MPI::Exception e)
> {
> ...//do something
> }
>
> is this the usual way or do i forget something?

By default (for both C and C++), errors on MPI communication will
case MPI to abort. So unless you're resetting the error handler on
the communicator in use, there's no need to check error conditions at
all. However, if you are (or plan to) reset the error handler, the C+
+ bindings throw exceptions on errors. So your example would be
correct.

There is nothing that says you should use the C++ MPI bindings if you
are writing C++ code. A high percentage of the C++ codes I deal with
use the C bindings to MPI. If you are more comfortable with the C
bindings to MPI, by all means use them. There are few advantages to
using the C++ bindings, and there can be a number of disadvantages.

Hope this helps,

Brian