Open MPI logo

Open MPI User's Mailing List Archives

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

Subject: Re: [OMPI users] Mixing the FORTRAN and C APIs.
From: Tim Prince (tcprince_at_[hidden])
Date: 2011-05-06 11:27:02

On 5/6/2011 7:58 AM, Tim Hutt wrote:
> Hi,
> I'm trying to use PARPACK in a C++ app I have written. This is an
> FORTRAN MPI routine used to calculate SVDs. The simplest way I found
> to do this is to use f2c to convert it to C, and then call the
> resulting functions from my C++ code.
> However PARPACK requires that I write some user-defined operations to
> be parallel using MPI. So far I have just been calling the FORTRAN
> versions of the MPI functions from C, because I wasn't sure whether
> you can mix the APIs. I.e. I've been doing this:
> -----8<-----
> extern "C"
> {
> int mpi_init__(integer *);
> int mpi_comm_rank__(integer *, integer *, integer *);
> int mpi_comm_size__(integer *, integer *, integer *);
> int mpi_finalize__(integer *);
> int mpi_allgatherv__(doublereal *, integer *, integer *, doublereal
> *, integer *, integer *, integer *, integer *);
> // OpenMPI version.
> const integer MPI_DOUBLE_PRECISION = 17;
> }
> bool MPI__Init()
> {
> integer ierr = 0;
> mpi_init__(&ierr);
> return ierr == 0;
> }
> ----8<----
> It works so far, but is getting quite tedious and seems like the wrong
> way to do it. Also I don't know if it's related but when I use
> allgatherv it gives me a segfault:
> [panic:20659] *** Process received signal ***
> [panic:20659] Signal: Segmentation fault (11)
> [panic:20659] Signal code: Address not mapped (1)
> [panic:20659] Failing at address: 0x7f4effffffe8
> [panic:20659] [ 0] /lib/ [0x7f4f8fd62af0]
> [panic:20659] [ 1] /usr/lib/ [0x7f4f905ec0c3]
> [panic:20659] [ 2] ./TDLSM() [0x510322]
> [panic:20659] [ 3] ./TDLSM() [0x50ec8d]
> [panic:20659] [ 4] ./TDLSM() [0x404ee7]
> [panic:20659] [ 5] /lib/ [0x7f4f8fd4dc4d]
> [panic:20659] [ 6] ./TDLSM() [0x404c19]
> [panic:20659] *** End of error message ***
> So my question is: Can I intermix the C and FORTRAN APIs within one
> program? Oh and also I think the cluster I will eventually run this on
> (, if anyone is from Imperial) doesn't use OpenMP, so
> what about other MPI implementations?
If you want to use the MPI Fortran library, don't convert your Fortran
to C. It's difficult to understand why you would consider f2c a
"simplest way," but at least it should allow you to use ordinary C MPI
function calls.
The MPI Fortran library must be built against the same Fortran run-time
libraries which you use for your own Fortran code. The header files for
the Fortran MPI calls probably don't work in C. It would be a big
struggle to get them to work with f2c, since f2c doesn't have much
ability to deal with headers other than its own.
There's no reason you can't make both C and Fortran MPI calls in the
same application. If you mean mixing a send from one language with a
receive in another, I think most would avoid that.
Whether someone uses OpenMP has little to do with choice of MPI
implementation. Some of us still may be cursing the choice of OpenMPI
for the name of an MPI implementation.

Tim Prince