Attempting to compile the following code gives the error message below:
recursive real function det(A) result(res)
real, dimension(:,:), intent(in) :: A
! Local variables.
real :: d
n = size(A,1)
d = 0.0
if (n==2) then
res = A(1,1)*A(2,2)-A(1,2)*A(2,1)
else if (n==3) then
d = A(1,1)*(A(2,2)*A(3,3)-A(3,2)*A(2,3))
d = d-A(1,2)*(A(2,1)*A(3,3)-A(3,1)*A(2,3))
d = d+A(1,3)*(A(2,1)*A(3,2)-A(3,1)*A(2,2))
res = d
else if (n==4) then
res = A(1,1)*det(A((/2,3,4/),(/2,3,4/))) &
write(*,*) 'det for matrices bigger than 4x4 not implemented'
end function det
real, dimension(4,4) :: A
integer :: i,j
do i = 1,4
do j = 1,4
end program main
[jchodera@opt2 detbug]$ gfortran -o detbug detbug.f90
detbug.f90: In function 'det':
detbug.f90:21: internal compiler error: in gfc_conv_ss_descriptor, at fortran/trans-array.c:1265
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
[jchodera@opt2 detbug]$ gfortran --version
GNU Fortran 95 (GCC 4.0.2 20051125 (Red Hat 4.0.2-8))
Copyright (C) 2005 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
Upgrade your compiler to at least 4.1.1, and try again.
Also, you need an explicit interface for the
recursive function in your main program
recursive real function det(a) result(res)
real, dimension(:,:), intent(in) :: a
end function det
Using gfortran 4.1.2 20060705 (prerelease) (SUSE Linux)
and GNU Fortran 95 (GCC) 4.2.0 20060822 (experimental)
it compiles and gives the output (from the program):
det for matrices bigger than 4x4 not implemented
John Chodera, I would really recommend to update to 4.1.x or to 4.2-snapshots as gfortran in GCC 4.0.x is rather buggy. See http://gcc.gnu.org/wiki/GFortranBinaries for binary GCC versions.
In addition: As the NAG compiler points out:
Error: Explicit interface required for DET from MAIN - argument A (no. 1) is an assumed-shape array
The problem is that Fortran passes an array differently for A(*) or A(n) than for A(:). The latter is called assumed-shaped array and is an addition to Fortran 90 (the former also work with Fortran 77). In order to let the compiler know that you want to pass an assumed-shaped array, you need to either create a module, which contains the function "det", or you put it below "contains" in the "program" section or you write an interface in the "program" section.
The ICE is fixed on recent versions of gfortran. However, I am keeping the PR and giving it a new summary because the lack of a warning on the assumed shape array is a problem that is related to others.
Please feel free to submit your problems, as (or if!) they come up. It would help both you and us if you would update. You will find binaries of version 4.2.0 at the gfortran wiki that I know work fine with RedHat.
Again, the same theme as 26227.
*** This bug has been marked as a duplicate of 26227 ***