[Mpi-forum] An f2c question

Pritchard Jr., Howard howardp at lanl.gov
Tue Aug 24 15:19:27 CDT 2021


Hi All,

In porting an MPI application written mainly in Fortran and a little c to using mpi_f08 rather than mpi, I’ve hit an issue.

Namely, how would I write example 19.11 in the MPI 4 standard if the app uses type(MPI_Type) rather than integer?
Note I’m working with an application, so the MPI_Type structure is opaque, or at least I thought we’re supposed to treat it as opaque.

Here’s the example:


Example 19.11 The example below illustrates how the Fortran MPI function

MPI_TYPE_COMMIT can be implemented by wrapping the C MPI function

MPI_Type_commit with a C wrapper to do handle conversions. In this example a Fortran-C

interface is assumed where a Fortran function is all upper case when referred to from C and

arguments are passed by addresses.

! FORTRAN PROCEDURE

SUBROUTINE MPI_TYPE_COMMIT(DATATYPE, IERR)

INTEGER :: DATATYPE, IERR

CALL MPI_X_TYPE_COMMIT(DATATYPE, IERR)

RETURN

END

/* C wrapper */

void MPI_X_TYPE_COMMIT(MPI_Fint *f_handle, MPI_Fint *ierr)

{

MPI_Datatype datatype;

datatype = MPI_Type_f2c(*f_handle);

*ierr = (MPI_Fint)MPI_Type_commit(&datatype);

*f_handle = MPI_Type_c2f(datatype);

return;

}

Now I suspect that most of the time if one has some old ‘c’ code assuming a pointer to a 4 byte fortran integer argument for the datatype is just going to work, but I’d rather not just try to be lucky.
Anyway, there are fortran gurus on this project and they’d be sure to want a better solution.

Thanks for any help/ideas,

Howard


—

[signature_61897647]

Howard Pritchard
Research Scientist
HPC-ENV

Los Alamos National Laboratory
howardp at lanl.gov

[signature_577235141]<https://www.instagram.com/losalamosnatlab/>[signature_692833302]<https://twitter.com/LosAlamosNatLab>[signature_2019430084]<https://www.linkedin.com/company/los-alamos-national-laboratory/>[signature_231667440]<https://www.facebook.com/LosAlamosNationalLab/>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20210824/cec4821c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 4349 bytes
Desc: image001.png
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20210824/cec4821c/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 1980 bytes
Desc: image002.png
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20210824/cec4821c/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 1516 bytes
Desc: image003.png
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20210824/cec4821c/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 1333 bytes
Desc: image004.png
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20210824/cec4821c/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 998 bytes
Desc: image005.png
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20210824/cec4821c/attachment-0009.png>


More information about the mpi-forum mailing list