I am playing around with selected_real_kind() against real(kind=8) to check how much extra processor time I require to improve numerical precision. The set of parameters I use are:
module param
implicit none
!extended double precision
INTEGER, PARAMETER :: xtd = SELECTED_REAL_KIND(16, 40)
save
!List of Input paramters and constants
real(xtd), parameter :: PI =4.0_xtd*atan(1.0_xtd)
integer, parameter :: L = 512
integer, parameter :: steps = 160000
real(xtd), parameter :: dt = 0.001_xtd
real(xtd), parameter :: lambda = 1.0_xtd
real(xtd), parameter :: mu = 0.0_xtd
real(xtd), parameter :: a = dt*(lambda+mu), b = dt*(lambda-mu)
end module param
The output when I print these parameters is:
Pi = 3.14159265358979323851
L = 512
steps = 160000
dt = 9.99999999999999999958E-0004
lambda = 1.00000000000000000000
mu = 0.00000000000000000000
a = dt*(Lambda+Mu) = 9.99999999999999999958E-0004
b = dt*(Lambda-Mu) = 9.99999999999999999958E-0004
The code for double precision real(kind=8),
module param
implicit none
save
!List of Input paramters and constants
real(kind=8), parameter :: PI =4.d0*atan(1.d0)
integer, parameter :: L = 512
integer, parameter :: steps = 160000
real(kind=8), parameter :: dt = 0.001d0
real(kind=8), parameter :: lambda = 1.0d0
real(kind=8), parameter :: mu = 0.0d0
real(kind=8), parameter :: a = dt*(lambda+mu), b = dt*(lambda-mu)
end module param
the output for which is
Pi = 3.1415926535897931
L = 512
steps = 160000
dt = 1.0000000000000000E-003
lambda = 1.0000000000000000
mu = 0.0000000000000000
a = dt*(Lambda+Mu) = 1.0000000000000000E-003
b = dt*(Lambda-Mu) = 1.0000000000000000E-003
I fear this difference in numerical constants may be contributing to the slower run-time for a marginally precise constant. Is there a better way to write these parameters using selected_real_kind()?