Skip to content

Commit

Permalink
revert code that prints gauges in critical section
Browse files Browse the repository at this point in the history
This part is still WIP, see discussion at clawpack#536
  • Loading branch information
rjleveque committed May 23, 2022
1 parent a25c353 commit 4f2d1dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
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. RJL Changed back to critical block 4/22
c NOW changed, mjb 2/6/2015.
c NOTE that gauge subr called before stepgrid, so never get
c the very last gauge time at end of run.

Expand Down
26 changes: 12 additions & 14 deletions src/2d/shallow/gauges_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ subroutine set_gauges(restart, num_eqn, num_aux, fname)
trim(aux_column)
close(OUTGAUGEUNIT)

endif ! end of file header for ascii
endif ! end of ascii header file


end do
Expand Down Expand Up @@ -690,7 +690,8 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
integer, intent(in) :: gauge_num

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

Expand All @@ -707,11 +708,10 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
gauges(gauge_num)%y_last_written = gauges(gauge_num)%data(4, j)
endif

! Rewritten for v5.9.0 with the file operations 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)
! Open unit dependent on thread number
mythread = 0
!$ mythread = omp_get_thread_num()
myunit = OUTGAUGEUNIT + mythread

if (gauges(gauge_num)%file_format == 1) then

Expand All @@ -724,11 +724,11 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
gauges(gauge_num)%display_format, ")"

! Open gauge file:
open(unit=OUTGAUGEUNIT, file=gauges(gauge_num)%file_name, &
open(unit=myunit, file=gauges(gauge_num)%file_name, &
status='unknown', position='append', form='formatted')

do j = 1, gauges(gauge_num)%buffer_index - 1
write(OUTGAUGEUNIT, out_format) gauges(gauge_num)%level(j), &
write(myunit, out_format) gauges(gauge_num)%level(j), &
(gauges(gauge_num)%data(k, j), &
k=1,gauges(gauge_num)%num_out_vars + 1)
end do
Expand All @@ -737,13 +737,13 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)

! binary output

open(unit=OUTGAUGEUNIT, file=gauges(gauge_num)%file_name_bin, &
open(unit=myunit, file=gauges(gauge_num)%file_name_bin, &
status='unknown', position='append',access='stream')

do j = 1, gauges(gauge_num)%buffer_index - 1
! convert level from int to real for binary output:
rlevel = real(gauges(gauge_num)%level(j), kind=8)
write(OUTGAUGEUNIT) rlevel, &
write(myunit) rlevel, &
(gauges(gauge_num)%data(k, j), &
k=1,gauges(gauge_num)%num_out_vars + 1)
end do
Expand All @@ -754,9 +754,7 @@ subroutine print_gauges_and_reset_nextLoc(gauge_num)
end if

! close file
close(OUTGAUGEUNIT)

!$OMP END CRITICAL(printg)
close(myunit)

gauges(gauge_num)%buffer_index = 1

Expand Down

0 comments on commit 4f2d1dd

Please sign in to comment.