如何使用 MPE 进行 MPI c++项目?

发布于 2025-01-19 18:25:27 字数 236 浏览 3 评论 0 原文

MPE对于可视化MPI程序非常有用,但是它仅为C和Fortran提供编译器包装器: MPECC MPEF77 。如果我的MPI项目是用C ++编写的,并且通常使用 MPIC ++ ,而不是 MPICC (因此无法使用 MPECC编译,我该如何使用它。 )?

如何设置(1)MPE库本身和(2)我的C ++项目?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-26 18:25:27

答案实际上很简单,尽管如此,我已经挣扎了几天。

下面显示的步骤可与Linux(Ubuntu 18)上的MPICH 3.3.2一起使用WSL2运行 - 在不同的Evnironments中可能需要进行一些调整。


C ++的MPE库设置

您正常设置MPE库,就像C项目相同的方式 - 必要的步骤是:

  1. 下载并提取最新的MPE档案(我使用过 mpe 2-1.4.9 来自在这里

  2. 导航到提取的目录:

    CD MPE2-2.4.9B

  3. 配置库的构建过程 - 在我的情况下,以下命令工作:

    ./ configure mpi_cc = mpiCc mpi_f77 = mpif77 prefix = $ home/installs/mpe2 mpi_cflags = -pthread mpi_fflags = -pthread

    说明:

    • mpe是在C中编写的,因此我们使用 MPICC 对其进行编译 - 我们还没有(尚未)指定如何构建我们的项目,因此我们不使用MPIC ++。如果我们使用 MPIC ++ 作为 mpi_cc ,则MPE库不会编译。
    • 指定fortran标志不是严格必要的,但是这样我们避免了编译输出中的不确定错误
    • 前缀(安装路径)是您选择的任意路径,请记住您在此处插入的内容,因为需要进一步的步骤
    • 我必须提供 pthread library的手动链接 - 这可能/可能不是必不可少的,具体取决于您的系统

  4. 我必须提供 pthread 库的手动链接 - 根据您的系统

    编译MPE库:

    make

  5. 安装编译库:

    使安装


使用C ++项目中的MPE

因为我们不能使用预定义的编译器包装器 mpecc 来编译C ++,我们必须手动链接必要的库,就像我们一样将与任何其他库一起使用。

假设我们有一个文件 main.cpp 带有以下内容:

#include <mpi.h>
#include <mpe.h>

/* other necessary includes */

int main(int argc, char** argv) {
    MPI_Init(&argc, &argv);
    MPE_Init_log();

    /* some MPI and MPE stuff */

    MPE_Finish_log("test");
    MPI_Finalize();
}

允许使用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 时指定的任意安装路径。
  • /installs/mpe2 是您在配置MPE库 -i flag )
  • -l <​​/code> flag告诉编译器在哪里可以找到编译的库项目(在随附的标头文件中定义的函数的实现)
  • -l <​​/code> flag告诉编译器实际链接我们可以使用特定库的可执行文件(这要感谢我们使用 -L flag Specyfing搜索位置),
  • 我必须链接 pthread 手动以使MPE工作,但这可能取决于在系统上,

如果您使用 cmake 构建项目,则以下cmakelists.txt应该有效:

cmake_minimum_required(VERSION 3.5)  # not necessarily 3.5, it;s just my setup

project(mpi_test)  # arbitrary project name

find_package(MPI REQUIRED)
set(CMAKE_CXX_COMPILER mpic++)

include_directories($ENV{HOME}/installs/mpe2/include)  # again, it's the MPE installation path
link_directories($ENV{HOME}/installs/mpe2/lib)  # again, it's the MPE installation path

add_executable(main_exp src/main_exp.cpp)
target_link_libraries(main_exp mpe pthread)  # again, pthread may/may not be neccessary

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:

  1. Download and extract the latest MPE archive (I've used MPE 2-1.4.9 from here)

  2. Navigate to extracted directory:

    cd mpe2-2.4.9b

  3. 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:

    • MPE is written in C, so we use mpicc to compile it - we do not (yet) specify how to build our project, so we do not use mpic++. If we use mpic++ as MPI_CC, the MPE library won't compile.
    • specifying Fortran flags isn't strictly necessary, but this way we avoid unneccessary errors in compilation output
    • prefix (installation path) is an arbitrary path of your choice, just remember what you have inserted here as it will be necessary in further steps
    • I had to provide manual linkage of the pthread library - this may/may not be neccessary depending on your system
  4. Compile the MPE library:

    make

  5. 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:

#include <mpi.h>
#include <mpe.h>

/* other necessary includes */

int main(int argc, char** argv) {
    MPI_Init(&argc, &argv);
    MPE_Init_log();

    /* some MPI and MPE stuff */

    MPE_Finish_log("test");
    MPI_Finalize();
}

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:

  • We use 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)
  • I had to link pthread manually for MPE to work, but that may depend on your system

If you use cmake for building your project, the following CMakeLists.txt should work:

cmake_minimum_required(VERSION 3.5)  # not necessarily 3.5, it;s just my setup

project(mpi_test)  # arbitrary project name

find_package(MPI REQUIRED)
set(CMAKE_CXX_COMPILER mpic++)

include_directories($ENV{HOME}/installs/mpe2/include)  # again, it's the MPE installation path
link_directories($ENV{HOME}/installs/mpe2/lib)  # again, it's the MPE installation path

add_executable(main_exp src/main_exp.cpp)
target_link_libraries(main_exp mpe pthread)  # again, pthread may/may not be neccessary
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文