[Mpi-forum] An f2c question

Rolf Rabenseifner rabenseifner at hlrs.de
Tue Aug 24 15:28:49 CDT 2021


Dear Howard,

SUBROUTINE MPI_TYPE_COMMIT(DATATYPE, IERR)
INTEGER :: IERR
! some module USE to include the definition of TYPE(MPI_Datatype)
TYPE(MPI_Datatype) :: DATATYPE
CALL MPI_X_TYPE_COMMIT(DATATYPE%IMPI_VAL, IERR)
RETURN
END

I do not know how to handle the optional ierr, but here is the way you should handle the datatype handle.

Best regards
Rolf

----- Original Message -----
> From: "Main MPI Forum mailing list" <mpi-forum at lists.mpi-forum.org>
> To: "Main MPI Forum mailing list" <mpi-forum at lists.mpi-forum.org>
> Cc: "Pritchard" <howardp at lanl.gov>
> Sent: Tuesday, August 24, 2021 10:19:27 PM
> Subject: [Mpi-forum] An f2c question

> 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
> 
> 
> 
> 
> 
>> 
> 
> 
> 
>	
> 
> Howard Pritchard
> 
> Research Scientist
> 
> HPC-ENV
> 
> 
> 
> Los Alamos National Laboratory
> 
> howardp at lanl.gov
> 
> 
> 
> [ https://www.instagram.com/losalamosnatlab/ ] [
> https://twitter.com/LosAlamosNatLab ] [
> https://www.linkedin.com/company/los-alamos-national-laboratory/ ] [
> https://www.facebook.com/LosAlamosNationalLab/ ]
> 
> 
> 
> 
> 
> 
> _______________________________________________
> mpi-forum mailing list
> mpi-forum at lists.mpi-forum.org
> https://lists.mpi-forum.org/mailman/listinfo/mpi-forum

-- 
Dr. Rolf Rabenseifner . . . . . . . . . .. email rabenseifner at hlrs.de .
High Performance Computing Center (HLRS) . phone ++49(0)711/685-65530 .
University of Stuttgart . . . . . . . . .. fax ++49(0)711 / 685-65832 .
Head of Dpmt Parallel Computing . . . www.hlrs.de/people/rabenseifner .
Nobelstr. 19, D-70550 Stuttgart, Germany . . . . (Office: Room 1.307) .


More information about the mpi-forum mailing list