- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a piece of Fortran 90 code which uses a recursive function for testing purpose.
I use both ifort (v 11.1) and gfortran (v 4.3.2) on an AMD64 Debian/Linux 5.0 machine.
The source code is shown below, and it's quite simple --- an integer "n" is gradually reduced until "n==1". Moreover, the intermediate results are also printed onto the standard output. However, The binary obtained by ifort would produce nothing, but an recursive I/O error.
Source code:
[fortran]program ex implicit none integer::n=4 integer,external::reduce write(*,*) n, reduce(n) stop end program ex recursive function reduce(n) result(ans) implicit none integer::n,ans if (n==1) then ans=1 write(*,*) "n=", n return endif ans=reduce(n-1) write(*,*) "n=", n return end function reduce[/fortran]
Execution of binary compiled by gfortran produces:
[bash] 4 n= 1 n= 2 n= 3 n= 4 1 [/bash]
Execution of binary compiled by ifort produces:
[bash]forrtl: severe (40): recursive I/O operation, unit -1, file unknown Image PC Routine Line Source a.out 000000000047303D Unknown Unknown Unknown a.out 0000000000471B45 Unknown Unknown Unknown a.out 0000000000448C19 Unknown Unknown Unknown a.out 00000000004359BF Unknown Unknown Unknown a.out 00000000004124D3 Unknown Unknown Unknown a.out 0000000000402D15 Unknown Unknown Unknown a.out 0000000000402C68 Unknown Unknown Unknown a.out 0000000000402C68 Unknown Unknown Unknown a.out 0000000000402B7A Unknown Unknown Unknown a.out 0000000000402ADC Unknown Unknown Unknown libc.so.6 00007FD7289AD1A6 Unknown Unknown Unknown a.out 00000000004029D9 Unknown Unknown Unknown[/bash]
The problem could be remedied by replacing "write(*,*)" with "write(6,*)" ineither themain program or the recursive function reduce.
I personally think this might be a bug in ifort. Any comments are welcome.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not a bug in ifort. The Fortran standard prohibits starting an I/O operation on a unit while another operation on that same unit is in progress. gfortran evidently has an extension which allows you to do this, Intel Fortran does not.
What I would recommend is replacing the use of reduce(n) in the main program with an assignment to a variable and then print the variable.
What I would recommend is replacing the use of reduce(n) in the main program with an assignment to a variable and then print the variable.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not a bug in ifort. The Fortran standard prohibits starting an I/O operation on a unit while another operation on that same unit is in progress. gfortran evidently has an extension which allows you to do this, Intel Fortran does not.
What I would recommend is replacing the use of reduce(n) in the main program with an assignment to a variable and then print the variable.
What I would recommend is replacing the use of reduce(n) in the main program with an assignment to a variable and then print the variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Steve! Your solution works!
![](/skins/images/3CECF0550DB8BF54496C114A1FF06FE9/responsive_peak/images/icon_anonymous_message.png)
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