bug with pgf90 when adding bind(c) to a function

Hi,

I found a very weird bug in a code that I’m writing. I deleted most of it, and the relevant two files can be now downloaded at:
https://filenurse.com/files/ff2ec3832dc5ce996e8e15d7c5632535.tgz

The code only has two files, and the relevant function is W3JS in math.f90, which as it is, it is declared as:

 FUNCTION W3JS(J1,J2,J3,M1,M2,M3) bind(c)

I compile the code with:

[angelv@deimos pgi_bug]$ pgf90 -cpp -o rii_bug_pgi.x math.f90 rii.f90

And run it as:

[angelv@deimos pgi_bug]$ ./rii_bug_pgi.x > out.pgi

If I now do the same, but removing bind© from the W3JS declaration, then I can see that the results from both executions are different:

In the case the function W3JS doesn’t have bind©, the values W3JS returns and those seen from within the zcs funcion in file rii.f90 are the same. All good:

 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:    0.5773502691896257
 W3JS RETURNS:    0.5773502691896257
 RETURNED:   -0.5000000000000000       -0.5000000000000000
  -0.5000000000000000       -0.5000000000000000        0.5773502691896257
   0.5773502691896257

But in the version with bind© the sign of the values returned are changed (actually not in all of them, not sure if it is just random or it follows some pattern):

 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:   -0.5000000000000000
 W3JS RETURNS:    0.5773502691896257
 W3JS RETURNS:    0.5773502691896257
 RETURNED:    0.5000000000000000        0.5000000000000000
   0.5000000000000000        0.5000000000000000        0.5773502691896257
   0.5773502691896257

The same code compiled with gfortran (also both including and excluding bind©) give identical results in both cases.

Any idea what is going on?

Thanks,
AdV

Hi AdV,

Which compiler version are you using?

I was able to recreate the error with PGI 17.10 through 18.3, but 18.4 seems to get correct answers.

Can you try 18.4 to see if it fixes the problem for you as well?

-Mat

Hi Mat,

yes, this was with 18.3.

I’m going to try with 18.4 once we can do the upgrade.

Thanks,
AdV

Hi,

yes, all in order with 18.4

Thanks,
AdV