Skip to content

Commit 9fd3717

Browse files
authored
Merge pull request #45 from magnusuMET/feature/timer
Component time tracking
2 parents f04325c + a45e660 commit 9fd3717

7 files changed

+441
-35
lines changed

src/common/fldout_nc.f90

+2-2
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ subroutine nc_declare_3d(iunit, dimids, varid, &
939939

940940
if (.false.) write (error_unit,*) chksz ! Silence compiler
941941

942-
write(iulog,*) "declaring ", iunit, TRIM(varnm), TRIM(units), &
942+
write(iulog,*) "declaring ", TRIM(varnm), TRIM(units), &
943943
TRIM(stdnm),TRIM(metnm)
944944
call check(nf90_def_var(iunit, TRIM(varnm), &
945945
NF90_FLOAT, dimids, varid), "def_"//varnm)
@@ -966,7 +966,7 @@ subroutine nc_declare_4d(iunit, dimids, varid, &
966966
INTEGER, INTENT(IN) :: iunit, dimids(4), chksz(4)
967967
CHARACTER(LEN=*), INTENT(IN) :: varnm, stdnm, metnm, units
968968

969-
write(iulog,*) "declaring ", iunit, TRIM(varnm), TRIM(units), &
969+
write(iulog,*) "declaring ", TRIM(varnm), TRIM(units), &
970970
TRIM(stdnm),TRIM(metnm)
971971
call check(nf90_def_var(iunit, TRIM(varnm), &
972972
NF90_FLOAT, dimids, varid), "def_"//varnm)

src/common/snap.F90

+30-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
PROGRAM bsnap
151151
USE iso_fortran_env, only: real64, output_unit, error_unit, IOSTAT_END
152152
USE DateCalc, only: epochToDate, timeGM
153-
USE snapdebug, only: iulog, idebug
153+
USE snapdebug, only: iulog, idebug, acc_timer => prefixed_accumulating_timer
154154
USE snapargosML, only: argosdepofile, argosdosefile, argoshoursrelease, &
155155
argoshourstep, argoshoursrun, iargos, margos, argosconcfile, nargos, &
156156
argostime
@@ -260,6 +260,12 @@ PROGRAM bsnap
260260
!> name of selected release position
261261
character(len=40), save :: srelnam = "*"
262262

263+
!> Time spent in various components of SNAP
264+
type(acc_timer) :: timeloop_timer
265+
type(acc_timer) :: output_timer
266+
type(acc_timer) :: input_timer
267+
type(acc_timer) :: particleloop_timer
268+
263269
#if defined(TRAJ)
264270
integer :: timeStart(6), timeCurrent(6)
265271
integer :: ilvl, k1, k2
@@ -664,9 +670,15 @@ PROGRAM bsnap
664670
" in this build"
665671
#endif
666672
end if
673+
674+
timeloop_timer = acc_timer("time_loop:")
675+
output_timer = acc_timer("output/accumulation:")
676+
input_timer = acc_timer("Reading MET input:")
677+
particleloop_timer = acc_timer("Particle loop:")
678+
667679
! start time loop
668680
time_loop: do istep = 0, nstep
669-
681+
call timeloop_timer%start()
670682
write (iulog, *) 'istep,nplume,npart: ', istep, nplume, npart
671683
flush (iulog)
672684
if (mod(istep, nsteph) == 0) then
@@ -702,6 +714,7 @@ PROGRAM bsnap
702714
nhleft = (nstep - istep + 1)/nsteph
703715
if (nhrun < 0) nhleft = -nhleft
704716
end if
717+
call input_timer%start()
705718
if (ftype == "netcdf") then
706719
call readfield_nc(istep, nhleft, itimei, ihr1, ihr2, &
707720
time_file, ierror)
@@ -715,6 +728,7 @@ PROGRAM bsnap
715728
write (iulog, *) "igtype, gparam(8): ", igtype, gparam
716729
end if
717730
if (ierror /= 0) call snap_error_exit(iulog)
731+
call input_timer%stop_and_log()
718732

719733
n = time_file(5)
720734
call vtime(time_file, ierr)
@@ -771,6 +785,7 @@ PROGRAM bsnap
771785
nxtinf = 1
772786
ifldout = 0
773787
! continue istep loop after initialization
788+
call timeloop_timer%stop()
774789
cycle time_loop
775790
end if
776791

@@ -869,6 +884,9 @@ PROGRAM bsnap
869884
do npl = 1, nplume
870885
iplume(npl)%ageInSteps = iplume(npl)%ageInSteps + 1
871886
end do
887+
!$OMP END PARALLEL DO
888+
889+
call particleloop_timer%start()
872890
! particle loop
873891
!$OMP PARALLEL DO PRIVATE(pextra) SCHEDULE(guided) !np is private by default
874892
part_do: do np = 1, npart
@@ -898,6 +916,7 @@ PROGRAM bsnap
898916
call checkDomain(pdata(np))
899917
end do part_do
900918
!$OMP END PARALLEL DO
919+
call particleloop_timer%stop_and_log()
901920

902921
!..remove inactive particles or without any mass left
903922
call rmpart(rmlimit)
@@ -1029,6 +1048,7 @@ PROGRAM bsnap
10291048
end if
10301049

10311050
!..field output if ifldout=1, always accumulation for average fields
1051+
call output_timer%start()
10321052
if (idailyout == 1) then
10331053
! daily output, append +x for each day
10341054
! istep/nsteph = hour -> /24 =day
@@ -1053,6 +1073,7 @@ PROGRAM bsnap
10531073
endif
10541074
if (ierror /= 0) call snap_error_exit(iulog)
10551075
end if
1076+
call output_timer%stop_and_log()
10561077

10571078
if (isteph == 0 .AND. iprecip < nprecip) iprecip = iprecip + 1
10581079

@@ -1110,6 +1131,7 @@ PROGRAM bsnap
11101131
enddo
11111132
endif
11121133
#endif
1134+
call timeloop_timer%stop_and_log()
11131135
end do time_loop
11141136
#if defined(TRAJ)
11151137
close (13)
@@ -1135,6 +1157,11 @@ PROGRAM bsnap
11351157
write (error_unit, '(''mhmax='',f10.2)') mhmax
11361158
write (error_unit, '(''mhmin='',f10.2)') mhmin
11371159
write (error_unit, *)
1160+
1161+
call timeloop_timer%print_accumulated()
1162+
call output_timer%print_accumulated()
1163+
call input_timer%print_accumulated()
1164+
call particleloop_timer%print_accumulated()
11381165
! b_end
11391166
write (iulog, *) ' SNAP run finished'
11401167
write (error_unit, *) ' SNAP run finished'
@@ -1192,7 +1219,7 @@ subroutine read_inputfile(snapinput_unit)
11921219
#if defined(FIMEX)
11931220
use find_parameters_fi, only: detect_gridparams_fi
11941221
#endif
1195-
1222+
11961223
!> Open file unit
11971224
integer, intent(in) :: snapinput_unit
11981225

src/common/snap.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ snapfldML.o: ../common/snapfldML.f90
4747
${F77} -c $(F77FLAGS) $(INCLUDES) $<
4848
ftest.o: ../common/ftest.f90 snapdebugML.o
4949
${F77} -c $(F77FLAGS) $(INCLUDES) $<
50-
snapdebugML.o: ../common/snapdebugML.f90
50+
snapdebugML.o: ../common/snapdebugML.F90
5151
${F77} -c $(F77FLAGS) $(INCLUDES) $<
5252
snapfilML.o: ../common/snapfilML.f90 snapdimML.o
5353
${F77} -c ${F77FLAGS} $<

0 commit comments

Comments
 (0)