Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Inquire call causes recursive I/O error

cdetech
Beginner
692 Views
I have the following code:

datafilename = 'dumpfile.666'
inquire(file=datafilename, exist=exists, opened=opn, number=iunit)

which cause the following error:

forrtl: severe(40): recursive I/O operation, unit -256, file unknown

The lines work in other versions of the program, but does not work. I wonder why it says file unknown, when the whole point is to discover whether the file exists. How can there be a recursive operation if I am just inquiring?

I am using Intel Fortran 8.1. Thank you.
0 Kudos
4 Replies
Steven_L_Intel1
Employee
692 Views

Can you, 1) Reduce this to a simple but complete test case, and 2) try it with a more recent compiler? Normally, you get this error if you try to do an I/O operation on a unit while another operation is in progress on the same unit. For example, if you have a function call in an I/O list where the function does I/O on the same unit. I am hard put to come up with a way you would see this with INQUIRE and would like to see a complete test case.

If you have one, please send it to Intel Premier Support.

0 Kudos
cdetech
Beginner
692 Views

The inquire statement is a part of this section of code(fixed length but ampersands aren't showing up and the formatting is not coming out right):

datafilename = 'dumpfile.666'
inquire(file=datafilename, exist=exists, opened=opn, number=iunit)
if (.not. exists) then
call getlun(idat)
open(idat, file=datafilename, status='new',
& access='sequential', form='binary')
else if (.not. opn) then
call getlun(idat)
open(idat, file=datafilename, status='old', access='sequential',
& form='binary')
else
idat = iunit
end if
write(idat) lat_lim(1),lon_lim(1),lat_lim(2),lon_lim(2),
& icell_h,icell_w,n_cells
When I change the code to the following:
datafilename = 'dumpfile.666'
c inquire(file=datafilename, exist=exists, opened=opn, number=iunit)
c if (.not. exists) then
call getlun(idat)
open(idat, file=datafilename, status='replace',
& access='sequential', form='binary')
c else if (.not. opn) then
c call getlun(idat)
c open(idat, file=datafilename, status='old', access='sequential',
c & form='binary')
c else
c idat = iunit
c end if
write(idat) lat_lim(1),l on_lim(1),lat_lim(2),lon_lim(2),
& icell_h,icell_w,n_cells
I get an error at the following code:

if (ptr_tmp_3 .eq. 0) call allocate_tmp_3(ptr_tmp_3, n_cells)

do 20 j = 1, n_cells

n_el = n_per_cell * (j - 1) + n_group

icell_service_p27(j) = btest(icell_service(n_el), n_bit)

20

continue

The error happens at the "icell_service_p27(j)" line on the first iteration.

The error is:

forttl: severe(157): Program exception: access violation

The loop happens before the "inquire" statement is called.

The function is only called once. The inquire/write statements

to the file are unrelated to the arrays being accessed.

I am wondering why commenting out code is causing a problem in

code that is run through before the commented code would have been run.

If I leave the code as it was originally, then the array access happens with

no problem, and then the program crashes at the inquire statement.

0 Kudos
Steven_L_Intel1
Employee
692 Views

The combination of symptoms leads me to guess that you've got stack corruption perhaps from incorrect calling mechanisms for routines you're calling, such as getlun. Again, it's impossible to tell without seeing a complete buildable and runnable test case. Excerpts of code don't tell much of anything. When you have such a complete example, please send it to Intel Premier Support. But in the mean time, check your routine declarations carefully - make sure that if you're calling non-Fortran code that you have declared the routines properly.

0 Kudos
cdetech
Beginner
692 Views

I found the reason for the problem, sort of. I wasn't properly allocating memory for the array "icell_service_p27"(ptr_tmp_3). For whatever reason, the program was reacting differently depending what code I had commented out, even though the commented out portion had nothing to do with the pointer/array(and the new errorcoming before the code that I commented out). With the inquire statement, the program would load the data into unallocated memory and then crash at the inquire statement. Without the inquire statement, the program crashed trying to load the data into unallocated memory. Interesting.

Thanks for the help. It did get me moving in the right direction.

0 Kudos
Reply