Why are resulsts of silverfrost and gfortran different?

293 Views Asked by At

When I run my code with Silverfrost fortran, the result is -2.987531633638E-02. But with gfortran (under cygwin and ubuntu linux) it is -2.9875316336381942E-002. My code is here:

program seebeck

real*8::ss
integer::ix,i
complex,parameter::i1=(0.0,1.0)

call quad3d(0.,190.,ss)
write(*,*) "result:",ss
stop
end program seebeck

  SUBROUTINE quad3d(x1,x2,ss)
  REAL:: x1,x2
  external f1
  real*8::ss,f1
  call qgausep(f1,x1,x2,ss)
  return
  END
  SUBROUTINE qgausep(f2,a,b,ss)
  external f2
  REAL:: a,b
  real*8::ss,f2
  INTEGER j
  REAL*8 dx,xm,xr,w(5),x(5)
  SAVE w,x
  DATA w/.2955242247,.2692667193,.2190863625,.1494513491,.0666713443/
  DATA x/.1488743389,.4333953941,.6794095682,.8650633666,.9739065285/
  xm=0.5*(b+a)
  xr=0.5*(b-a)
  ss=0
  do 11 j=1,5
    dx=xr*x(j)
    ss=ss+w(j)*(f2(xm+dx)+f2(xm-dx))
  11    continue
  ss=xr*ss
  return
  END

  function f1(t)
  real*8::t,f1
  f1=cos(t)/(1+exp(t))**2
  end function

There is a huge difference between the two results. I cannot explain the cause of this difference as a floating point inaccuracy.

Note: My code is a draft version and has no physical meaning.

1

There are 1 best solutions below

1
macelee On

This has something to do with how different compilers handling your data assignment at line 26/27 of your code. You defined both w and x as double-precision arrays, but only initialize them with lower precision values. This will introduce some floating point inaccuracy. In fact if I pass your code through the NAG compiler (which is known to be very strict), it gives a warning:

Warning: test.f90, line 26: Low-precision data-value assigned to high-precision data-object

To confirm, you can print out the values in array w and x to see if they are different when using different compilers.