Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] opening a file with MPI-IO
From: Rob Latham (robl_at_[hidden])
Date: 2013-07-19 15:23:57

On Fri, May 17, 2013 at 11:00:36AM +0200, Peter van Hoof wrote:
> Dear users,
> I have been banging my head against the wall for some time to find a
> reliable and portable way to determine if a call to
> MPI::File::Open() was successful or not.

Sorry for the long delay in responding

In C, we do it like this:

static void handle_error(int errcode, char *str)
        char msg[MPI_MAX_ERROR_STRING];
        int resultlen;
        MPI_Error_string(errcode, msg, &resultlen);
        fprintf(stderr, "%s: %s\n", str, msg);
        MPI_Abort(MPI_COMM_WORLD, 1);

errcode = MPI_File_open(MPI_COMM_SELF, filename,
if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_FILE_OPEN");

With the C++ bindings... ugh what a mess. I had to crack open the
yellow book to find out the answer. But on page 18 it's pretty

Quoting: C++ functions do not return error codes [...]

More Quoting: Advice to Users: C++ programmers that want to handle MPI
errors on their own should use th MPI::ERRORS_THROW_EXCEPTIONS error
handler, rather than MPI::ERROR_RETURN, which is used for that purpose
in C.

It's important to note that MPI-IO routines *do* use ERROR_RETURN as
the error handler, so you will have to take the additional step of
setting that.


Rob Latham
Mathematics and Computer Science Division
Argonne National Lab, IL USA