20.3.5. Status

PreviousUpNext
Up: Language Interoperability Next: MPI Opaque Objects Previous: Transfer of Handles

The following two procedures are provided in C to convert from a Fortran (with the mpi module or deprecated mpif.h) status (which is an array of integers) to a C status (which is a structure), and vice versa. The conversion occurs on all the information in status, including that which is hidden. That is, no status information is lost in the conversion.


int MPI_Status_f2c(const MPI_Fint *f_status, MPI_Status *c_status)

If f_status is a valid Fortran status, but not the Fortran value of MPI_STATUS_IGNORE or MPI_STATUSES_IGNORE, then MPI_Status_f2c returns in c_status a valid C status with the same content. If f_status is the Fortran value of MPI_STATUS_IGNORE or MPI_STATUSES_IGNORE, or if f_status is not a valid Fortran status, then the call is erroneous.

In C, such an f_status array can be defined with MPI_Fint f_status[ MPI_F_STATUS_SIZE]. Within this array, one can use in C the indexes MPI_F_SOURCE, MPI_F_TAG, and MPI_F_ERROR, to access the same elements as in Fortran with MPI_SOURCE, MPI_TAG and MPI_ERROR. The C indexes are 1 less than the corresponding indexes in Fortran due to the different default array start indexes in both languages.

The C status has the same source, tag and error code values as the Fortran status, and returns the same answers when queried for count, elements, and cancellation. The conversion function may be called with a Fortran status argument that has an undefined error field, in which case the value of the error field in the C status argument is undefined.

Two global variables of type MPI_Fint*, MPI_F_STATUS_IGNORE and MPI_F_STATUSES_IGNORE are declared in mpi.h. They can be used to test, in C, whether f_status is the Fortran value of MPI_STATUS_IGNORE or MPI_STATUSES_IGNORE defined in the mpi module or (deprecated) mpif.h. These are global variables, not C constant expressions and cannot be used in places where C requires constant expressions. Their value is defined only between the calls to MPI_INIT and MPI_FINALIZE and should not be changed by user code.

To do the conversion in the other direction, we have the following:


int MPI_Status_c2f(const MPI_Status *c_status, MPI_Fint *f_status)

This call converts a C status into a Fortran status, and has a behavior similar to MPI_Status_f2c. That is, the value of c_status must not be either MPI_STATUS_IGNORE or MPI_STATUSES_IGNORE.


Advice to users.

There exists no separate conversion function for arrays of statuses, since one can simply loop through the array, converting each status with the routines in Figure 40. ( End of advice to users.)

Rationale.

The handling of MPI_STATUS_IGNORE is required in order to layer libraries with only a C wrapper: if the Fortran call has passed MPI_STATUS_IGNORE, then the C wrapper must handle this correctly. Note that this constant need not have the same value in Fortran and C. If MPI_Status_f2c were to handle MPI_STATUS_IGNORE, then the type of its result would have to be MPI_Status**, which was considered an inferior solution. ( End of rationale.)
Using the mpi_f08 Fortran module, a status is declared as TYPE(MPI_Status). The C type MPI_F08_status can be used to pass a Fortran TYPE(MPI_Status) argument into a C routine. Figure 40 illustrates all status conversion routines. Some are only available in C, some in both C and the Fortran mpi and mpi_f08 interfaces (but not in the deprecated mpif.h include file).

Image file


Figure 40: Status conversion routines


int MPI_Status_f082c(const MPI_F08_status *f08_status, MPI_Status *c_status)

This C routine converts a Fortran mpi_f08 TYPE(MPI_Status) into a C MPI_Status.


int MPI_Status_c2f08(const MPI_Status *c_status, MPI_F08_status *f08_status)

This C routine converts a C MPI_Status into a Fortran mpi_f08 TYPE(MPI_Status). Two global variables of type MPI_F08_status*, MPI_F08_STATUS_IGNORE and MPI_F08_STATUSES_IGNORE are declared in mpi.h. They can be used to test, in C, whether f_status is the Fortran value of MPI_STATUS_IGNORE or MPI_STATUSES_IGNORE defined in the mpi_f08 module. These are global variables, not C constant expressions and cannot be used in places where C requires constant expressions. Their value is defined only between the calls to MPI_INIT and MPI_FINALIZE and should not be changed by user code.

Conversion between the two Fortran versions of a status can be done with:

MPI_STATUS_F2F08(f_status, f08_status)
IN f_statusstatus object declared as array (status)
OUT f08_statusstatus object declared as named type (status)
int MPI_Status_f2f08(const MPI_Fint *f_status, MPI_F08_status *f08_status)
Fortran 2008 binding
MPI_Status_f2f08(f_status, f08_status, ierror)

INTEGER, INTENT(IN) :: f_status(MPI_STATUS_SIZE)
TYPE(MPI_Status), INTENT(OUT) :: f08_status
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding (the following procedure is not available with mpif.h)
MPI_STATUS_F2F08(F_STATUS, F08_STATUS, IERROR)

INTEGER :: F_STATUS(MPI_STATUS_SIZE), IERROR
TYPE(MPI_Status) :: F08_STATUS

This routine converts a Fortran INTEGER, DIMENSION(MPI_STATUS_SIZE) status array into a Fortran mpi_f08 TYPE(MPI_Status).

MPI_STATUS_F082F(f08_status, f_status)
IN f08_statusstatus object declared as named type (status)
OUT f_statusstatus object declared as array (status)
C binding
int MPI_Status_f082f(const MPI_F08_status *f08_status, MPI_Fint *f_status)
Fortran 2008 binding
MPI_Status_f082f(f08_status, f_status, ierror)

TYPE(MPI_Status), INTENT(IN) :: f08_status
INTEGER, INTENT(OUT) :: f_status(MPI_STATUS_SIZE)
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding (the following procedure is not available with mpif.h)
MPI_STATUS_F082F(F08_STATUS, F_STATUS, IERROR)

TYPE(MPI_Status) :: F08_STATUS
INTEGER :: F_STATUS(MPI_STATUS_SIZE), IERROR

This routine converts a Fortran mpi_f08 TYPE(MPI_Status) into a Fortran INTEGER, DIMENSION(MPI_STATUS_SIZE) status array.


PreviousUpNext
Up: Language Interoperability Next: MPI Opaque Objects Previous: Transfer of Handles


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023