| ... | @@ -3,32 +3,20 @@ title: Profilage de code (C/C++/Fortran) |
... | @@ -3,32 +3,20 @@ title: Profilage de code (C/C++/Fortran) |
|
|
---
|
|
---
|
|
|
# Code profilers
|
|
# Code profilers
|
|
|
|
|
|
|
|
In this Wiki, we will provide a methodology to install and run some code profilers. This has been tested on a specific Conda environment.
|
|
In this Wiki, we will provide a methodology to install and run the Score-P profiler. This has been tested on a specific Conda environment in order to make sure that it can be applied both locally and on remote servers.
|
|
|
|
|
|
|
|
The tools that were tested are proposed:
|
|
|
|
|
|
|
|
|
|
- [Score-P](https://www.vi-hps.org/projects/score-p/)
|
|
|
|
|
- [TAU](https://www.cs.uoregon.edu/research/tau/home.php), which allows the profiling of `for` loops
|
|
|
|
|
- [Scalasca](https://www.scalasca.org/)
|
|
|
|
|
|
|
|
|
|
In order to be able to perform source instrumentation using Tau, the [PDT](https://www.cs.uoregon.edu/research/pdt/home.php) and [Salt](https://github.com/ParaToolsInc/salt) source instrumentation tool must be installed.
|
|
|
|
|
|
|
|
|
|
## Preparing the install
|
|
## Preparing the install
|
|
|
|
|
|
|
|
### Download:
|
|
### Download:
|
|
|
|
|
|
|
|
- Salt: `git clone --recursive https://github.com/ParaToolsInc/salt.git`
|
|
- Score-P: https://perftools.pages.jsc.fz-juelich.de/cicd/scorep/tags/scorep-9.2/scorep-9.2.tar.gz
|
|
|
- PDT: http://tau.uoregon.edu/pdt.tgz
|
|
|
|
|
- Score-P: https://perftools.pages.jsc.fz-juelich.de/cicd/scorep/tags/scorep-8.4/scorep-8.4.tar.gz
|
|
|
|
|
- Tau: `gh repo clone barriern/tau2`
|
|
|
|
|
- Scalasca: https://apps.fz-juelich.de/scalasca/releases/scalasca/2.6/dist/scalasca-2.6.1.tar.gz
|
|
|
|
|
|
|
|
|
|
### Conda Environment
|
|
### Conda Environment
|
|
|
|
|
|
|
|
Create the Conda environment as follows:
|
|
Create the Conda environment as follows:
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
mamba create --name profilers python=3.10 sphinx mpich-mpifort mpich-mpicc mpich-mpicxx netcdf4 six c-compiler compilers cxx-compiler clangdev llvmdev cmake
|
|
mamba create -y --name profilers python=3.10 sphinx openmpi-mpifort openmpi-mpicc openmpi-mpicxx netcdf4 six clangdev llvmdev cmake
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Alternatively, the environment can also be download [here](uploads/c01b03d6b7cae396aa5d21bb2490f97e/profilers.yml)
|
|
Alternatively, the environment can also be download [here](uploads/c01b03d6b7cae396aa5d21bb2490f97e/profilers.yml)
|
| ... | @@ -39,15 +27,6 @@ Activate the environment: |
... | @@ -39,15 +27,6 @@ Activate the environment: |
|
|
conda activate profilers
|
|
conda activate profilers
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Go to the `$CONDA_PREFIX/lib` folder and type:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
mkdir save
|
|
|
|
|
mv libbfd.a libsframe.a save
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**This trick allows to avoid the use of the Conda `BFD` library and will force the use of the Score-P and Tau BFD downloaded libraries**
|
|
|
|
|
|
|
|
|
|
## Install
|
|
## Install
|
|
|
|
|
|
|
|
### Install Score-P
|
|
### Install Score-P
|
| ... | @@ -62,12 +41,6 @@ export PROFILER_PATH_SCOREP=/home/BARRIER/Softwares/profilers/install-scorep |
... | @@ -62,12 +41,6 @@ export PROFILER_PATH_SCOREP=/home/BARRIER/Softwares/profilers/install-scorep |
|
|
```
|
|
```
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
# Change the compiler in MPICH wrappers:
|
|
|
|
|
export MPICH_CXX=g++
|
|
|
|
|
export MPICH_CC=gcc
|
|
|
|
|
export MPICH_FC=gfortran
|
|
|
|
|
export MPICH_F77=gfortran
|
|
|
|
|
|
|
|
|
|
# Define compiler variables
|
|
# Define compiler variables
|
|
|
export CC=gcc
|
|
export CC=gcc
|
|
|
export FC=gfortran
|
|
export FC=gfortran
|
| ... | @@ -77,99 +50,22 @@ export MPICC=mpicc |
... | @@ -77,99 +50,22 @@ export MPICC=mpicc |
|
|
export MPICXX=mpic++
|
|
export MPICXX=mpic++
|
|
|
export MPIFORT=mpifort
|
|
export MPIFORT=mpifort
|
|
|
export FCFLAGS="-ffree-form"
|
|
export FCFLAGS="-ffree-form"
|
|
|
```
|
|
|
|
|
|
|
|
|
|
When the variables are defined, go the Score-P folder, activate the `profilers` environment and type:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./configure --prefix=$PROFILER_PATH_SCOREP --without-shmem --with-libbfd=download --with-libunwind=download
|
|
|
|
|
make
|
|
|
|
|
make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Install PDT/Salt/Tau
|
|
|
|
|
|
|
|
|
|
To allow for source instrumentation using Tau, we need to use the clang compilers. Therefore, we will need do define some variables:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# Install folder for Tau
|
|
|
|
|
export PROFILER_PATH_TAU=/home/BARRIER/Softwares/profilers/install-tau
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# Change the compiler in MPICH wrappers:
|
|
|
|
|
export MPICH_CXX=clang++
|
|
|
|
|
export MPICH_CC=clang
|
|
|
|
|
export MPICH_FC=gfortran
|
|
|
|
|
export MPICH_F77=gfortran
|
|
|
|
|
|
|
|
|
|
# Define compiler variables
|
|
# Define compiler variables
|
|
|
export CC=clang
|
|
export CC=gcc
|
|
|
export FC=gfortran
|
|
export FC=gfortran
|
|
|
export F77=gfortran
|
|
export F77=gfortran
|
|
|
export CXX=clang++
|
|
export CXX=g++
|
|
|
export MPICC=mpicc
|
|
export MPICC=mpicc
|
|
|
export MPICXX=mpic++
|
|
export MPICXX=mpic++
|
|
|
export MPIFORT=mpifort
|
|
export MPIFORT=mpifort
|
|
|
export FCFLAGS="-ffree-form"
|
|
export FCFLAGS="-ffree-form"
|
|
|
|
|
|
|
|
# Define library path and path
|
|
|
|
|
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$PROFILER_PATH_TAU/lib
|
|
|
|
|
export PATH=$PROFILER_PATH_TAU/bin:$PATH
|
|
|
|
|
export PATH=$PROFILER_PATH_TAU/x86_64/bin/:$PATH
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Install PDT
|
|
|
|
|
|
|
|
|
|
In order to install the PDT source instrumentation tool, go to the PDT folder and type the following:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./configure -prefix=$PROFILER_PATH_TAU/ -clang
|
|
|
|
|
make
|
|
|
|
|
make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Install Salt
|
|
|
|
|
|
|
|
|
|
In order to install the Salt source instrumentation tool, go to the Salt folder and type the following:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# configure SALT and generate build system
|
|
|
|
|
cmake -Wdev -Wdeprecated -S . -B $PROFILER_PATH_TAU -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
|
|
|
|
|
cmake --build $PROFILER_PATH_TAU --parallel # Add --verbose to debug something going wrong
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Install Tau
|
|
|
|
|
|
|
|
|
|
When the variables are defined, go to the Tau folder and type:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./configure -prefix=$PROFILER_PATH_TAU/ -c++=clang++ -cc=clang -fortran=gfortran -bfd=download -unwind=download -zlib=download
|
|
|
|
|
make install
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
To compile a MPI code, add a `-mpi` flag:
|
|
When the variables are defined, go the Score-P folder, activate the `profilers` environment and type:
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./configure -prefix=$PROFILER_PATH_TAU/ -c++=clang++ -cc=clang -fortran=gfortran -bfd=download -unwind=download -zlib=download -mpi
|
|
|
|
|
make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
To compile a MPI code with PDT instrumentation, add a `-mpi` and `-pdt` flag as follows: flag:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./configure -prefix=$PROFILER_PATH_TAU/ -c++=clang++ -cc=clang -fortran=gfortran -bfd=download -unwind=download -zlib=download -mpi -pdt=$PROFILER_PATH_TAU
|
|
|
|
|
make install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> **CAUTION** In TAU, each set of compile options generate a specific Makefile that will be used for the profiling. In the above, the generated Makefile will include PDT, Score-P and MPI. To compile a non-MPI program, re-compile TAU without the `-mpi` option
|
|
|
|
|
|
|
|
|
|
### Install Scalasca
|
|
|
|
|
|
|
|
|
|
Go to your Scalasca folder and type:
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
./configure --prefix=$PROFILER_PATH
|
|
./configure --prefix=$PROFILER_PATH_SCOREP --without-shmem --with-libgotcha=download --with-libbfd=download --with-libunwind=download
|
|
|
make
|
|
make
|
|
|
make install
|
|
make install
|
|
|
```
|
|
```
|
| ... | @@ -178,9 +74,7 @@ make install |
... | @@ -178,9 +74,7 @@ make install |
|
|
|
|
|
|
|
Once everything is installed, you will be able to compile your code using the profiler tools.
|
|
Once everything is installed, you will be able to compile your code using the profiler tools.
|
|
|
|
|
|
|
|
### Profile with Score-P
|
|
### Compiler instrumentation
|
|
|
|
|
|
|
|
#### Compiler instrumentation
|
|
|
|
|
|
|
|
|
|
To profile a code with Score-P, you first need to define some environment variables:
|
|
To profile a code with Score-P, you first need to define some environment variables:
|
|
|
|
|
|
| ... | @@ -252,7 +146,7 @@ paraprof scorep-20250310_1624_81500554863145/profile.cubex & |
... | @@ -252,7 +146,7 @@ paraprof scorep-20250310_1624_81500554863145/profile.cubex & |
|
|
|
|
|
|
|
> **Note**: `.cubex` files can also be analysed using the Cube software, available as an App Image [here](https://apps.fz-juelich.de/scalasca/releases/cube/4.8/dist/CubeGUI-4.8.2.AppImage): `CubeGUI-4.8.2.AppImage scorep-20250310_1624_81500554863145/profile.cubex &`
|
|
> **Note**: `.cubex` files can also be analysed using the Cube software, available as an App Image [here](https://apps.fz-juelich.de/scalasca/releases/cube/4.8/dist/CubeGUI-4.8.2.AppImage): `CubeGUI-4.8.2.AppImage scorep-20250310_1624_81500554863145/profile.cubex &`
|
|
|
|
|
|
|
|
#### Manual instrumentation
|
|
### Manual instrumentation
|
|
|
|
|
|
|
|
You can add manual instrumentation within a code. For instance:
|
|
You can add manual instrumentation within a code. For instance:
|
|
|
|
|
|
| ... | @@ -300,166 +194,6 @@ export SCOREP_WRAPPER_INSTRUMENTER_FLAGS="--instrument-filter=scorep.filt --user |
... | @@ -300,166 +194,6 @@ export SCOREP_WRAPPER_INSTRUMENTER_FLAGS="--instrument-filter=scorep.filt --user |
|
|
scorep-g++ -DSCOREP -I$BOOST_ROOT test_cpp.cpp
|
|
scorep-g++ -DSCOREP -I$BOOST_ROOT test_cpp.cpp
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
### Profile with TAU
|
|
|
|
|
|
|
|
|
|
To profile with TAU, you first need to manually define the `LD_LIBRARY_PATH`:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
export MPICH_CXX=clang++
|
|
|
|
|
export MPICH_CC=clang
|
|
|
|
|
export MPICH_FC=gfortran
|
|
|
|
|
export MPICH_F77=gfortran
|
|
|
|
|
|
|
|
|
|
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$PROFILER_PATH_TAU/x86_64/zlib-1.3.1/lib:$PROFILER_PATH_TAU/x86_64/binutils-2.40/lib:PROFILER_PATH_TAU/x86_64/libunwind-1.6.2-clang/lib:$PROFILER_PATH_TAU/lib
|
|
|
|
|
export PATH=$PROFILER_PATH_TAU/bin:$PATH
|
|
|
|
|
export PATH=$PROFILER_PATH_TAU/x86_64/bin/:$PATH
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Compiler instrumentation
|
|
|
|
|
|
|
|
|
|
To profile with compiler instrumentation, you first need to define the `Makefile` that you will use and which has been generated by the compilation of TAU. For example:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
export TAU_MAKEFILE=$PROFILER_PATH/x86_64/lib/Makefile.tau-clang-mpi
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
You also need to define a set of options to insure that compiler instrumentation will be used:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
export TAU_OPTIONS='-optKeepFiles -optVerbose -optCompInst'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Now, to compile the program, replace the standard compile commands as follows:
|
|
|
|
|
|
|
|
|
|
- `gcc` and `mpicc`-\> `tau_cc.sh`
|
|
|
|
|
- `g++` and `mpic++`-\> `tau_cxx.sh`
|
|
|
|
|
- `gfortran` and `mpifort`-\> `tau_f90.sh`
|
|
|
|
|
- `f77` and `mpif77`-\> `tau_f70.sh`
|
|
|
|
|
|
|
|
|
|
#### Profiling with source instrumentation
|
|
|
|
|
|
|
|
|
|
To profile using source instrumentation with Tau, you need to specify the `Makefile` that you will use and which has been generated by the compilation of TAU. For example:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
export TAU_MAKEFILE=$PROFILER_PATH/x86_64/lib/Makefile.tau-clang-mpi
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### Using Salt parser
|
|
|
|
|
|
|
|
|
|
To compile a code by using the Salt parser, you also need to provide the following environment variable:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
export TAU_OPTIONS='-optKeepFiles -optVerbose -optTauSelectFile="select.tau" -optSaltParser="saltfm" -optSaltInst'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
In the above, the `-optKeepFiles` allows to keep intermediate files. The `-optTauSelectFile` specifies the file where additional profiling options are provided. These options are provided in a `select.tau` file (see below). **Note that Salt does not allow loop profiling.**
|
|
|
|
|
|
|
|
|
|
##### Using PDT parser
|
|
|
|
|
|
|
|
|
|
To compile a code by using the PDT parser, you simply need to specify a Tau makefile that includes `pdt` and remove the `-optSaltParser` and `-optSaltInst` from the TAU_OPTIONS. For instance:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
export TAU_MAKEFILE=$PROFILER_PATH/x86_64/lib/Makefile.tau-clang-pdt
|
|
|
|
|
export TAU_OPTIONS='-optKeepFiles -optVerbose -optTauSelectFile="select.tau"'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
In the above, the `-optKeepFiles` allows to keep intermediate files. The `-optTauSelectFile` specifies the file where additional profiling options are provided. These options are provided in a `select.tau` file (see below)
|
|
|
|
|
|
|
|
|
|
> \[!important\] The PDT parser will not work with resent C++ code. For example, it will fail with includes statements of the Boost library. You need to use Salt instead
|
|
|
|
|
|
|
|
|
|
##### Selecting profiled code
|
|
|
|
|
|
|
|
|
|
To select the parts of the code that will be profiled, you need to define a `select.tau` file, which is as follows:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
#Tell tau to not profile these functions
|
|
|
|
|
BEGIN_EXCLUDE_LIST
|
|
|
|
|
# You need to add void as argument!
|
|
|
|
|
void toto(void)
|
|
|
|
|
void quicksort(int *, int, int)
|
|
|
|
|
# The next line excludes all functions beginning with "sort_" and having
|
|
|
|
|
# arguments "int *"
|
|
|
|
|
void sort_#(int *)
|
|
|
|
|
void interchange(int *, int *)
|
|
|
|
|
END_EXCLUDE_LIST
|
|
|
|
|
|
|
|
|
|
#Exclude these files from profiling
|
|
|
|
|
BEGIN_FILE_EXCLUDE_LIST
|
|
|
|
|
*.so
|
|
|
|
|
END_FILE_EXCLUDE_LIST
|
|
|
|
|
|
|
|
|
|
BEGIN_INSTRUMENT_SECTION
|
|
|
|
|
# These section does not work with Salt!!!
|
|
|
|
|
# A dynamic phase will break up the profile into phase where
|
|
|
|
|
# each events is recorded according to what phase of the application
|
|
|
|
|
# in which it occured.
|
|
|
|
|
dynamic phase name="foo1_bar" file="foo.c" line=26 to line=27
|
|
|
|
|
|
|
|
|
|
# instrument all the outer loops in all the routines
|
|
|
|
|
loops file="*cpp" routine="#"
|
|
|
|
|
|
|
|
|
|
# tracks memory allocations/deallocations as well as potential leaks
|
|
|
|
|
memory file="foo.f90" routine="INIT"
|
|
|
|
|
|
|
|
|
|
# tracks the size of read, write and print statements in this routine
|
|
|
|
|
io file="foo.f90" routine="RINB"
|
|
|
|
|
|
|
|
|
|
END_INSTRUMENT_SECTION
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Here, we specify that loops will be instrumented in all the functions of the program.
|
|
|
|
|
|
|
|
|
|
Now, to compile the program, replace the standard compile commands as follows:
|
|
|
|
|
|
|
|
|
|
- `gcc` and `mpicc`-\> `tau_cc.sh`
|
|
|
|
|
- `g++` and `mpic++`-\> `tau_cxx.sh`
|
|
|
|
|
- `gfortran` and `mpifort`-\> `tau_f90.sh`
|
|
|
|
|
- `f77` and `mpif77`-\> `tau_f70.sh`
|
|
|
|
|
|
|
|
|
|
r example:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
tau_cxx.sh test_cpp.cpp -o test.exe
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Next, execute your code as follows:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./test.exe
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
A `paraprof.0.0.0` file will appear containing all the profiling informations. It can be opened by using the `paraprof` tool as follows:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
paraprof profile.0.0.0 &
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> **Note**: `.cubex` files can also be analysed using the Cube software, available as an App Image [here](https://www.scalasca.org/software/cube-4.x/download.html): `CubeGUI-4.8.2.AppImage scorep-20250310_1624_81500554863145/profile.cubex &`
|
|
|
|
|
|
|
|
|
|
### Profile with Scalasca
|
|
|
|
|
|
|
|
|
|
To profile a code with Scalasca, you need to compile the code by replacing:
|
|
|
|
|
|
|
|
|
|
- `g++` -\> `skin g++`
|
|
|
|
|
- `gfortran` -\> `skin gfortran`
|
|
|
|
|
- `mpicxx` -\> `skin mpicxx`
|
|
|
|
|
- `mpif90` -\> `skin mpif90`
|
|
|
|
|
- `gcc` -\> `skin gcc`
|
|
|
|
|
- `mpicc` -\> `skin mpicc`
|
|
|
|
|
- `mpif77` -\> `skin mpif77`
|
|
|
|
|
|
|
|
|
|
Once your code has been compiled, you can execute it as follows:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
scan test.exe
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Note**: to activate tracing, add a `-t` option to the `scan` command:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
scan -t test.exe
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
|
Resources:
|
|
Resources:
|
| ... | @@ -470,4 +204,3 @@ Resources: |
... | @@ -470,4 +204,3 @@ Resources: |
|
|
Acknowledgements:
|
|
Acknowledgements:
|
|
|
|
|
|
|
|
* Score-P support: Marc, Christian, Bill, Bert |
|
* Score-P support: Marc, Christian, Bill, Bert |
|
\ No newline at end of file |
|
|
|
|
* Tau support: Sameer, Nicholas |
|
|
|
\ No newline at end of file |
|
|