Skip to content

Commit

Permalink
Merge pull request #45 from magnusuMET/feature/timer
Browse files Browse the repository at this point in the history
Component time tracking
  • Loading branch information
magnusuMET authored Jan 15, 2021
2 parents f04325c + a45e660 commit 9fd3717
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/common/fldout_nc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ subroutine nc_declare_3d(iunit, dimids, varid, &

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

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

write(iulog,*) "declaring ", iunit, TRIM(varnm), TRIM(units), &
write(iulog,*) "declaring ", TRIM(varnm), TRIM(units), &
TRIM(stdnm),TRIM(metnm)
call check(nf90_def_var(iunit, TRIM(varnm), &
NF90_FLOAT, dimids, varid), "def_"//varnm)
Expand Down
33 changes: 30 additions & 3 deletions src/common/snap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
PROGRAM bsnap
USE iso_fortran_env, only: real64, output_unit, error_unit, IOSTAT_END
USE DateCalc, only: epochToDate, timeGM
USE snapdebug, only: iulog, idebug
USE snapdebug, only: iulog, idebug, acc_timer => prefixed_accumulating_timer
USE snapargosML, only: argosdepofile, argosdosefile, argoshoursrelease, &
argoshourstep, argoshoursrun, iargos, margos, argosconcfile, nargos, &
argostime
Expand Down Expand Up @@ -260,6 +260,12 @@ PROGRAM bsnap
!> name of selected release position
character(len=40), save :: srelnam = "*"

!> Time spent in various components of SNAP
type(acc_timer) :: timeloop_timer
type(acc_timer) :: output_timer
type(acc_timer) :: input_timer
type(acc_timer) :: particleloop_timer

#if defined(TRAJ)
integer :: timeStart(6), timeCurrent(6)
integer :: ilvl, k1, k2
Expand Down Expand Up @@ -664,9 +670,15 @@ PROGRAM bsnap
" in this build"
#endif
end if

timeloop_timer = acc_timer("time_loop:")
output_timer = acc_timer("output/accumulation:")
input_timer = acc_timer("Reading MET input:")
particleloop_timer = acc_timer("Particle loop:")

! start time loop
time_loop: do istep = 0, nstep

call timeloop_timer%start()
write (iulog, *) 'istep,nplume,npart: ', istep, nplume, npart
flush (iulog)
if (mod(istep, nsteph) == 0) then
Expand Down Expand Up @@ -702,6 +714,7 @@ PROGRAM bsnap
nhleft = (nstep - istep + 1)/nsteph
if (nhrun < 0) nhleft = -nhleft
end if
call input_timer%start()
if (ftype == "netcdf") then
call readfield_nc(istep, nhleft, itimei, ihr1, ihr2, &
time_file, ierror)
Expand All @@ -715,6 +728,7 @@ PROGRAM bsnap
write (iulog, *) "igtype, gparam(8): ", igtype, gparam
end if
if (ierror /= 0) call snap_error_exit(iulog)
call input_timer%stop_and_log()

n = time_file(5)
call vtime(time_file, ierr)
Expand Down Expand Up @@ -771,6 +785,7 @@ PROGRAM bsnap
nxtinf = 1
ifldout = 0
! continue istep loop after initialization
call timeloop_timer%stop()
cycle time_loop
end if

Expand Down Expand Up @@ -869,6 +884,9 @@ PROGRAM bsnap
do npl = 1, nplume
iplume(npl)%ageInSteps = iplume(npl)%ageInSteps + 1
end do
!$OMP END PARALLEL DO

call particleloop_timer%start()
! particle loop
!$OMP PARALLEL DO PRIVATE(pextra) SCHEDULE(guided) !np is private by default
part_do: do np = 1, npart
Expand Down Expand Up @@ -898,6 +916,7 @@ PROGRAM bsnap
call checkDomain(pdata(np))
end do part_do
!$OMP END PARALLEL DO
call particleloop_timer%stop_and_log()

!..remove inactive particles or without any mass left
call rmpart(rmlimit)
Expand Down Expand Up @@ -1029,6 +1048,7 @@ PROGRAM bsnap
end if

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

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

Expand Down Expand Up @@ -1110,6 +1131,7 @@ PROGRAM bsnap
enddo
endif
#endif
call timeloop_timer%stop_and_log()
end do time_loop
#if defined(TRAJ)
close (13)
Expand All @@ -1135,6 +1157,11 @@ PROGRAM bsnap
write (error_unit, '(''mhmax='',f10.2)') mhmax
write (error_unit, '(''mhmin='',f10.2)') mhmin
write (error_unit, *)

call timeloop_timer%print_accumulated()
call output_timer%print_accumulated()
call input_timer%print_accumulated()
call particleloop_timer%print_accumulated()
! b_end
write (iulog, *) ' SNAP run finished'
write (error_unit, *) ' SNAP run finished'
Expand Down Expand Up @@ -1192,7 +1219,7 @@ subroutine read_inputfile(snapinput_unit)
#if defined(FIMEX)
use find_parameters_fi, only: detect_gridparams_fi
#endif

!> Open file unit
integer, intent(in) :: snapinput_unit

Expand Down
2 changes: 1 addition & 1 deletion src/common/snap.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ snapfldML.o: ../common/snapfldML.f90
${F77} -c $(F77FLAGS) $(INCLUDES) $<
ftest.o: ../common/ftest.f90 snapdebugML.o
${F77} -c $(F77FLAGS) $(INCLUDES) $<
snapdebugML.o: ../common/snapdebugML.f90
snapdebugML.o: ../common/snapdebugML.F90
${F77} -c $(F77FLAGS) $(INCLUDES) $<
snapfilML.o: ../common/snapfilML.f90 snapdimML.o
${F77} -c ${F77FLAGS} $<
Expand Down
Loading

0 comments on commit 9fd3717

Please sign in to comment.