Skip to content

Commit

Permalink
SeaState: Add OMP critical around file open
Browse files Browse the repository at this point in the history
`!$ OMP critical` directives were added to all other modules in the 3.5.5 updates, but new modules don't include these
  • Loading branch information
andrew-platt committed Dec 21, 2024
1 parent 840be1f commit acf1739
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modules/seastate/src/SeaState_Input.f90
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ subroutine SeaSt_ParseInput( InputFileName, OutRootName, defWtrDens, defWtrDpth,
if (Failed()) return;

! WvKinFile
call ParseVar( FileInfo_In, CurLine, 'WvKinFile', InputFileData%Waves%WvKinFile, ErrStat2, ErrMsg2, UnEc )
call ParseVar( FileInfo_In, CurLine, 'WvKinFile', InputFileData%Waves%WvKinFile, ErrStat2, ErrMsg2, UnEc, IsPath=.true. )
if (Failed()) return;

!-------------------------------------------------------------------------------------------------
Expand Down
22 changes: 15 additions & 7 deletions modules/seastate/src/SeaState_Output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ SUBROUTINE SeaStOut_WriteWvKinFiles( Rootname, SeaSt_Prog, WaveField, WaveDT, X_

DO iFile = 1,7

CALL GetNewUnit( UnWv )

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

call WriteWvKinHeader( UnWv, iFile, Delim, SeaSt_Prog, waveDT, -z_gridPts(1), NGrid, deltaGrid )
Expand Down Expand Up @@ -330,11 +332,11 @@ SUBROUTINE SeaStOut_WriteWvKinFiles( Rootname, SeaSt_Prog, WaveField, WaveDT, X_
END DO

! WaveElevation Grid

CALL GetNewUnit( UnWv )

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


Expand Down Expand Up @@ -444,13 +446,15 @@ subroutine SeaStOut_WriteWaveElev0( Rootname, NStepWave, NGrid, WaveElev1, WaveE
ErrMsg = ""
Frmt = '(F12.4,ES12.4e2)'
Frmt2 = '(2(A12))'
CALL GetNewUnit( UnWv )


WvName = TRIM(Rootname) // '.Elev'
i = NGrid(1) / 2 + 1
j = NGrid(2) / 2 + 1
!$OMP critical(fileopen)
CALL GetNewUnit( UnWv )
CALL OpenFOutFile ( UnWv, WvName, ErrStat, ErrMsg )
!$OMP end critical(fileopen)
IF (ErrStat >=AbortErrLev) RETURN
! WRITE (UnWv,'(A)', IOSTAT=ErrStat) 'This wave elevation (0,0) file was generated by '//TRIM( SeaSt_Prog%Name )//&
! ' '//TRIM( SeaSt_Prog%Ver )//' on '//CurDate()//' at '//CurTime()//'.'
Expand Down Expand Up @@ -718,9 +722,11 @@ SUBROUTINE SeaStOut_OpenOutput( SeaSt_ProgDesc, OutRootName, p, InitOut, ErrSta

! Open the file for output
OutFileName = TRIM(OutRootName)//'.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 Expand Up @@ -1011,9 +1017,11 @@ SUBROUTINE SeaStOut_WrSummaryFile(InitInp, InputFileData, p, ErrStat, ErrMsg )

SummaryName = trim(InitInp%OutRootName)//'.sum'
UnSum = -1
CALL GetNewUnit( UnSum )

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

Expand Down
20 changes: 12 additions & 8 deletions modules/seastate/src/UserWaves.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ SUBROUTINE WaveElev_ReadFile ( InitInp, WaveElevData, ErrStat, ErrMsg )
ErrStat = ErrID_None
ErrMsg = ""

! Get a unit number for reading in the file
CALL GetNewUnit( WaveElevUnit )

! Assemble the filename for the wave elevation data.
WaveElevData%FileName = TRIM(InitInp%WvKinFile)//'.Elev'

! Open the file containing the wave elevation timeseries
!$OMP critical(fileopen)
CALL GetNewUnit( WaveElevUnit )
CALL OpenFInpFile( WaveElevUnit, WaveElevData%FileName, ErrStatTmp, ErrMsgTmp )
!$OMP end critical(fileopen)
CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat,ErrMsg, RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CLOSE ( WaveElevUnit )
Expand Down Expand Up @@ -492,11 +492,13 @@ SUBROUTINE UserWaves_Init ( InitInp, InitOut, WaveField, ErrStat, ErrMsg )

! Read the first file and set the initial values of the
DO iFile = 1,7
CALL GetNewUnit( UnWv )

FileName = TRIM(InitInp%WvKinFile) // TRIM(extension(iFile))

!$OMP critical(fileopen)
CALL GetNewUnit( UnWv )
CALL OpenFInpFile ( UnWv, FileName, ErrStatTmp, ErrMsgTmp )
!$OMP end critical(fileopen)
IF ( ErrStatTmp /= 0 ) THEN
ErrMsgTmp = 'Failed to open wave kinematics file, ' // TRIM(FileName)
CALL SetErrStat( ErrID_Fatal, ErrMsgTmp, ErrStat, ErrMsg, RoutineName )
Expand Down Expand Up @@ -552,11 +554,13 @@ SUBROUTINE UserWaves_Init ( InitInp, InitOut, WaveField, ErrStat, ErrMsg )
end do

! WaveElev
CALL GetNewUnit( UnWv )

FileName = TRIM(InitInp%WvKinFile) // '.Elev'

!$OMP critical(fileopen)
CALL GetNewUnit( UnWv )
CALL OpenFInpFile ( UnWv, FileName, ErrStatTmp, ErrMsgTmp )
!$OMP end critical(fileopen)
IF ( ErrStatTmp /= 0 ) THEN
ErrMsgTmp = 'Failed to open wave elevation file, ' // TRIM(FileName)
CALL SetErrStat( ErrID_Fatal, ErrMsgTmp, ErrStat, ErrMsg, RoutineName )
Expand Down Expand Up @@ -691,14 +695,14 @@ SUBROUTINE WaveComp_ReadFile ( InitInp, WaveDOmega, WaveCompData, ErrStat, ErrMs
ErrStat = ErrID_None
ErrMsg = ""

! Get a unit number for reading in the file
CALL GetNewUnit( WaveCompUnit )

! Assemble the filename for the wave component data.
WaveCompData%FileName = TRIM(InitInp%WvKinFile)

! Open the file containing the list of wave components
!$OMP critical(fileopen)
CALL GetNewUnit( WaveCompUnit )
CALL OpenFInpFile( WaveCompUnit, WaveCompData%FileName, ErrStatTmp, ErrMsgTmp )
!$OMP end critical(fileopen)
CALL SetErrStat( ErrStatTmp, ErrMsgTmp, ErrStat,ErrMsg, RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CALL CleanUpError()
Expand Down

0 comments on commit acf1739

Please sign in to comment.