3434# Build configuration:
3535# FCFLAGS_DEBUG Testing ("debug") compiler flags
3636# FCFLAGS_REPRO Production ("repro") compiler flags
37+ # FCFLAGS_OPT Aggressive optimization compiler flags
3738# FCFLAGS_INIT Variable initialization flags
3839# FCFLAGS_COVERAGE Code coverage flags
3940#
@@ -72,6 +73,7 @@ export MPIFC
7273# NOTE: FMS will be built using FCFLAGS_DEBUG
7374FCFLAGS_DEBUG ?= -g -O0
7475FCFLAGS_REPRO ?= -g -O2
76+ FCFLAGS_OPT ?= -g -O3 -mavx -fno-omit-frame-pointer
7577FCFLAGS_INIT ?=
7678FCFLAGS_COVERAGE ?=
7779# Additional notes:
@@ -96,6 +98,7 @@ DO_REPRO_TESTS ?=
9698# Time measurement (configurable by the CI)
9799TIME ?= time
98100
101+
99102# ---
100103# Dependencies
101104DEPS = deps
@@ -122,6 +125,11 @@ ifeq ($(DO_REPRO_TESTS), true)
122125 TESTS += repros
123126endif
124127
128+ # Profiling
129+ ifeq ($(DO_PROFILE ) , false)
130+ BUILDS += opt opt_target
131+ endif
132+
125133# The following variables are configured by Travis:
126134# DO_REGRESSION_TESTS: true if $(TRAVIS_PULL_REQUEST) is a PR number
127135# MOM_TARGET_SLUG: TRAVIS_REPO_SLUG
@@ -195,6 +203,7 @@ endif
195203.PHONY : all build.regressions
196204all : $(foreach b,$(BUILDS ) ,build/$(b ) /MOM6) $(VENV_PATH )
197205build.regressions : $(foreach b,symmetric target,build/$(b ) /MOM6)
206+ build.prof : $(foreach b,opt opt_target,build/$(b ) /MOM6)
198207
199208# Executable
200209BUILD_TARGETS = MOM6 Makefile path_names
@@ -217,6 +226,7 @@ PATH_FMS = PATH="${PATH}:../../$(DEPS)/bin"
217226SYMMETRIC_FCFLAGS := FCFLAGS="$(FCFLAGS_DEBUG ) $(FCFLAGS_INIT ) $(COVERAGE ) $(FCFLAGS_FMS ) "
218227ASYMMETRIC_FCFLAGS := FCFLAGS="$(FCFLAGS_DEBUG ) $(FCFLAGS_INIT ) $(FCFLAGS_FMS ) "
219228REPRO_FCFLAGS := FCFLAGS="$(FCFLAGS_REPRO ) $(FCFLAGS_FMS ) "
229+ OPT_FCFLAGS := FCFLAGS="$(FCFLAGS_OPT ) $(FCFLAGS_FMS ) "
220230OPENMP_FCFLAGS := FCFLAGS="$(FCFLAGS_DEBUG ) $(FCFLAGS_INIT ) $(FCFLAGS_FMS ) "
221231TARGET_FCFLAGS := FCFLAGS="$(FCFLAGS_DEBUG ) $(FCFLAGS_INIT ) $(FCFLAGS_FMS ) "
222232
@@ -230,6 +240,8 @@ build/asymmetric/Makefile: MOM_ENV=$(PATH_FMS) $(ASYMMETRIC_FCFLAGS) $(MOM_LDFLA
230240build/repro/Makefile : MOM_ENV=$(PATH_FMS ) $(REPRO_FCFLAGS ) $(MOM_LDFLAGS )
231241build/openmp/Makefile : MOM_ENV=$(PATH_FMS ) $(OPENMP_FCFLAGS ) $(MOM_LDFLAGS )
232242build/target/Makefile : MOM_ENV=$(PATH_FMS ) $(TARGET_FCFLAGS ) $(MOM_LDFLAGS )
243+ build/opt/Makefile : MOM_ENV=$(PATH_FMS ) $(OPT_FCFLAGS ) $(MOM_LDFLAGS )
244+ build/opt_target/Makefile : MOM_ENV=$(PATH_FMS ) $(OPT_FCFLAGS ) $(MOM_LDFLAGS )
233245build/coupled/Makefile : MOM_ENV=$(PATH_FMS ) $(SYMMETRIC_FCFLAGS ) $(SYMMETRIC_LDFLAGS )
234246build/nuopc/Makefile : MOM_ENV=$(PATH_FMS ) $(SYMMETRIC_FCFLAGS ) $(SYMMETRIC_LDFLAGS )
235247build/mct/Makefile : MOM_ENV=$(PATH_FMS ) $(SYMMETRIC_FCFLAGS ) $(SYMMETRIC_LDFLAGS )
@@ -240,12 +252,15 @@ build/asymmetric/Makefile: MOM_ACFLAGS=--enable-asymmetric
240252build/repro/Makefile : MOM_ACFLAGS=
241253build/openmp/Makefile : MOM_ACFLAGS=--enable-openmp
242254build/target/Makefile : MOM_ACFLAGS=
255+ build/opt/Makefile : MOM_ACFLAGS=
256+ build/opt_target/Makefile : MOM_ACFLAGS=
243257build/coupled/Makefile : MOM_ACFLAGS=--with-driver=coupled_driver
244258build/nuopc/Makefile : MOM_ACFLAGS=--with-driver=nuopc_driver
245259build/mct/Makefile : MOM_ACFLAGS=--with-driver=mct_driver
246260
247261# Fetch regression target source code
248262build/target/Makefile : | $(TARGET_CODEBASE )
263+ build/opt_target/Makefile : | $(TARGET_CODEBASE )
249264
250265
251266# Define source code dependencies
@@ -276,7 +291,8 @@ build/%/Makefile: ../ac/configure ../ac/Makefile.in $(DEPS)/lib/libFMS.a $(MKMF)
276291
277292
278293# Fetch the regression target codebase
279- build/target/Makefile : $(TARGET_CODEBASE ) /ac/configure $(DEPS ) /lib/libFMS.a $(MKMF ) $(LIST_PATHS )
294+ build/target/Makefile build/opt_target/Makefile : \
295+ $(TARGET_CODEBASE ) /ac/configure $(DEPS ) /lib/libFMS.a $(MKMF ) $(LIST_PATHS )
280296 mkdir -p $(@D )
281297 cd $(@D ) \
282298 && $(MOM_ENV ) ../../$(TARGET_CODEBASE ) /ac/configure $(MOM_ACFLAGS ) \
@@ -621,6 +637,64 @@ test.summary:
621637 fi
622638
623639
640+ # ---
641+ # Profiling
642+ # XXX: This is experimental work to track, log, and report changes in runtime
643+ PCONFIGS = p0
644+
645+ .PHONY : profile
646+ profile : $(foreach p,$(PCONFIGS ) , prof.$(p ) )
647+
648+ .PHONY : prof.p0
649+ prof.p0 : work/p0/opt/clocks.json work/p0/opt_target/clocks.json
650+ python tools/compare_clocks.py $^
651+
652+ work/p0/% /clocks.json : work/p0/% /std.out
653+ python tools/parse_fms_clocks.py -d $(@D ) $^ > $@
654+
655+ work/p0/opt/std.out : build/opt/MOM6
656+ work/p0/opt_target/std.out : build/opt_target/MOM6
657+
658+ work/p0/% /std.out :
659+ mkdir -p $(@D )
660+ cp -RL p0/* $(@D )
661+ mkdir -p $(@D ) /RESTART
662+ echo -e " " > $(@D ) /MOM_override
663+ cd $(@D ) \
664+ && $(MPIRUN ) -n 1 ../../../$< 2> std.err > std.out
665+
666+ # ---
667+ # Same but with perf
668+
669+ # TODO: This expects the -e flag, can I handle it in the command?
670+ PERF_EVENTS ?=
671+
672+ .PHONY : perf
673+ perf : $(foreach p,$(PCONFIGS ) , perf.$(p ) )
674+
675+ .PHONY : prof.p0
676+ perf.p0 : work/p0/opt/profile.json work/p0/opt_target/profile.json
677+ python tools/compare_perf.py $^
678+
679+ work/p0/% /profile.json : work/p0/% /perf.data
680+ python tools/parse_perf.py -f $< > $@
681+
682+ work/p0/opt/perf.data : build/opt/MOM6
683+ work/p0/opt_target/perf.data : build/opt_target/MOM6
684+
685+ work/p0/% /perf.data :
686+ mkdir -p $(@D )
687+ cp -RL p0/* $(@D )
688+ mkdir -p $(@D ) /RESTART
689+ echo -e " " > $(@D ) /MOM_override
690+ cd $(@D ) \
691+ && perf record \
692+ -F 3999 \
693+ ${PERF_EVENTS} \
694+ ../../../$< 2> std.perf.err > std.perf.out \
695+ || cat std.perf.err
696+
697+
624698# ----
625699# NOTE: These tests assert that we are in the .testing directory.
626700
0 commit comments