https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92836
--- Comment #11 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- (In reply to Andrew Benson from comment #10) > (In reply to Thomas Koenig from comment #8) > > Also, why do you use inquire at all? AFAIK, it is not an error > > to OPEN a file more than one if you don't change anything, so > > a simple > > > > open (10,file="foo.dat",status="unknown") > > > > should, in principle, work even with OpenMP; if it doesn't, this is > > another bug that needs fixing. > > I haven't tried this. Are you suggesting this as an alternative to using > INQUIRE? That is the idea. > My reasoning for using INQUIRE to check the existence of the file > is that if it doesn't exist I want one thread to proceed to create the data > for the file (and actually that thread will then spawn another set of nested > OpenMP threads to do that work). If you look at 12.5.6.1 in F2018, you will find If the file to be connected to the unit is the same as the file to which the unit is connected, a new connection is not established and values for any changeable modes (12.5.2) specified come into effect for the established connection; the current file position is unaffected. Before any effect on changeable modes, a wait operation is performed for any pending asynchronous data transfer operations for the specified unit. If the POSITION= specifier appears in such an OPEN statement, the value specified shall not disagree with the current position of the file. If the STATUS= specifier is included in such an OPEN statement, it shall be specified with the value OLD. Other than ERR=, IOSTAT=, and IOMSG=, and the changeable modes, the values of all other specifiers in such an OPEN statement shall not differ from those in effect for the established connection. ... so my example was actually not quite correct, because the STATUS was wrong. However, in order to to do what you describe, maybe an explicit variable to hold the file number (or flag) may be better, like this, with access guarded by OMP CRITICAL: integer :: file_num = -1 !$omp parallel ... !$omp critical if (file_num < 0) then open (newunit = file_num, file="foo.dat") ! Do a lot of other stuff end if !$omp end critical ! file_num contains something valid here