Introduction

Usually, in order to profile a code using the GNU tools, it is necessary to compile the given code in static mode, with the option -pg of the compiler. A program compiled this way will generate, at its first execution, a file called gmon.out.This file can be further analysed with the gprof tool.

Problem

If a program that is instrumented for profiling is run in parallel (using the MPI tools), there will be many instances of the same program running as different processes, each process generating its own gmon.out file. Of course, all copies but one will be destroyed upon program termination, because, in the typical parallel setup, the many processes share the same environment (hence use the same filesystem).

Solution

A solution to this situation is offered by the later versions of the glibc library, which introduces an environment variable named GMON_OUT_PREFIX. Setting this variable to something non-null, induces that the gmon.out file will be in fact named GMON_OUT_PREFIX.<pid>.

Thus, for the use in GIREF, I chose the following solution: add this variable to the /etc/csh.giref configuration file or to the /etc/profile.d/giref.{csh,sh} (the later on the cluster, e.g.), with the following commands:

GMON_OUT_PREFIX='gmon.out-'`/bin/uname -n`
export GMON_OUT_PREFIX

or

setenv GMON_OUT_PREFIX 'gmon.out-'`/bin/uname -n`
This was tested on SuSE Linux 8.0 (then 8.2) and it functions.