Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print gauges in a critical section, using a single unit number #536

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/2d/shallow/advanc.f
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ subroutine par_advanc (mptr,mitot,mjtot,nvar,naux,dtnew)
c # now has boundary conditions filled in.

c should change the way print_gauges does io - right now is critical section
c NOW changed, mjb 2/6/2015.
c NOW changed, mjb 2/6/2015. RJL Changed back to critical block 4/22
c NOTE that gauge subr called before stepgrid, so never get
c the very last gauge time at end of run.

Expand Down
19 changes: 10 additions & 9 deletions src/2d/shallow/gauges_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,14 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
integer, intent(in) :: gauge_num

! Locals
integer :: j, k, myunit
integer :: omp_get_thread_num, mythread
integer :: j, k
character(len=32) :: out_format

! Open unit dependent on thread number
mythread = 0
!$ mythread = omp_get_thread_num()
myunit = OUTGAUGEUNIT + mythread
! Rewritten for v5.9.0 with this subroutine in a critical block
! so that the same OUTGAUGEUNIT can be used for all gauges,
! rather than unique unit number based on OMP thread number.

!$OMP CRITICAL(printg)

! ASCII output
if (gauges(gauge_num)%file_format == 1) then
Expand All @@ -692,7 +692,7 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
gauges(gauge_num)%num_out_vars + 1, &
gauges(gauge_num)%display_format, ")"

open(unit=myunit, file=gauges(gauge_num)%file_name, status='old', &
open(unit=OUTGAUGEUNIT, file=gauges(gauge_num)%file_name, status='old', &
position='append', form='formatted')

!if (gauges(gauge_num)%gtype == 2) then
Expand All @@ -709,19 +709,20 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
! reset buffer_index back to beginning of buffer since we are emptying
! the buffer here
do j = 1, gauges(gauge_num)%buffer_index - 1
write(myunit, out_format) gauges(gauge_num)%level(j), &
write(OUTGAUGEUNIT, out_format) gauges(gauge_num)%level(j), &
(gauges(gauge_num)%data(k, j), k=1, &
gauges(gauge_num)%num_out_vars + 1)
end do
gauges(gauge_num)%buffer_index = 1

! close file
close(myunit)
close(OUTGAUGEUNIT)
else
print *, "Unhandled file format ", gauges(gauge_num)%file_format
stop
end if

!$OMP END CRITICAL(printg)
end subroutine print_gauges_and_reset_nextLoc

end module gauges_module
2 changes: 1 addition & 1 deletion src/2d/shallow/restrt.f
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ subroutine restrt(nsteps,time,nvar,naux)
dimension intrtx(maxlv),intrty(maxlv),intrtt(maxlv)
type(fgrid), pointer :: fg

integer :: num_gauges_previous, i, ii
integer :: num_gauges_previous, i, ii, previous_gauge_num
c
c :::::::::::::::::::::::::::: RESTRT ::::::::::::::::::::::::::::::::
c read back in the check point files written by subr. check.
Expand Down