MPE is very useful for visualizing MPI programs, but it only provides compiler wrappers for C and Fortran: mpecc and mpef77, respectively. How can I use it if my MPI project is written in C++ and is normally compiled with mpic++, not mpicc (and so it can't be compiled with mpecc)?
How do I setup (1) the MPE library itself and (2) my C++ project?
The answer is actually quite simple, nonetheless I struggled with it for days.
Steps shown below works with MPICH 3.3.2 on Linux (Ubuntu 18) run with WSL2 - some adjustments may be necessary in different evnironments.
MPE library setup for c++
You setup the MPE library normally, the same way you would for a C project - the necessary steps are:
Download and extract the latest MPE archive (I've used MPE 2-1.4.9 from here)
Navigate to extracted directory:
cd mpe2-2.4.9bConfigure library's build process - in my case the following command worked:
./configure MPI_CC=mpicc MPI_F77=mpif77 prefix=$HOME/installs/mpe2 MPI_CFLAGS=-pthread MPI_FFLAGS=-pthreadExplanation:
mpic++asMPI_CC, the MPE library won't compile.pthreadlibrary - this may/may not be neccessary depending on your systemCompile the MPE library:
makeInstall the compiled library:
make installUsing MPE in c++ project
Since we cannot use a predefined compiler wrapper
mpeccto compile c++, we have to link the necessary libraries manually, as we would do with any other library.Suppose we have a file
main.cppwith following content:The specific command which allows to build a c++ file with MPI and MPE calls is:
mpic++ main.cpp -o main -I/$HOME/installs/mpe2/include -L/$HOME/installs/mpe2/lib -lmpe -pthreadExplanation:
mpic++to link the all MPI items automatically$HOME/installs/mpe2is an arbitrary installation path you've specified when configuring the MPE library-Iflag tells the compiler where to look for header files (the ones we#include)-Lflag tells the compiler where to find the compiled library items (implementation of functions defined in included header files)-lflag tells compiler to actually link our executable with specific library (which can be found thanks to us specyfing search location with-Lflag)pthreadmanually for MPE to work, but that may depend on your systemIf you use cmake for building your project, the following CMakeLists.txt should work: