- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We're having a problem with inconsistent results of our Fortran program depending on whether we useloop counters as subroutine arguments.
When loop counters are used as arguments, thosearguments are not changed within the called subroutine, only read. We get different results when using the loop counter itself as the argument versus using a local var copy as the argument. Conceptually, the following illustrates the issue:
The following code:
integer i
...
do i=1,100
call myroutine(i,other_vars)
...
enddo
gives different results than
integer i,i1
...
do i=1,100
i1 = i
call myroutine(i1,other_vars)
...
enddo
We feel this shouldn't be happening and might indicate some unrecognized problem in our code. Our code is complex and I can't post it; unfortunately I was unable to reproduce the problem with a simple example. We are running Fortran compiler version 9.1.031; with compiler flags:
-g -xW -vec_report0 -save -zero -align all -CB -fpe0 -u -r8
The problemdoesn't happen with all cases of counters passed as arguments, only certain ones. Also, only happens when the code is compiled with optimization flags enabled. When using -O0and no -xW the problem doesn't happen at all. We are on RHE Linux with kernel 2.6.9-89.ELsmp on an x86_64.
Any suggestions on why this might be happening and what to look for? Thanks very much.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you might have is something in the subroutine modifying memory it isn't supposed to, overwriting the loop variable. That's one thing I have seen in the past.
I will comment that compiler version 9.1 is quite old.... What you might try doing is adding a WRITE statement to write the value of the variable to a file or the terminal each time through the loop to see if it is changing inappropriately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...
myroutine( constant i, ... )
...
Or, maybe it willallow in somefuture releases?
Anyway,the advise regardinga 'WRITE statement' in the body of myroutine function to find a problemwill definetely work.
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Perhaps you are thinking of INTENT(IN) which forbids a PURE function from returning a modified argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I recall correctly, there were some issues with version 9.n.mm where in some cases inlining would not properly use/save registers. Not olny could your loop control variable get bunged-up but other registerized variables as well. A compiler update might be in order.
Or force your call tosubroutine to compile as out-of-inline.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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