incorrect exponentiation result

Dear all,

today a colleague of mine came across a very peculiar problem. In a very simple fortran program the result of 3**1 = 1, which is obviously not correct. We do not understand this problem at all.

The following program
program main
implicit none
integer n3,k3
data k3/3/

n3 = 1
write (0,) ’ test0: k3,n3,k3n3 : ',k3,n3,k3n3
n3 = 2
write (0,
) ’ test1: k3,n3,k3n3 : ',k3,n3,k3n3
n3 = 3
write (0,) ’ test2: k3,n3,k3n3 : ',k3,n3,k3n3

compiled without any flags (pgf90 test.f) gives the following output:

test0: k3,n3,k3n3 : 3 1 1
test1: k3,n3,k3
n3 : 3 2 1
test2: k3,n3,k3**n3 : 3 3 1

Compiling the same program with debugging information (-g), with the Intel compiler (ifort test.f), or using reals rather than integers for either n3 or k3 does give the correct output:

test0: k3,n3,k3n3 : 3 1 3
test1: k3,n3,k3
n3 : 3 2 9
test2: k3,n3,k3**n3 : 3 3 27

Has anyone come across this problem before? Am I missing something very obvious or is it a compiler bug?
We are using release 5.2 of the Portland compiler and the problem occurred on workstations running OpenSuse 10.2.

Thanks in advance for any help.

Bert van Ulft

Hi Bert,

Looks like this was a short lived compiler bug specific to the 5.2 release. However, I’m unable to find any previous report of this problem. The current release, 7.2, as well as releases 6.0 and 5.1 do not exhibit the behavior so I would suggest upgrading to the latest PGI compilers.

Hope this helps,

Hi Mat,

thanks for your quick reply. I will inform the proper people at our institute about the problem and let them decide whether or not the compiler should be upgraded.