Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Problems with IFC 8.0 and CSQRT

Deleted_U_Intel
Employee
597 Views

I'm having some trouble with the CSQRT in IFC 8.0. It seems to give different results on the same data depending on the subroutine it is contained in. Example:

program test
implicit none
COMPLEX z
z = (-0.5,0.)
write(6,*) 'z =',z,' csqrt =',CSQRT(z*z-1.)
call W(z)
stop
end

SUBROUTINE W(dummy)
IMPLICIT NONE
complex dummy
COMPLEX z

write(6,*) 'Using assigned values for kz and k'
z = (-0.5,0.)
write(6,*) 'z =',z,' csqrt =',CSQRT(z*z-1.)
return
END


This program outputs:

z = (-0.5000000,0.0000000E+00) csqrt = (0.0000000E+00,-0.8660254)
Using assigned values for kz and k
z = (-0.5000000,0.0000000E+00) csqrt = (0.0000000E+00,0.8660254)


Thus the complex part changes sign. g77 handles the code fine and so does IFC 7.0

0 Kudos
3 Replies
TimP
Honored Contributor III
597 Views
It looks like this comes under the heading of how to minimize incidental numerical differences. A few suggestions:

Replace z*z-1 by (z+1)*(z-1)

Attempt to have the entire compilation done with SSE (option -xK or -xW), unless you have a very old CPU.

Try the -mp and -mp1 options, and -fp_port if you can't use SSE.

It does look in this case that all possible versions should produce exact results for z**2-1, so I agree that it doesn't make sense for one of the intermediate results to fall slightly below the branch cut.
0 Kudos
Deleted_U_Intel
Employee
597 Views

It seems that -mp makes the result consistent (both CSQRT returns a negative number)
When re-written to (z+1)*(z-1) both return positive.

Hmm.

0 Kudos
Deleted_U_Intel
Employee
597 Views

It is clear that the differences has to do with the branch cut implementation.
However, the compiler is not consistent in its exact location of the branch cut.
Two examples:
1) If the call to W (line 7) is commented out by a c in column 1 the maginary part of the result from the main program changes from negative to positive.
2) If the argument of the "subroutine W" (line 13) is changed from dummy to z the maginary part of the result from the subroutine changes from positive to negative.

0 Kudos
Reply