gfortran matmul
Author Message
gfortran matmul

Error in gfortran matmul ?

~\$ cat tmatmul.f90
program tmatmul
implicit none
integer, parameter         ::  nmax = 3
integer                    ::  n = 2
real, dimension(nmax,nmax) ::  B=0.0, C=1.0, X=0.0

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

X(1:n,1) = matmul( B(2,1:n),C(1:n,1:n) )
print *, X(:,1)
print *, "  Should be: 8.0  8.0  0.0"

end program tmatmul

~\$ ifort-8.1 -o tmatmul-intel81 tmatmul.f90
~\$ g95 -o tmatmul-g95 tmatmul.f90
~\$ gfortran -o tmatmul-gfortran tmatmul.f90
~\$
~\$ ./tmatmul-intel81
8.000000       8.000000      0.0000000E+00
Should be: 8.0  8.0  0.0
~\$
~\$ ./tmatmul-g95
8. 8. 0.
Should be: 8.0  8.0  0.0
~\$
~\$ ./tmatmul-gfortran
3.000000       3.000000       0.000000
Should be: 8.0  8.0  0.0
~\$
~\$ gfortran --version
GNU Fortran 95 (GCC) 4.2.0 20060610 (experimental)
....
~\$ uname -a
Linux debegil 2.6.15.6 #1 Fri Mar 10 20:51:55 CET 2006 i686 GNU/Linux
also observed in previous versions of gfortran and on x86_64

Regards Egil

Wed, 26 Nov 2008 17:30:44 GMT
gfortran matmul

Quote:
> Error in gfortran matmul ?

> ~\$ cat tmatmul.f90
> program tmatmul
>    implicit none
>    integer, parameter         ::  nmax = 3
>    integer                    ::  n = 2
>    real, dimension(nmax,nmax) ::  B=0.0, C=1.0, X=0.0

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

>    X(1:n,1) = matmul( B(2,1:n),C(1:n,1:n) )
>    print *, X(:,1)
>    print *, "  Should be: 8.0  8.0  0.0"

> end program tmatmul

> ~\$ ifort-8.1 -o tmatmul-intel81 tmatmul.f90
> ~\$ g95 -o tmatmul-g95 tmatmul.f90
> ~\$ gfortran -o tmatmul-gfortran tmatmul.f90
> ~\$
> ~\$ ./tmatmul-intel81
>     8.000000       8.000000      0.0000000E+00
>     Should be: 8.0  8.0  0.0
> ~\$
> ~\$ ./tmatmul-g95
>   8. 8. 0.
>     Should be: 8.0  8.0  0.0
> ~\$
> ~\$ ./tmatmul-gfortran
>     3.000000       3.000000       0.000000
>     Should be: 8.0  8.0  0.0
> ~\$
> ~\$ gfortran --version
> GNU Fortran 95 (GCC) 4.2.0 20060610 (experimental)
> ....
> ~\$ uname -a
> Linux debegil 2.6.15.6 #1 Fri Mar 10 20:51:55 CET 2006 i686
GNU/Linux
> also observed in previous versions of gfortran and on x86_64

> Regards Egil

I confirm this bug on May 31 windows version of gfortran.

Ian

--