[MPIWG Fortran] Type of MPI_Status

Bill Long longb at cray.com
Mon Mar 17 13:12:32 CDT 2014


On Mar 16, 2014, at 7:47 AM, Rolf Rabenseifner <rabenseifner at hlrs.de> wrote:

> Dear Junchao,
> 
> I had not the time to go through all details, but I detected two issues:
> 
> 1. TYPE(MPI_Status) must be declared with BIND(C).
>   It is missing in your example below.

This seems to be needed only so that the routines that convert between the Fortran and C versions of MPI_Status are callable from C.  It would have been a better design to have required that there be only one version of the MPI_Status struct - the Fortran and C structs are the same.  That would require that the Fortran version have bind(c) for some uses, but a separate C_Status would not be needed.  Also, the conversion routines could be discarded. 

> 
> 2. To declare an equivalent struct in C, i.e., 
>   the C type MPI_F08_status, you should use MPI_Fint
>   and not int.

Similarly, this complication would not be needed either.  Even with the current scheme, making a struct for C that looks like the Fortran struct would seem to not have any purpose.  It is useful to have a type definition in Fortran for the C struct (C_Status in the earlier example), which would be used in the  currently needed conversion routines.   I have yet to find any use for MPI_Fint.  It appears to be for a C function to call a non-bind(c) Fortran routine that has INTEGER arguments, but that seems unlikely to actually happen.  The library is in C and Fortran calls to C, not the other way around.  Unless there is some obscure usage in the Fortran tools interface.  (Craig and Jeff both know my solution to that. :) )

Cheers,
Bill


> 
> See MPI-3.0 p30:24-26 + ticket #415 and Sect. 17.2..5.
> 
> Best regards
> Rolf
> 
> 
> 
> ----- Original Message -----
>> From: "Junchao Zhang" <jczhang at mcs.anl.gov>
>> To: "MPI-WG Fortran working group" <mpiwg-fortran at lists.mpi-forum.org>
>> Sent: Saturday, March 15, 2014 10:52:42 PM
>> Subject: Re: [MPIWG Fortran] Type of MPI_Status
>> 
>> 
>> 
>> 
>> Rolf, you are right. Passing MPI%MPI_SOURCE as an argument will cause
>> problems. Thanks.
>> I list why I wanted to use c_int in MPI_Status. It is amusing.
>> Without c_int, the design is something like
>> 
>> 
>> type MPI_Status
>> INTEGER :: MPI_SOURCE, MPI_ERROR, MPI_TAG
>> ! other fields
>> end type MPI_Status
>> 
>> 
>> type(MPI_Status), parameter :: MPI_STATUS_IGNORE = ...
>> 
>> 
>> type c_Status
>> INTEGER(c_int) :: MPI_SOURCE, MPI_ERROR, MPI_TAG
>> ! other fields
>> end type c_Status
>> 
>> 
>> type(c_Status), BIND(C, name="MPIR_C_STATUS_IGNORE") ::
>> MPIR_C_STATUS_IGNORE
>> 
>> 
>> ! Declare the C function prototype to bind
>> function MPIR_Example_c(len, counts, status) result(ierror) BIND(C,
>> name="MPI_Example")
>> integer(c_int), intent(in) :: len
>> integer(c_int), intent(in) :: counts(len)
>> type(c_Status) :: status
>> integer(c_int) :: ierror
>> end function
>> 
>> 
>> subroutine MPI_Example_f08(len, counts, status, ierror)
>> integer, intent(in) :: len
>> integer, intent(in) :: counts(len)
>> type(MPI_Status) :: status
>> integer, optional :: ierror_c
>> 
>> 
>> integer(c_int), intent(in) :: len_c
>> integer(c_int), intent(in) :: counts_c(len)
>> type(c_Status) :: status_c
>> integer(c_int) :: ierror_c
>> 
>> 
>> if (c_int == kind(0) then ! Common case
>> if (c_loc(status) == c_loc(MPI_STATUS_IGNORE)) then ! In C
>> MPI_Example, it will checks again if status is 'IGNORE'. But we have
>> to duplicate the work here due to type difference of
>> MPI_STATUS_IGNORE and MPIR_C_STATUS_IGNORE.
>> ierror = MPIR_Example_c(len, counts, MPIR_C_STATUS_IGNORE)
>> else
>> ! ierror = MPIR_Example_c(len, counts, status) ! Compile error since
>> type(MPI_Status) mismatches type(c_Status) even c_int = INTEGER
>> ierror = MPIR_Example_c(len, counts, status_c)
>> status = status_c ! Note that = is overloaded. Can Compiler optimize
>> away this copy propogation? probably not.
>> endif ! This is bad since MPI_Status and c_Status are indeed the
>> same. Even worse if status is an array.
>> else
>> len_c = len
>> counts_c = counts
>> if (c_loc(status) == c_loc(MPI_STATUS_IGNORE)) then
>> ierror = MPIR_Example_c(len_c, counts_c, MPIR_C_STATUS_IGNORE)
>> else
>> ierror = MPIR_Example_c(len_c, counts_c, status_c)
>> status = status_c
>> endif
>> endif
>> 
>> 
>> if(present(ierror)) ierror = ierror_c
>> end subroutine
>> 
>> 
>> However, if I can use c_int in MPI_Status, then MPI_Status and
>> c_Status are the same. I will have
>> 
>> 
>> type MPI_Status
>> INTEGER(c_int) :: MPI_SOURCE, MPI_ERROR, MPI_TAG
>> ! other fields
>> end type MPI_Status
>> 
>> 
>> type(MPI_Status), BIND(C, name="MPI_STATUS_IGNORE") ::
>> MPI_STATUS_IGNORE
>> 
>> 
>> function MPIR_Example_c(len, counts, status) result(ierror) BIND(C,
>> name="MPI_Example")
>> integer(c_int), intent(in) :: len
>> integer(c_int), intent(in) :: counts(len)
>> type(MPI_Status) :: status ! Now use MPI_Status instead of c_Status
>> integer(c_int) :: ierror
>> end function
>> 
>> 
>> subroutine MPI_Example_f08(len, counts, status, ierror)
>> integer, intent(in) :: len
>> integer, intent(in) :: counts(len)
>> type(MPI_Status) :: status
>> integer, optional :: ierror_c
>> 
>> 
>> integer(c_int), intent(in) :: len_c
>> integer(c_int), intent(in) :: counts_c(len)
>> integer(c_int) :: ierror_c
>> 
>> 
>> if (c_int == kind(0) then
>> ierror = MPIR_Example_c(len, counts, status) ! Zero overhead incurred
>> on status.
>> else
>> len_c = len
>> counts_c = counts
>> ierror = MPIR_Example_c(len_c, counts_c, status)
>> endif
>> 
>> 
>> if(present(ierror)) ierror = ierror_c
>> end subroutine
>> 
>> 
>> 
>> 
>> 
>> --Junchao Zhang
>> 
>> 
>> On Sat, Mar 15, 2014 at 7:38 AM, Rolf Rabenseifner <
>> rabenseifner at hlrs.de > wrote:
>> 
>> 
>> Dear Junchao,
>> 
>> As long as you use status%MPI_SOURCE in an expression,
>> all is fine.
>> 
>> If you pass it to an application routine dummy argument
>> that is defined as INTEGER and your status%MPI_SOURCE
>> is define as INTEGER(C_INT) then you may get compiler
>> warnings or errors if size of both INTEGER types is different.
>> 
>> CALL foo(status%MPI_SOURCE)
>> 
>> with
>> SUBROUTINE foo(rank)
>> INTEGER :: rank
>> 
>> 
>> Best regards
>> Rolf
>> 
>> 
>> ----- Original Message -----
>>> From: "Junchao Zhang" < jczhang at mcs.anl.gov >
>>> To: "MPI-WG Fortran working group" mpi-forum.org >
>> 
>> 
>>> Sent: Saturday, March 15, 2014 11:54:38 AM
>>> Subject: Re: [MPIWG Fortran] Type of MPI_Status
>>> 
>>> 
>>> 
>>> My point is, with the C_INT implementation of MPI_Status, there
>>> should be no compilation warnings AND runtime errors, even if
>>> INTEGER kind is not c_int, since users can only operate MPI_Status
>>> through their public interfaces, in which we take care of data
>>> conversion.
>>> 
>>> 
>>> But for other arguments of type INTEGER or array of INTEGERs, I can
>>> not change their type. Users pass in an array of INTEGERs, I can
>>> not
>>> pretend they are c_int and don't do conversion.
>>> 
>>> 
>>> 
>>> --Junchao Zhang
>>> 
>>> 
>>> On Sat, Mar 15, 2014 at 3:33 AM, Rolf Rabenseifner <
>>> rabenseifner at hlrs.de > wrote:
>>> 
>>> 
>>> Junchao,
>>> 
>>> With the erratum ticket #415, your implementation
>>> with INTEGER(C_INT) is clearly wrong,
>>> but who cares as long as an application programmer cannot
>>> write an application code that produces compilation errors
>>> or warnings or infos due to your wrong implementation
>>> of TYPE(MPI_Status).
>>> 
>>> I do not exactly now the rules about Fortran subroutine
>>> prototype and overloading where handing over a INTEGER rank
>>> or a INTEGER(C_INT) rank may cause to choose different interfaces.
>>> 
>>> Maybe that Bill Long should comment on such strange things
>>> before you define any field within TYPE(MPI_Status) or
>>> any dummy argument in a routine declaration as INTEGER(C_INT)
>>> instead of INTEGER as defined in MPI-3.0.
>>> 
>>> 
>>> Best regards
>>> Rolf
>>> 
>>> ----- Original Message -----
>>>> From: "Junchao Zhang" < jczhang at mcs.anl.gov >
>>>> To: "MPI-WG Fortran working group" mpi-forum.org >
>>> 
>>> 
>>>> Sent: Saturday, March 15, 2014 12:11:35 AM
>>>> Subject: Re: [MPIWG Fortran] Type of MPI_Status
>>>> 
>>>> 
>>>> 
>>>> Not sure if it is worth discussing. Even if INTEGER and C_INT are
>>>> of
>>>> different size, I think I can still use C_INT in MPI_Status.
>>>> 
>>>> 
>>>> 
>>>> TYPE, BIND(C) :: MPI_Status
>>>> INTEGER(C_INT) :: MPI_SOURCE, MPI_TAG, MPI_ERROR
>>>> ... ! other fields
>>>> END TYPE MPI_Status
>>>> 
>>>> 
>>>> Since MPI_Status is a derived datatype, users access it through
>>>> its
>>>> public interfaces(i.e., %MPI_SOURCE, ..., MPI_STATUS_SIZE).
>>>> As long as MPI_STATUS_SIZE >= sizeof(MPI_STATUS)/sizeof(INTEGER),
>>>> who
>>>> cares its internals.
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> --Junchao Zhang
>>>> 
>>>> 
>>>> On Thu, Mar 13, 2014 at 10:56 AM, Rolf Rabenseifner <
>>>> rabenseifner at hlrs.de > wrote:
>>>> 
>>>> 
>>>> Jeff is right.
>>>> Bill's theoretical statement is also correct.
>>>> 
>>>> And ticket#415 is also correct because it resolves an
>>>> inconsistency
>>>> within the mpi_f08 interface.
>>>> 
>>>> Strange theoretical discussions are also there for
>>>> long Fortran INTEGER may not be identical with some shorter
>>>> INTEGER(C_int).
>>>> As a side effect also solved by this ticket.
>>>> 
>>>> 
>>>> Rolf
>>>> 
>>>> ----- Original Message -----
>>>> 
>>>>> From: "Jeff Hammond" < jeff.science at gmail.com >
>>>>> To: "MPI-WG Fortran working group" mpi-forum.org >
>>>>> Sent: Thursday, March 13, 2014 4:12:56 PM
>>>>> Subject: Re: [MPIWG Fortran] Type of MPI_Status
>>>>> 
>>>>> MPI should test for interoperability of Fortran's default
>>>>> integer
>>>>> and
>>>>> light the machine room on fire if it is not.
>>>>> 
>>>>> Jeff
>>>>> 
>>>>> On Thu, Mar 13, 2014 at 8:58 AM, Bill Long < longb at cray.com >
>>>>> wrote:
>>>>>> This does raise an earlier issue that it is
>>>> 
>>>> 
>>>>>> possible that Fortran’s default INTEGER is not an
>>>>>> interoperable
>>>>>> type, and thus the MPI_Status type should not be a BIND(C)
>>>>>> type
>>>>>> if
>>>>>> it has INTEGER components. Having BIND(C) does allow you to
>>>>>> declare a C global name MPI_STATUS_IGNORE in Fortran, which
>>>>>> solves
>>>>>> one problem nicely. I don’t see any advantage to having
>>>>>> INTEGER
>>>>>> components (as opposed to INTEGER(C_Int), for example). So
>>>>>> this
>>>>>> seems to represent the worse of the two options.
>>>>>> 
>>>>>> Cheers,
>>>>>> Bill
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> On Mar 13, 2014, at 8:36 AM, Jeff Squyres (jsquyres)
>>>>>> < jsquyres at cisco.com > wrote:
>>>>>> 
>>>>>>> Done. Good catch:
>>>>>>> 
>>>>>>> https://svn.mpi-forum.org/trac/mpi-forum-web/ticket/415
>>>>>>> 
>>>>>>> This is a trivial ticket, but if you could make sure it's
>>>>>>> ok,
>>>>>>> I'll
>>>>>>> send it to the mpi-forum list so that it can get added to
>>>>>>> the
>>>>>>> next meeting's agenda.
>>>>>>> 
>>>>>>> 
>>>>>>> On Mar 13, 2014, at 1:51 AM, Rolf Rabenseifner
>>>>>>> < rabenseifner at hlrs.de > wrote:
>>>>>>> 
>>>>>>>> Jeff and Junchao,
>>>>>>>> 
>>>>>>>> it is a missing word INTEGER in this part of the sentence
>>>>>>>> 
>>>>>>>> In whole MPI these three values are in Fortran INTEGER and
>>>>>>>> nothing else
>>>>>>>> 
>>>>>>>> Junchao, thank you for the hint that an erratum is neede
>>>>>>>> to prevent from such misinterpretation
>>>>>>>> 
>>>>>>>> Jeff, please can you file the errata ticket resulting in
>>>>>>>> 
>>>>>>>> ... containing three public INTEGER fields named ...
>>>>>>>> 
>>>>>>>> Best regards
>>>>>>>> Rolf
>>>>>>>> 
>>>>>>>> 
>>>>>>>> ----- Original Message -----
>>>>>>>>> From: "Junchao Zhang" < jczhang at mcs.anl.gov >
>>>>>>>>> To: "MPI-WG Fortran working group"
>>>> 
>>>> 
>>>>>>>>> mpi-forum.org >
>>>>>>>>> Sent: Thursday, March 13, 2014 4:49:49 AM
>>>>>>>>> Subject: [MPIWG Fortran] Type of MPI_Status
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Hello,
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> p30 of MPI3 says "In Fortran with USE mpi or INCLUDE
>>>>>>>>> ’mpif.h’,
>>>>>>>>> status
>>>>>>>>> is an array of INTEGERs of size MPI_STATUS_SIZE. ..., With
>>>>>>>>> Fortran
>>>>>>>>> USE mpi_f08, status is defined as the Fortran BIND(C)
>>>>>>>>> derived
>>>>>>>>> type
>>>>>>>>> TYPE(MPI_Status) containing three public fields named
>>>>>>>>> MPI_SOURCE
>>>>>>>>> ,
>>>>>>>>> MPI_TAG , and MPI_ERROR"
>>>>>>>>> 
>>>>>>>>> In other words, it does't say type of the three public
>>>>>>>>> fields
>>>>>>>>> must be
>>>>>>>>> INTEGER. So, in mpi_f08, can I declare MPI_Status as
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> TYPE, BIND(C) :: MPI_Status
>>>>>>>>> INTEGER(C_INT) :: MPI_SOURCE, MPI_TAG, MPI_ERROR
>>>>>>>>> ... ! other fields
>>>>>>>>> END TYPE MPI_Status
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> I find it makes MPI_Status binding easier. Since this type
>>>>>>>>> is
>>>>>>>>> interoperable with C, I do not need to allocate temp
>>>>>>>>> variables
>>>>>>>>> to do
>>>>>>>>> type conversion when INTEGER is not a C_INT.
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> --Junchao Zhang
>>>>>>>>> _______________________________________________
>>>>>>>>> mpiwg-fortran mailing list
>>>>>>>>> mpiwg-fortran at lists.mpi-forum.org
>>>>>>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>>>>>>> 
>>>>>>>> --
>>>>>>>> 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)
>>>>>>>> _______________________________________________
>>>>>>>> mpiwg-fortran mailing list
>>>>>>>> mpiwg-fortran at lists.mpi-forum.org
>>>>>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>>>>>> 
>>>>>>> 
>>>>>>> --
>>>>>>> Jeff Squyres
>>>>>>> jsquyres at cisco.com
>>>>>>> For corporate legal information go to:
>>>>>>> http://www.cisco.com/web/about/doing_business/legal/cri/
>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> mpiwg-fortran mailing list
>>>>>>> mpiwg-fortran at lists.mpi-forum.org
>>>>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>>>>> 
>>>>>> Bill Long
>>>>>> longb at cray.com
>>>>>> Fortran Technical Suport & voice:
>>>>>> 651-605-9024
>>>>>> Bioinformatics Software Development fax:
>>>>>> 651-605-9142
>>>>>> Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul,
>>>>>> MN
>>>>>> 55101
>>>>>> 
>>>>>> 
>>>>>> _______________________________________________
>>>>>> mpiwg-fortran mailing list
>>>>>> mpiwg-fortran at lists.mpi-forum.org
>>>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> Jeff Hammond
>>>>> jeff.science at gmail.com
>>>>> _______________________________________________
>>>>> mpiwg-fortran mailing list
>>>>> mpiwg-fortran at lists.mpi-forum.org
>>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>>> 
>>>> --
>>>> 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)
>>>> _______________________________________________
>>>> mpiwg-fortran mailing list
>>>> mpiwg-fortran at lists.mpi-forum.org
>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>>> 
>>>> _______________________________________________
>>>> mpiwg-fortran mailing list
>>>> mpiwg-fortran at lists.mpi-forum.org
>>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>> 
>>> --
>>> 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)
>>> _______________________________________________
>>> mpiwg-fortran mailing list
>>> mpiwg-fortran at lists.mpi-forum.org
>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>>> 
>>> _______________________________________________
>>> mpiwg-fortran mailing list
>>> mpiwg-fortran at lists.mpi-forum.org
>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>> 
>> --
>> 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)
>> _______________________________________________
>> mpiwg-fortran mailing list
>> mpiwg-fortran at lists.mpi-forum.org
>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>> 
>> _______________________________________________
>> mpiwg-fortran mailing list
>> mpiwg-fortran at lists.mpi-forum.org
>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
> 
> -- 
> 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)
> _______________________________________________
> mpiwg-fortran mailing list
> mpiwg-fortran at lists.mpi-forum.org
> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran

Bill Long                                                                       longb at cray.com
Fortran Technical Suport  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101





More information about the mpiwg-fortran mailing list