Tool Time: Using the Python Extrae API to Profile Python OpenMP Codes

Wednesday, September 15, 2021

Extrae supports the collecting of trace data for Python codes. This is commonly done for codes using MPI or the multiprocessing package but, as well as this, the Intel distributions of the NumPy and SciPy Python packages both support Intel MKL which means both packages can take advantage of OpenMP parallelism. These versions of NumPy/SciPy can be installed as part of the Anaconda Python distribution. Note that if NumPy is installed via pip, it will use BLAS rather than Intel MKL and so will not contain any parallelism.

The directory $EXTRAE_HOME/libexec contains Python modules to be used in user codes. However, a module for OpenMP does not exist by default so one has to be made manually. Firstly, the Python module path should be set:


Then create a directory in $EXTRAE_HOME/libexec/pyextrae named “omp” and create a file in that directory named “”.

Inside the file, add the lines:

from pyextrae.common.extrae import *
TracingLibrary = “”

Note this Python module file can be created anywhere as long as $EXTRAE_HOME/libexec is set correctly, and your Python code can access this new file.

To use this module, import it into your Python code with:

import pyextrae.omp as pyextrae

If you do not want to profile the initialisation section of the code, profiling can be disabled:


Profiling can be enabled once again with:


These shutdown() and restart() functions can be used to profile specific regions of the Python code.