[MPIWG Fortran] Question about named constants

William Gropp wgropp at illinois.edu
Fri Jun 19 07:45:27 CDT 2015


Given the intent of the wording with respect to C, I don’t think the test is valid (in C, the clear intent was that handles could be pointers resolved only at link time).

Bill

On Jun 18, 2015, at 10:19 PM, Bill Long <longb at cray.com> wrote:

> 
> On Jun 18, 2015, at 5:52 PM, Junchao Zhang <jczhang at mcs.anl.gov> wrote:
> 
>> In OpenMPI F08, those predefined MPI datatypes are not "parameter variables".  Thus OMPI failed to compile an MPICH F08 test, which has
>> 
>>  INTEGER, PARAMETER :: nb=2
>>  TYPE(MPI_DATATYPE) :: types(nb)=(/MPI_DOUBLE_PRECISION, MPI_CHAR/)
>> 
>> Jeff Squyres and I discussed in emails.  I don't know whether this is correct according to the MPI spec.
> 
> Given the wording in the spec, I’m not sure either.  BTW, there is no such thing as a “parameter variable”.  Something with the parameter attribute is a constant, and hence not a variable.  It is true that an initialization expression in a type declaration is required to be a constant expression.   If OMPI is declaring these datatypes as variables instead of constants, then there would be a problem compiling the above code using their module.
> 
> Cheers,
> Bill
> 
> 
> 
>> 
>> 
>> 
>> --Junchao Zhang
>> 
>> On Thu, Jun 18, 2015 at 12:48 PM, Bill Long <longb at cray.com> wrote:
>> 
>> On Jun 18, 2015, at 11:05 AM, Junchao Zhang <jczhang at mcs.anl.gov> wrote:
>> 
>>> Hello, Fortran experts,
>>>  I am a little puzzled by MPI-3.1 Chapter 2.5.4,
>> 
>> Not surprising.  The (mis)use of terminology is confusing at best.
>> 
>>> 
>>> All named constants, with the exceptions noted below for Fortran, can be used in
>>> initialization expressions or assignments, but not necessarily in array declarations or as
>>> labels in C switch or Fortran select/case statements.  This implies named constants
>>> to be link-time but not necessarily compile-time constants.
>> 
>> In Fortran “named constant” is a defined term.  They are declared with the PARAMETER attribute.  And can be used in most places where literal constants can be used, including array declarations.  They cannot be used as statement labels, though I think the reference to “Fortran select/case statements” intends to talk about case-values, and not labels.  Named constants can be used as case-values.
>> 
>>> 
>>> Then in F08, should MPI_INTEGER be declared as a parameter variable?
>> 
>> Yes.  That’s what I did in my prototype mpi_f08 modules.
>> 
>>> If no, then I get an error when compiling this initialization expression with gfortran
>>>          type(MPI_Datatype) :: dtype = MPI_INTEGER
>>> 
>>>    Error: Parameter 'mpi_integer' at (1) has not been declared or is a variable, which does not reduce to a constant expression
>>> 
>>> If yes, then of course I can use MPI_INTEGER in Fortran select/case.
>> 
>> Right.
>> 
>>> 
>>> Another question is what is the meaning of "link-time constants". I could not find in MPI. Does it mean I can use MPI_INTEGER after main before MPI_Init?
>> 
>> I suspect this is a historical artifact where some special head standing was needed to correctly define MPI_INTEGER based on whether the code was compiled with -i4 or -i8 (or equivalent, depending on the compiler).  For the modern case of using the mpi_f08 module, you just compile the mpi_f08 module twice (once with -i4 and once with -i8) and then have the compile command select the right actual module to reference based on how the using program unit is compiled.   Generally, values of objects are not set at link time;  addresses of objects are set at link time.   MPI objects that represent addresses  (MPI_BOTTOM ??) are examples.  If MPI_INTEGER is accessible, you can reference it.  If should not have anything to do with whether MPI_Init has been called.
>> 
>> Perhaps some of the MPI historians can shed more light on this terminology.  I suspect it would be completely moot if we got rid of mpif.h.
>> 
>> Cheers,
>> Bill
>> 
>> 
>>> 
>>> Thank you!
>>> 
>>> --Junchao Zhang
>>> _______________________________________________
>>> 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 Support  &                                  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
>> 
>> _______________________________________________
>> 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 Support  &                                  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




More information about the mpiwg-fortran mailing list