如何使用 MPE 进行 MPI c++项目?
MPE对于可视化MPI程序非常有用,但是它仅为C和Fortran提供编译器包装器: MPECC
和 MPEF77
。如果我的MPI项目是用C ++编写的,并且通常使用 MPIC ++
,而不是 MPICC
(因此无法使用 MPECC编译,我该如何使用它。
)?
如何设置(1)MPE库本身和(2)我的C ++项目?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案实际上很简单,尽管如此,我已经挣扎了几天。
下面显示的步骤可与Linux(Ubuntu 18)上的MPICH 3.3.2一起使用WSL2运行 - 在不同的Evnironments中可能需要进行一些调整。
C ++的MPE库设置
您正常设置MPE库,就像C项目相同的方式 - 必要的步骤是:
下载并提取最新的MPE档案(我使用过 mpe 2-1.4.9 来自在这里)
导航到提取的目录:
CD MPE2-2.4.9B
配置库的构建过程 - 在我的情况下,以下命令工作:
./ configure mpi_cc = mpiCc mpi_f77 = mpif77 prefix = $ home/installs/mpe2 mpi_cflags = -pthread mpi_fflags = -pthread
说明:
MPIC ++
作为mpi_cc
,则MPE库不会编译。pthread
library的手动链接 - 这可能/可能不是必不可少的,具体取决于您的系统pthread
库的手动链接 - 根据您的系统编译MPE库:
,
make
安装编译库:
使安装
使用C ++项目中的MPE
因为我们不能使用预定义的编译器包装器
mpecc
来编译C ++,我们必须手动链接必要的库,就像我们一样将与任何其他库一起使用。假设我们有一个文件
main.cpp
带有以下内容:允许使用MPI和MPE调用构建C ++文件的特定命令为:
mpic ++ main.cpp -o main -i main -i/$ home/installs/mpe2/include -l/$ home/installs/mpe2/lib -lmpe -pthread
说明:
mpic ++
来链接所有mpi项目自动$ $ home 时指定的任意安装路径。
-i
flag )-l </code> flag告诉编译器在哪里可以找到编译的库项目(在随附的标头文件中定义的函数的实现)
-l </code> flag告诉编译器实际链接我们可以使用特定库的可执行文件(这要感谢我们使用
-L
flag Specyfing搜索位置),pthread
手动以使MPE工作,但这可能取决于在系统上,如果您使用 cmake 构建项目,则以下cmakelists.txt应该有效:
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.9b
Configure 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=-pthread
Explanation:
mpic++
asMPI_CC
, the MPE library won't compile.pthread
library - this may/may not be neccessary depending on your systemCompile the MPE library:
make
Install the compiled library:
make install
Using MPE in c++ project
Since we cannot use a predefined compiler wrapper
mpecc
to compile c++, we have to link the necessary libraries manually, as we would do with any other library.Suppose we have a file
main.cpp
with 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 -pthread
Explanation:
mpic++
to link the all MPI items automatically$HOME/installs/mpe2
is an arbitrary installation path you've specified when configuring the MPE library-I
flag tells the compiler where to look for header files (the ones we#include
)-L
flag tells the compiler where to find the compiled library items (implementation of functions defined in included header files)-l
flag tells compiler to actually link our executable with specific library (which can be found thanks to us specyfing search location with-L
flag)pthread
manually for MPE to work, but that may depend on your systemIf you use cmake for building your project, the following CMakeLists.txt should work: