How do I retain precision for a Fortran MPI program in a portable way?

前端 未结 3 1972
独厮守ぢ
独厮守ぢ 2020-12-11 01:36

I have a Fortran program where I specify the kind of the numeric data types in an attempt to retain a minimum level of precision, regardless of what compiler is

3条回答
  •  醉梦人生
    2020-12-11 01:51

    How about:

    integer, parameter :: DOUBLE_PREC = kind(0.0d0)
    integer, parameter :: SINGLE_PREC = kind(0.0e0)
    
    integer, parameter :: MYREAL = DOUBLE_PREC
    
    
    if (MYREAL .eq. DOUBLE_PREC) then
       MPIREAL = MPI_DOUBLE_PRECISION
    else if (MYREAL .eq. SINGLE_PREC) then
       MPIREAL = MPI_REAL
    else
       print *, "Erorr: Can't figure out MPI precision."
       STOP
    end if
    

    and use MPIREAL instead of MPI_DOUBLE_PRECISION from then on.

提交回复
热议问题