bspline-fortran icon indicating copy to clipboard operation
bspline-fortran copied to clipboard

pgfortran compilation fail

Open yushiro-yamashita opened this issue 2 years ago • 1 comments

PGI Fortran compiler gives the following error when compiling the sub_module:

bspline-fortran/src> pgfortran -c -Ktrap=fp bspline_kinds_module.F90 bspline_sub_module.f90 
bspline_kinds_module.F90:
bspline_sub_module.f90:
PGF90-W-0155-Integer overflow occurred when evaluating ** (bspline_sub_module.f90: 3615)
PGF90-S-0098-Divide by zero (bspline_sub_module.f90: 3615)
  0 inform,   1 warnings,   1 severes, 0 fatal for dbint4

This error caused by line 3615 in bspline_sub_module.f90

real(wp),parameter :: wdtol = radix(1.0_wp)**(1-digits(1.0_wp)) !! d1mach(4)

The types of radix and digits are integer, so the right-hand side of this expression is (integer)^(integer) form. Therefore, when the result of radix(1.0_wp)**(1-digits(1.0_wp)) is too small for the integer type, the overflow causes. (Perhaps other compilers do type conversion automatically, but the PGI compiler does not.)

Possible alternatives are:

real(wp),parameter :: wdtol = real(radix(1.0_wp), kind=wp)**(1-digits(1.0_wp)) !! d1mach(4)

or

real(wp),parameter :: wdtol = epsilon(1.0_wp) !! d1mach(4)

yushiro-yamashita avatar Jun 22 '22 10:06 yushiro-yamashita

Ah interesting. Yes, I think this is the way to go:

real(wp),parameter :: wdtol = real(radix(1.0_wp), dp)**(1 - digits(1.0_wp))

I you make a merge request I can merge it in.

jacobwilliams avatar Jun 22 '22 15:06 jacobwilliams