Skip to content

Commit

Permalink
Add !$ OMP critical around file opening for VTK
Browse files Browse the repository at this point in the history
We were having problems with the `!OMP` directives around high resolution file reading in AWAE.f90. Since the file reading starts with a call to `GetNewUnit` before starting the opening, parallel calls to `GetNewUnit` could result in the same unit number handed out to two processes.  The first process would open the file and start reading, but then the second process would open a different file with the same unit number causing read errors for both processes as they attempted to read the same file at the same time.

Adding `$OMP critical` around the `GetNewUnit` and following `OpenFile...` calls so that in theory these cannot be done in parallel.

Co-authored-by: Derek Slaughter <deslaughter@gmail.com>
  • Loading branch information
andrew-platt and deslaughter committed Jul 19, 2024
1 parent 75f1e32 commit ed6bad7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/nwtc-library/src/VTK.f90
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ SUBROUTINE ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel
closeOnReturn = .FALSE.
END IF

!$OMP critical
CALL GetNewUnit( Un, ErrStat, ErrMsg )
CALL OpenFInpFile ( Un, TRIM(FileName), ErrStat, ErrMsg )
if (ErrStat >= AbortErrLev) return
!$OMP end critical

CALL ReadCom( Un, FileName, 'File header: Module Version (line 1)', ErrStat2, ErrMsg2, 0 )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
Expand Down Expand Up @@ -358,9 +360,11 @@ SUBROUTINE WrVTK_SP_header( FileName, descr, Un, ErrStat, ErrMsg )
INTEGER(IntKi) , INTENT( OUT) :: ErrStat !< error level/status of OpenFOutFile operation
CHARACTER(*) , INTENT( OUT) :: ErrMsg !< message when error occurs

!$OMP critical
CALL GetNewUnit( Un, ErrStat, ErrMsg )
CALL OpenFOutFile ( Un, TRIM(FileName), ErrStat, ErrMsg )
if (ErrStat >= AbortErrLev) return
!$OMP end critical

WRITE(Un,'(A)') '# vtk DataFile Version 3.0'
WRITE(Un,'(A)') trim(descr)
Expand Down

0 comments on commit ed6bad7

Please sign in to comment.