Version 8 (modified by xnwang, 5 months ago) (diff)


Profiling with Gprof


Background of this item: gprof is a type of tool called a profiler. It is available on Obelix and it has been successfully used to analyze single processor jobs. Profiling allows you to learn where your program spent its time and which functions called which other functions while it was executing. This information can show you which pieces of your program are slower than you expected and might be candidates for rewriting to make your program execute faster.

Gprof on obelix

Authors: A.S. Lansø and S. Luyssaert
Last revision: S. Luyssaert (2019/09/30)
Last revision: X. Wang (2021/05/11)

Basically one needs to add the compiler option -p -g or -pg. Use on-line manuals to learn about additional settings that can be used to fine tune the outcomes of gprof.

Because ORCHIDEE makes use of several scripts, these options need to be added at several places:

  • ORCHIDEE/config/Makefile add -p -g to the production line mode F_O
  • If you want this to become the default also after a make clean and ins_make then also change the compiler options in ORCHIDEE/util/AA_make.def add -p -g to the production line mode F_O for obelix. Then run ins_make (./ins_make)
  • ORCHIDEE/model/ORCHIDEE/arc.fcm add -p -g to the prod line

Note that around revision 6610 the way of compiling the model has changed. The instructions provided above are no longer valid for the compilation using the ./ script. The remainder of this item should still be valid.

Recompile the model from the config/ORCHIDEE_OL folder. Rerun the model. If all goes well a gmon.out file will be created in the RUN_DIR. So, on obelix you will first have to change the path of the RUN_DIR else you will not be able to access this folder. Open …/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh and change the RUN_DIR_PATH (example below)

#- RUN_DIR_PATH : Temporary working directory (=> TMP)
if [ X${PBS_JOBID} != X ] ; then
  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/home/scratch01/sluys/$PBS_O_LOGNAME.$PBS_JOBID}
  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/tmp/tmp$$}

You can now look at the gmon.out file with gprof.

gprof orchide_ol gmon.out > view.txt 

Tested in trunk rev n7164 with gprof on Irene.

  • modify the modeles/IOIPSL/src/Makefile: add -p -g to the line F_O
  • modify modeles/ORCHIDEE/arch/archservername.fcm: add -p -g to RPOD_FFLAGS
  • recompile orchidee ./
  • if use a small region and without libIGCM for simulation: ./orchidee_ol_prod > out_orchidee_ol_prod 2>&1
  • gprof -a orchidee_ol_prod gmon.out > analysis.txt