Error with passing arrays in matmul

Error with passing arrays in matmul

There is an error with passing arrays using the fortran90 function matmul. If the function is applied to an array smaller than the definition of the array the function matmul produces incorrect results. See:

integer, parameter :: nMax = 3
integer :: i, j, k
real :: B(nMax,nMax), C(nMax,nMax), BC(nMax,nMax)
n = 2

B(1,1) = 1.0
B(1,2) = 2.0
B(2,1) = 3.0
B(2,2) = 5.0

C(1,1) = 1.0
C(1,2) = 1.0
C(2,1) = 1.0
C(2,2) = 1.0

BC(1:n,1:n) = matmul(B(1:n,1:n),C(1:n,1:n))

write(*,*) bc(1:2,1:2)
write(*,*) "BC should be: 3.0 8.0 3.0 8.0"

end

We are using: Red Hat 7.3,i686 Itanium processor. The problem does not occur on a different processor and version of linux.

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.