Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28701 Discussions

Ifort 2021.7 reusing file units despite newunit specifier

bwe
Novice
748 Views

Hi all,

I have a large program that’s been converted to using the newunit specifier for most file I/O applications. The program runs fine compiled with ifort 16, ifort 19, and gfortran 12. It crashes while running when compiled with ifort 2021.7, however. It seems to be reusing units, with 2 files pointing to -129 and 2 pointing to unit -131.

Has anyone else encountered this? Is this a known compiler bug, or am I doing something wrong?

0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
740 Views

If your program is multi-threaded, try encapsulating the OPEN (and potential ERR/EOF code) within a (named) critical section.

 

Jim Dempsey 

0 Kudos
bwe
Novice
736 Views

It has a multi-threaded version, but the one I'm testing is fully single-threaded. The multi-threaded versions work fine with the other compilers, though.

 

Another data point: 2021.4 also has collisions with newunit. I saw in this thread that changes were made to newunit around this time. https://community.intel.com/t5/Intel-Fortran-Compiler/Running-out-of-valid-logical-units-from-newunit/m-p/1336989

0 Kudos
jimdempseyatthecove
Honored Contributor III
709 Views

It seems like this bug has returned. While you await a fix...

 

I suggest you write your own work around to obtain a unit number. Say, a function that obtains a unit number together with one the relieves the unit number

 

aUnitNumber = MyNewUnit() ! Obtain an arbitrary unit number (or 0 if none available)

aUnitNumber = MyNewUnit(desiredUnitNumber) ! Obtain an specific unit number (or 0 if not available)

err = MyReturnNewUnit(closedUnitNumber) ! return unit number to pool/table or error if not formerly taken

 

Note, make the code thread-safe.

 

Jim Dempsey

0 Kudos
Barbara_P_Intel
Employee
699 Views

Do you have a small reproducer?  Please attach it and I'll get this reported.

 

0 Kudos
bwe
Novice
666 Views

I don't have a small reproducer because I've been so confused as to what exactly is happening to try to narrowly reproduce the behavior.

 

For now, I seem to be able to get around the problem by replacing a section of code, which was essentially

close (unit1)
close (unit2)
open(newunit =unit1,...)
open(newunit = unit2,...)

 

And instead `inquire`ing if the files are open already (for subsequent passes), and if so, `rewind`ing them instead of closing and reopening and calling newunit again.

0 Kudos
Reply