Skip to content

Commit

Permalink
Add !$OMP critical directives around some GetNewUnit/Open*File calls
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-platt committed Dec 10, 2024
1 parent 4943c19 commit 6688a58
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 90 deletions.
4 changes: 4 additions & 0 deletions modules/aerodyn/src/AeroDyn_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1080,13 +1080,15 @@ SUBROUTINE ReadBladeInputs ( ADBlFile, BladeKInputFileData, AeroProjMod, UnEc, E
ErrMsg = ""
UnIn = -1

!$OMP critical(filename)
CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)


! Open the input file for blade K.

CALL OpenFInpFile ( UnIn, ADBlFile, ErrStat2, ErrMsg2 )
!$OMP end critical(filename)
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
IF ( ErrStat >= AbortErrLev ) RETURN

Expand Down Expand Up @@ -1324,8 +1326,10 @@ SUBROUTINE AD_PrintSum( InputFileData, p, p_AD, u, y, ErrStat, ErrMsg )

! Open the summary file and give it a heading.

!$OMP critical(filename)
CALL GetNewUnit( UnSu, ErrStat, ErrMsg )
CALL OpenFOutFile ( UnSu, TRIM( p%RootName )//'.sum', ErrStat, ErrMsg )
!$OMP end critical(filename)
IF ( ErrStat >= AbortErrLev ) RETURN

! Heading:
Expand Down
15 changes: 9 additions & 6 deletions modules/aerodyn/src/UnsteadyAero.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,11 @@ subroutine UA_Init( InitInp, u, p, x, xd, OtherState, y, m, Interval, &
p%Delim =''

if (p%NumOuts > 0) then
!$OMP critical(filename)
CALL GetNewUnit( p%unOutFile, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
CALL OpenFOutFile ( p%unOutFile, trim(InitInp%OutRootName)//'.UA.out', ErrStat2, ErrMsg2 )
if (ErrStat2 < AbortErrLev) then
CALL OpenFOutFile ( p%unOutFile, trim(InitInp%OutRootName)//'.UA.out', ErrStat2, ErrMsg2 )
!$OMP end critical(filename)
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand Down Expand Up @@ -3685,10 +3686,12 @@ subroutine UA_WriteAFIParamsToFile(InitInp, AFInfo, ErrStat, ErrMsg)
ChanName(i) = 'c_Rate'; ChanUnit(i) = '(-/rad)'; i = i+1;
ChanName(i) = 'c_RateUpper'; ChanUnit(i) = '(-/rad)'; i = i+1;

!$OMP critical(filename)
CALL GetNewUnit( unOutFile, ErrStat, ErrMsg )
IF ( ErrStat /= ErrID_None ) RETURN

CALL OpenFOutFile ( unOutFile, trim(InitInp%OutRootName)//'.UA.sum', ErrStat2, ErrMsg2 )
if (ErrStat2 < AbortErrLev) then
CALL OpenFOutFile ( unOutFile, trim(InitInp%OutRootName)//'.UA.sum', ErrStat2, ErrMsg2 )
endif
!$OMP end critical(filename)
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand Down
2 changes: 2 additions & 0 deletions modules/awae/src/AWAE_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,10 @@ SUBROUTINE AWAE_PrintSum( p, u, y, ErrStat, ErrMsg )

! Open the summary file and give it a heading.

!$OMP critical(fileopen)
CALL GetNewUnit( UnSu, ErrStat, ErrMsg )
CALL OpenFOutFile ( UnSu, TRIM( p%OutFileRoot )//'.sum', ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF ( ErrStat >= AbortErrLev ) RETURN


Expand Down
6 changes: 6 additions & 0 deletions modules/beamdyn/src/BeamDyn_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,11 @@ SUBROUTINE BD_ReadPrimaryFile(InputFile,InputFileData,OutFileRoot,UnEc,ErrStat,E
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )


!$OMP critical(filename)
CALL GetNewUnit(UnIn,ErrStat2,ErrMsg2)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
CALL OpenFInpFile(UnIn,InputFile,ErrStat2,ErrMsg2)
!$OMP end critical(filename)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF (ErrStat >= AbortErrLev) then
call cleanup()
Expand Down Expand Up @@ -1048,9 +1050,11 @@ SUBROUTINE BD_ReadBladeFile(BldFile,BladeInputFileData,UnEc,ErrStat,ErrMsg)
ErrStat = ErrID_None
ErrMsg = ""

!$OMP critical(filename)
CALL GetNewUnit(UnIn,ErrStat2,ErrMsg2)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
CALL OpenFInpFile (UnIn,BldFile,ErrStat2,ErrMsg2)
!$OMP end critical(filename)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
if (ErrStat >= AbortErrLev) then
return
Expand Down Expand Up @@ -1940,8 +1944,10 @@ SUBROUTINE BD_PrintSum( p, x, OtherState, m, InitInp, ErrStat, ErrMsg )

! Open the summary file and give it a heading.

!$OMP critical(filename)
CALL GetNewUnit( UnSu, ErrStat, ErrMsg )
CALL OpenFOutFile ( UnSu, TRIM( InitInp%RootName )//'.sum.yaml', ErrStat, ErrMsg )
!$OMP end critical(filename)
IF ( ErrStat >= AbortErrLev ) RETURN

! Heading:
Expand Down
8 changes: 5 additions & 3 deletions modules/elastodyn/src/ElastoDyn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9634,10 +9634,12 @@ SUBROUTINE ED_PrintSum( p, OtherState, ErrStat, ErrMsg )

! Open the summary file and give it a heading.

!$OMP critical(filename)
CALL GetNewUnit( UnSu, ErrStat, ErrMsg )
IF ( ErrStat /= ErrID_None ) RETURN

CALL OpenFOutFile ( UnSu, TRIM( p%RootName )//'.sum', ErrStat, ErrMsg )
if (ErrStat < AbortErrLev) then
CALL OpenFOutFile ( UnSu, TRIM( p%RootName )//'.sum', ErrStat, ErrMsg )
endif
!$OMP end critical(filename)
IF ( ErrStat /= ErrID_None ) RETURN


Expand Down
39 changes: 20 additions & 19 deletions modules/elastodyn/src/ElastoDyn_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1582,12 +1582,13 @@ SUBROUTINE ReadBladeFile ( BldFile, BladeKInputFileData, UnEc, ErrStat, ErrMsg )
ErrMsg = ""

UnIn = -1
!$OMP critical(filename)
CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 )


IF (ErrStat2 < AbortErrLev) THEN
! Open the input file for blade K.

CALL OpenFInpFile ( UnIn, BldFile, ErrStat2, ErrMsg2 )
CALL OpenFInpFile ( UnIn, BldFile, ErrStat2, ErrMsg2 )
ENDIF
!$OMP end critical(filename)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
Expand Down Expand Up @@ -1888,13 +1889,13 @@ SUBROUTINE ReadBladeMeshFileAD( BladeKInputFileMesh, MeshFile, UnEc, ErrStat, Er

! Get an available unit number for the file.

!$OMP critical(filename)
CALL GetNewUnit( UnIn, ErrStat, ErrMsg )
IF ( ErrStat >= AbortErrLev ) RETURN


IF ( ErrStat < AbortErrLev ) THEN
! Open the AeroDyn input file.

CALL OpenFInpFile ( UnIn, MeshFile, ErrStat2, ErrMsg2 )
CALL OpenFInpFile ( UnIn, MeshFile, ErrStat2, ErrMsg2 )
ENDIF
!$OMP end critical(filename)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
Expand Down Expand Up @@ -2179,12 +2180,13 @@ SUBROUTINE ReadTowerFile( TwrFile, InputFileData, UnEc, ErrStat, ErrMsg )
ErrMsg = ""


!$OMP critical(filename)
CALL GetNewUnit( UnIn, ErrStat, ErrMsg )
IF ( ErrStat >= AbortErrLev ) RETURN

IF ( ErrStat < AbortErrLev ) THEN
! Open the tower input file.

CALL OpenFInpFile ( UnIn, TwrFile, ErrStat2, ErrMsg2 )
CALL OpenFInpFile ( UnIn, TwrFile, ErrStat2, ErrMsg2 )
ENDIF
!$OMP end critical(filename)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
Expand Down Expand Up @@ -2521,14 +2523,13 @@ SUBROUTINE ReadPrimaryFile( InputFile, InputFileData, BldFile, FurlFile, TwrFile


! Get an available unit number for the file.

!$OMP critical(filename)
CALL GetNewUnit( UnIn, ErrStat, ErrMsg )
IF ( ErrStat >= AbortErrLev ) RETURN


IF ( ErrStat < AbortErrLev ) THEN
! Open the Primary input file.

CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 )
CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 )
ENDIF
!$OMP end critical(filename)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
Expand Down
8 changes: 8 additions & 0 deletions modules/hydrodyn/src/HydroDyn_Output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,11 @@ SUBROUTINE HDOut_OpenSum( UnSum, SummaryName, HD_Prog, ErrStat, ErrMsg )
ErrMsg = ""


!$OMP critical(fileopen)
CALL GetNewUnit( UnSum )

CALL OpenFOutFile ( UnSum, SummaryName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN


Expand Down Expand Up @@ -1033,10 +1035,12 @@ SUBROUTINE HDOut_WriteWvKinFiles( Rootname, HD_Prog, NStepWave, NNodes, NWaveEle

DO iFile = 1,7

!$OMP critical(fileopen)
CALL GetNewUnit( UnWv )

WvName = Rootname // TRIM(extension(iFile))
CALL OpenFOutFile ( UnWv, WvName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN


Expand Down Expand Up @@ -1084,10 +1088,12 @@ SUBROUTINE HDOut_WriteWvKinFiles( Rootname, HD_Prog, NStepWave, NNodes, NWaveEle

IF ( NWaveElev > 0 ) THEN

!$OMP critical(fileopen)
CALL GetNewUnit( UnWv )

WvName = Rootname // '.Elev'
CALL OpenFOutFile ( UnWv, WvName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN


Expand Down Expand Up @@ -1463,9 +1469,11 @@ SUBROUTINE HDOut_OpenOutput( HydroDyn_ProgDesc, OutRootName, p, InitOut, ErrSta

! Open the file for output
OutFileName = TRIM(OutRootName)//'.HD.out'
!$OMP critical(fileopen)
CALL GetNewUnit( p%UnOutFile )

CALL OpenFOutFile ( p%UnOutFile, OutFileName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN


Expand Down
2 changes: 2 additions & 0 deletions modules/hydrodyn/src/Morison_Output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6610,9 +6610,11 @@ SUBROUTINE MrsnOut_OpenOutput( ProgName, OutRootName, p, InitOut, ErrStat, ErrM

! Open the file for output
OutFileName = TRIM(OutRootName)//'.MRSN.out'
!$OMP critical(fileopen)
CALL GetNewUnit( p%UnOutFile )

CALL OpenFOutFile ( p%UnOutFile, OutFileName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN


Expand Down
37 changes: 11 additions & 26 deletions modules/hydrodyn/src/WAMIT2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3649,20 +3649,13 @@ SUBROUTINE Read_DataFile3D( InitInp, Filename3D, Data3D, ErrStat, Errmsg )
!------------------------------------------------------------------------------

! Find a unit number to use
!$OMP critical(fileopen)
CALL GetNewUnit(UnitDataFile,ErrStatTmp,ErrMsgTmp)
CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat, ErrMsg, RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
IF (ALLOCATED(TmpRealArr)) DEALLOCATE(TmpRealArr,STAT=ErrStatTmp)
IF (ALLOCATED(RawData3D)) DEALLOCATE(RawData3D,STAT=ErrStatTmp)
IF (ALLOCATED(RawData3DTmp)) DEALLOCATE(RawData3DTmp,STAT=ErrStatTmp)
IF (ALLOCATED(TmpDataRow)) DEALLOCATE(TmpDataRow,STAT=ErrStatTmp)
IF (ALLOCATED(TmpWvFreq1)) DEALLOCATE(TmpWvFreq1,STAT=ErrStatTmp)
CALL CleanUp
RETURN
ENDIF

! Open the file
CALL OpenFInpFile( UnitDataFile, TRIM(Filename3D), ErrStat, ErrMsg ) ! Open file containing mean drift information
if (ErrStatTmp < AbortErrLev) then
! Open the file
CALL OpenFInpFile( UnitDataFile, TRIM(Filename3D), ErrStat, ErrMsg ) ! Open file containing mean drift information
endif
!$OMP end critical(fileopen)
CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat, ErrMsg, RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
CLOSE( UnitDataFile )
Expand Down Expand Up @@ -4423,21 +4416,13 @@ SUBROUTINE Read_DataFile4D( InitInp, Filename4D, Data4D, ErrStat, Errmsg )
!------------------------------------------------------------------------------

! Find a unit number to use
!$OMP critical(fileopen)
CALL GetNewUnit(UnitDataFile,ErrStatTmp,ErrMsgTmp)
CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat, ErrMsg, RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
IF (ALLOCATED(RawData4D)) DEALLOCATE(RawData4D,STAT=ErrStatTmp)
IF (ALLOCATED(RawData4DTmp)) DEALLOCATE(RawData4DTmp,STAT=ErrStatTmp)
IF (ALLOCATED(TmpRealArr)) DEALLOCATE(TmpRealArr,STAT=ErrStatTmp)
IF (ALLOCATED(TmpDataRow)) DEALLOCATE(TmpDataRow,STAT=ErrStatTmp)
IF (ALLOCATED(TmpWvFreq1)) DEALLOCATE(TmpWvFreq1,STAT=ErrStatTmp)
IF (ALLOCATED(TmpWvFreq2)) DEALLOCATE(TmpWvFreq2,STAT=ErrStatTmp)
CALL CleanUp
RETURN
ENDIF

if (ErrStatTmp < AbortErrLev) then
! Open the file
CALL OpenFInpFile( UnitDataFile, TRIM(Filename4D), ErrStat, ErrMsg ) ! Open file containing mean drift information
CALL OpenFInpFile( UnitDataFile, TRIM(Filename4D), ErrStat, ErrMsg ) ! Open file containing mean drift information
endif
!$OMP end critical(fileopen)
CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat, ErrMsg, RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
CLOSE( UnitDataFile )
Expand Down
34 changes: 19 additions & 15 deletions modules/inflowwind/src/InflowWind_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,13 @@ subroutine IfW_TurbSim_Init(InitInp, SumFileUnit, G3D, FileDat, ErrStat, ErrMsg)
!----------------------------------------------------------------------------

! Get a unit number to use for the wind file
!$OMP critical(fileopen)
call GetNewUnit(WindFileUnit, TmpErrStat, TmpErrMsg)
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

! Open binary file
call OpenBInpFile(WindFileUnit, TRIM(InitInp%WindFileName), TmpErrStat, TmpErrMsg)
if (TmpErrStat < AbortErrLev) then
! Open binary file
call OpenBInpFile(WindFileUnit, TRIM(InitInp%WindFileName), TmpErrStat, TmpErrMsg)
endif
!$OMP end critical(fileopen)
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand Down Expand Up @@ -883,16 +884,17 @@ subroutine IfW_HAWC_Init(InitInp, SumFileUnit, G3D, FileDat, ErrStat, ErrMsg)
TRIM(Num2LStr(G3D%GridBase + G3D%ZHWid*2))// &
' m above ground) with a characteristic wind speed of '//TRIM(Num2LStr(G3D%MeanWS))//' m/s. ')

! Get a unit number to use for the wind file
call GetNewUnit(WindFileUnit, TmpErrStat, TmpErrMsg)
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

! Loop through wind components (X, Y, Z)
do IC = 1, G3D%NComp

! Open wind file for this component
call OpenBInpFile(WindFileUnit, InitInp%WindFileName(IC), TmpErrStat, TmpErrMsg)
! Get a unit number to use for the wind file
!$OMP critical(fileopen)
call GetNewUnit(WindFileUnit, TmpErrStat, TmpErrMsg)
if (TmpErrStat < AbortErrLev) then
! Open wind file for this component
call OpenBInpFile(WindFileUnit, InitInp%WindFileName(IC), TmpErrStat, TmpErrMsg)
endif
!$OMP end critical(fileopen)
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand Down Expand Up @@ -1132,16 +1134,18 @@ subroutine IfW_Bladed_Init(InitInp, SumFileUnit, InitOut, G3D, FileDat, ErrStat,
end if

! Get a unit number to use
!$OMP critical(fileopen)
call GetNewUnit(UnitWind, TmpErrStat, TmpErrMsg)
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
if (TmpErrStat < AbortErrLev) then

!----------------------------------------------------------------------------
! Open the binary file, read its "header" (first 2-byte integer) to
! determine what format binary file it is, and close it.
!----------------------------------------------------------------------------

call OpenBInpFile(UnitWind, TRIM(BinFileName), TmpErrStat, TmpErrMsg)
call OpenBInpFile(UnitWind, TRIM(BinFileName), TmpErrStat, TmpErrMsg)
endif
!$OMP end critical(fileopen)
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand Down
2 changes: 2 additions & 0 deletions modules/inflowwind/src/InflowWind_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1575,8 +1575,10 @@ SUBROUTINE InflowWind_OpenSumFile( SumFileUnit, SummaryName, IfW_Prog, WindType,
ErrMsg = ""

SumFileUnit = -1
!$OMP critical(fileopen)
CALL GetNewUnit( SumFileUnit )
CALL OpenFOutFile ( SumFileUnit, SummaryName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN


Expand Down
Loading

0 comments on commit 6688a58

Please sign in to comment.