[petsc-dev] fortran literals
Blaise A Bourdin
bourdin at lsu.edu
Thu Sep 1 18:15:25 CDT 2016
Hi,
If I recall correctly, fortran does not mandate that "selected_real_kind(5)" means the same across compilers, so that hardcoding kind values may not be portable.
Instead, I would recommend the following (not my idea, it was proposed by Michael Metcalf in comp.lang.fortran a _long_ time ago) in a top-level module.
! The following ensures that mef90 and PETSC real types are compatible:
! thanks to Michael Metcalf in comp.lang.fortran
PetscReal,Parameter :: PReal = 1.0
Integer,Parameter,Public :: Kr = Selected_Real_Kind(Precision(PReal))
PetscInt,Parameter :: PInt = 1
Integer,Parameter,Public :: Ki = Selected_Int_Kind(PInt)
PetscLogDouble,Parameter :: flop = 1.0
Integer,Parameter,Public :: PFlop = Selected_Real_Kind(Precision(flop))
so that Real(Kind = Kr) is the same as PetscReal, and literals can be written 1.234_Kr or 23_flop.
I guess PETSc could define them in the petsc module and inherited from "use petsc”.
Blaise
> On Sep 1, 2016, at 5:37 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
>
>> On Sep 1, 2016, at 5:28 PM, Munson, Todd <tmunson at mcs.anl.gov> wrote:
>>
>>
>> Which platforms do not define PETSC_USE_FORTRANKIND?
>
> It uses it everywhere the Fortran compiler supports it.
>
> # reverse of the above - but more standard thing to do for F90 compilers
> def checkFortranKind(self):
> '''Checks whether selected_int_kind etc work USE_FORTRANKIND'''
> self.pushLanguage('FC')
> body = '''
> integer(kind=selected_int_kind(10)) i
> real(kind=selected_real_kind(10)) d
> '''
> if self.checkCompile('', body):
> self.addDefine('USE_FORTRANKIND', 1)
> self.popLanguage()
> return
>
> Presumably any Fortran compiler that supports F90 supports it so it is not unreasonable for us to just require it and simplify PETSc in a few places.
>
>
>
>
>> Are they important
>> or can we drop support for them?
>>
>> I could probably hack the D or Q for the others, but it would probably
>> be ugly.
>>
>> Or I could just overrule my OCD today...
>>
>> Todd.
>>
>>> On Sep 1, 2016, at 5:08 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>
>>>
>>>> On Sep 1, 2016, at 4:37 PM, Munson, Todd <tmunson at mcs.anl.gov> wrote:
>>>>
>>>>
>>>> Cool!
>>>>
>>>> For what its worth, that only works when PETSC_USE_FORTRANKIND is true.
>>>> I'm not sure how many of the Petsc builds have this flag set.
>>>
>>> in the other case could you try to tack on the D or Q business?
>>>
>>> Barry
>>>
>>>>
>>>> Any idea how to do the same thing in C?
>>>>
>>>> Todd.
>>>>
>>>>> On Sep 1, 2016, at 4:13 PM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
>>>>>
>>>>>
>>>>> On 1 September 2016 at 23:05, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>>> I didn't have a solution to this
>>>>>
>>>>> ! These lines should be added to $PETSC_DIR/include/petsc/finclude/petscsysdef.h
>>>>> #if defined(PETSC_USE_REAL_SINGLE)
>>>>> integer, parameter :: PETSC_REAL_KIND = selected_real_kind(5)
>>>>> #elif defined(PETSC_USE_REAL_DOUBLE)
>>>>> integer, parameter :: PETSC_REAL_KIND = selected_real_kind(10)
>>>>> #elif defined(PETSC_USE_REAL___FLOAT128)
>>>>> integer, parameter :: PETSC_REAL_KIND = selected_real_kind(20)
>>>>> #endif
>>>>>
>>>>> ! User code should write literals this way
>>>>> PetscReal x
>>>>> x = 0.123456789123456789123456789_PETSC_REAL_KIND
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Lisandro Dalcin
>>>>> ============
>>>>> Research Scientist
>>>>> Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
>>>>> Extreme Computing Research Center (ECRC)
>>>>> King Abdullah University of Science and Technology (KAUST)
>>>>> http://ecrc.kaust.edu.sa/
>>>>>
>>>>> 4700 King Abdullah University of Science and Technology
>>>>> al-Khawarizmi Bldg (Bldg 1), Office # 0109
>>>>> Thuwal 23955-6900, Kingdom of Saudi Arabia
>>>>> http://www.kaust.edu.sa
>>>>>
>>>>> Office Phone: +966 12 808-0459
>>>>
>>>
>>
>
--
Department of Mathematics and Center for Computation & Technology
Louisiana State University, Baton Rouge, LA 70803, USA
Tel. +1 (225) 578 1612, Fax +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
More information about the petsc-dev
mailing list