Skip to content

Commit

Permalink
Add timings_tests/time_MOM_remapping
Browse files Browse the repository at this point in the history
- Added new driver, time_MOM_remapping, to config_src/timing_tests/
  that exercises the remapping_core_h() function with PCM and PLM.
- We should add other reconstruction schemes too, but the main reason for
  adding this now is to monitor the impact of refactoring the function
  remapping_core_h() which is mostly independent of the reconstruction
  schemes.
- Fixed .testing/Makefile to not fail with `make build.timing -j`
  • Loading branch information
adcroft committed Mar 25, 2024
1 parent 4386102 commit edbe556
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ $(BUILD)/timing/Makefile: MOM_ACFLAGS += --with-driver=timing_tests


# Build executables
.NOTPARALLEL:$(foreach e,$(UNIT_EXECS),$(BUILD)/unit/$(e))
$(BUILD)/unit/test_%: $(BUILD)/unit/Makefile FORCE
cd $(@D) && $(TIME) $(MAKE) $(@F) -j
$(BUILD)/unit/Makefile: $(foreach e,$(UNIT_EXECS),../config_src/drivers/unit_tests/$(e).F90)
.NOTPARALLEL:$(foreach e,$(TIMING_EXECS),$(BUILD)/timing/$(e))
$(BUILD)/timing/time_%: $(BUILD)/timing/Makefile FORCE
cd $(@D) && $(TIME) $(MAKE) $(@F) -j
$(BUILD)/timing/Makefile: $(foreach e,$(TIMING_EXECS),../config_src/drivers/timing_tests/$(e).F90)
Expand Down
93 changes: 93 additions & 0 deletions config_src/drivers/timing_tests/time_MOM_remapping.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
program time_MOM_remapping

! This file is part of MOM6. See LICENSE.md for the license.

use MOM_remapping, only : remapping_CS
use MOM_remapping, only : initialize_remapping
use MOM_remapping, only : remapping_core_h

implicit none

type(remapping_CS) :: CS
integer, parameter :: nk=75, nij=20*20, nits=10, nsamp=100, nschemes = 2
character(len=10) :: scheme_labels(nschemes)
real, dimension(nschemes) :: timings, tmean, tstd, tmin, tmax
real, dimension(:,:), allocatable :: u0, h0, u1, h1
real :: start, finish, h0sum, h1sum
integer :: ij, k, seed_size, isamp, iter, ischeme
integer, allocatable :: seed(:)

! Set seed for random numbers
call random_seed(size=seed_size)
allocate( seed(seed_Size) )
seed(:) = 102030405
call random_seed(put=seed)

scheme_labels(1) = 'PCM'
scheme_labels(2) = 'PLM'

! Set up some test data (note: using k,i indexing rather than i,k)
allocate( u0(nk,nij), h0(nk,nij), u1(nk,nij), h1(nk,nij) )
call random_number(u0) ! In range 0-1
call random_number(h0) ! In range 0-1)
call random_number(h1) ! In range 0-1)
do ij = 1, nij
h0(:,ij) = max(0., h0(:,ij) - 0.05) ! Make 5% of values equal to zero
h1(:,ij) = max(0., h1(:,ij) - 0.05) ! Make 5% of values equal to zero
h0sum = h0(1,ij)
h1sum = h1(1,ij)
do k = 2, nk
h0sum = h0sum + h0(k,ij)
h1sum = h1sum + h1(k,ij)
enddo
h0(:,ij) = h0(:,ij) / h0sum
h1(:,ij) = h1(:,ij) / h1sum
enddo

! Loop over many samples of timing loop to collect statistics
tmean(:) = 0.
tstd(:) = 0.
tmin(:) = 1.e9
tmax(:) = 0.
do isamp = 1, nsamp
! Time reconstruction + remapping
do ischeme = 1, nschemes
call initialize_remapping(CS, remapping_scheme=trim(scheme_labels(ischeme)))
call cpu_time(start)
do iter = 1, nits ! Make many passes to reduce sampling error
do ij = 1, nij ! Calling nij* to make similar cost to call in MOM_ALE()
call remapping_core_h(CS, nk, h0(:,ij), u0(:,ij), nk, h1(:,ij), u1(:,ij))
enddo
enddo
call cpu_time(finish)
timings(ischeme) = (finish-start)/real(nits*nij) ! Average time per call
enddo
tmean(:) = tmean(:) + timings(:)
tstd(:) = tstd(:) + timings(:)**2 ! tstd contains sum of squares here
tmin(:) = min( tmin(:), timings(:) )
tmax(:) = max( tmax(:), timings(:) )
enddo
tmean(:) = tmean(:) / real(nsamp) ! convert to mean
tstd(:) = tstd(:) / real(nsamp) ! convert to mean of squares
tstd(:) = tstd(:) - tmean(:)**2 ! convert to variance
tstd(:) = sqrt( tstd(:) * real(nsamp) / real(nsamp-1) ) ! convert to standard deviation


! Display results in YAML
write(*,'(a)') "{"
do ischeme = 1, nschemes
write(*,"(2x,5a)") '"MOM_remapping remapping_core_h(remapping_scheme=', &
trim(scheme_labels(ischeme)), ')": {'
write(*,"(4x,a,1pe11.4,',')") '"min": ',tmin(ischeme)
write(*,"(4x,a,1pe11.4,',')") '"mean":',tmean(ischeme)
write(*,"(4x,a,1pe11.4,',')") '"std": ',tstd(ischeme)
write(*,"(4x,a,i7,',')") '"n_samples": ',nsamp
if (ischeme.ne.nschemes) then
write(*,"(4x,a,1pe11.4,'},')") '"max": ',tmax(ischeme)
else
write(*,"(4x,a,1pe11.4,'}')") '"max": ',tmax(ischeme)
endif
enddo
write(*,'(a)') "}"

end program time_MOM_remapping

0 comments on commit edbe556

Please sign in to comment.