- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I found a situation which is most likely illegal in Fortran, but the Intel compiler failed to catch that. The situation is reproduced in the following simple code. The problem is in declaring A in subroutine test.The local variable K is used in declaring A, which I think is illegal in Fortran. I was hoping that the compiler can find this error for me, but Intel Fortran (10.1.013for windows and 10.1.?for Linux) did not. The code was "compiled" without trouble. I am wondering whether this is a bug of the compiler.
Haifeng
------------------------------------------------------------------------------------------------------
I found a situation which is most likely illegal in Fortran, but the Intel compiler failed to catch that. The situation is reproduced in the following simple code. The problem is in declaring A in subroutine test.The local variable K is used in declaring A, which I think is illegal in Fortran. I was hoping that the compiler can find this error for me, but Intel Fortran (10.1.013for windows and 10.1.?for Linux) did not. The code was "compiled" without trouble. I am wondering whether this is a bug of the compiler.
Haifeng
------------------------------------------------------------------------------------------------------
[cpp]
program main use test_mod real,allocatable :: A(:,:,:) allocate(A(n1,n2,n3)) call test(A) end program main module test_mod integer :: n1=2 integer :: n2=4 integer :: n3=6 contains subroutine test(A) real,intent(out) :: A(1-K(1,1):n1+K(2,1), & 1-K(2,1):n2+K(2,2), & n3) ! - local variables integer :: K(3,2) A = -1 end subroutine test end module test_mod[/cpp]
Link Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So it appears:
$ gfortran -c test_mod.f90
test_mod.f90:7.35:
real,intent(out) :: A(1-K(1,1):n1+K(2,1), &
1
Error: Expression at (1) must be scalar
test_mod.f90:7.35:
real,intent(out) :: A(1-K(1,1):n1+K(2,1), &
1
Error: Expression at (1) must be scalar
$ gfortran -c test_mod.f90
test_mod.f90:7.35:
real,intent(out) :: A(1-K(1,1):n1+K(2,1), &
1
Error: Expression at (1) must be scalar
test_mod.f90:7.35:
real,intent(out) :: A(1-K(1,1):n1+K(2,1), &
1
Error: Expression at (1) must be scalar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is the output from PGI fortran
pgf90 -c test_mod.f90
PGF90-S-0043-Illegal attempt to redefine symbol k (test_mod.f90: 12)
0 inform, 0 warnings, 1 severes, 0 fatal for test
pgf90 -c test_mod.f90
PGF90-S-0043-Illegal attempt to redefine symbol k (test_mod.f90: 12)
0 inform, 0 warnings, 1 severes, 0 fatal for test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interesting - thanks. I'll report this to the developers. DPD200141301
I will note that Intel Fortran requires that the module appear first in the source.
I will note that Intel Fortran requires that the module appear first in the source.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are never minding the fact that
! - local variables
integer :: K(3,2)
the contents of K is(are) undefined (hold junk data) at the time of
subroutine test(A)
real,intent(out) :: A(1-K(1,1):n1+K(2,1), &
1-K(2,1):n2+K(2,2), &
n3)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim, this is an error. The request is for the compiler to complain. I don't think anyone is suggesting that this coding be accepted and do something useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would have to say the particular error message was in error, however the coding was in error as well. Was there a bug or was the compiler confused? (And issued the closest error message to the problem encountered.)
Had K been located inside the module data (above contains) then it would (should have been) correct programming. As to if the compiler emits the same error message in erroris up to someone to run a test. (Note, K not having been initialized would have been a seperate but run-time error).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ifort did not give any error at all, which it should have. I have no clue what kind of code it generated for this.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A few things to add
This is an error in a big Fortran code thatwe didn't find, and neither did the Intel compiler. Fortunately it was detected by another compiler (PGI) recently. The correct coding should be declaring A as A(n1,n2,n3) without those K.
There is no run-time error with run-time checking of array bounds and uninitialized variables.
When I step into this subroutine during debugging in Visual studio, the actual value of K used in declaring A happened to be zero. I don't know why it is zero rather than junk data. The code worked correctly for a long time. (If K were not zero in our code, I am sure the results from the codewon't be correct at all for us)
Thanks,
Haifeng
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>(If K were not zero in our code, I am sure the results from the codewon't be correct at all for us)
The values within K(3,2) are subscript biases for how you intend to index A within the subroutine. Your subroutine declared the valid index ranges for A as seen inside the subroutine (not the indexes used outside the subroutine)
A = -1
Would not have generated a subscript out of bounds error.
*** However, when values of K(3,2) are not zero then -1's may have been written over the top of other data.
As to if this would affect the results of your computations it may or may not have affected the results.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - jimdempseyatthecove
>>(If K were not zero in our code, I am sure the results from the codewon't be correct at all for us)
The values within K(3,2) are subscript biases for how you intend to index A within the subroutine. Your subroutine declared the valid index ranges for A as seen inside the subroutine (not the indexes used outside the subroutine)
A = -1
Would not have generated a subscript out of bounds error.
*** However, when values of K(3,2) are not zero then -1's may have been written over the top of other data.
As to if this would affect the results of your computations it may or may not have affected the results.
Jim Dempsey
Thanks for the reply.
It isimpossible that our code can work correctly if K/=0. The association of A(1:n1,1:n2,1:n3) fromthe calling subroutine with the dumy argument A(1-K(1,1):n1+K(2,1),1-K(1,2):n2+K(2,2),1:n3)) leads to two consequences inside the subroutine: 1. changing the lower subscripts of the array and 2. changing the shape of the array. So A(i,j,k) inside the subroutine cann'tbe the right "A(i,j,k)" in the calling subroutine givenany non-zero elements in K(1:2,1:2).
Haifeng

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page