CMake:在 openmpi 上选择 mpich

CMake : Selecting mpich over openmpi

我正在使用 cmake 3.10.2。我同时安装了 openmpi 和 mpich。但是我只需要加载 mpich。所以我从文档中找到了以下

MPI_EXECUTABLE_SUFFIX

A suffix which is appended to all names that are being looked for. For instance you may set this to .mpich or .openmpi to prefer the one or the other on Debian and its derivatives.

我的 CMake 文件是这样的

set(MPI_EXECUTABLE_SUFFIX ".mpich")
FIND_PACKAGE(MPI REQUIRED)
INCLUDE_DIRECTORIES(${MPI_INCLUDE_DIRS})
LINK_DIRECTORIES(${MPI_LIBRARY_DIRS})
message(${MPI_INCLUDE_PATH})

然而这表明

/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/usr/lib/x86_64-linux-gnu/openmpi/include...

我哪里错了。你能帮我解决一下吗

还有

mpicc -show
gcc -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent/include -I/usr/lib/x86_64-linux-gnu/openmpi/include -pthread -L/usr//lib -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi

mpicc.mpich -show
gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -I/usr/include/mpich -L/usr/lib/x86_64-linux-gnu -lmpich

默认的 mpicc 不是你的选择。您可以在 cmake 文件中手动指定它,或者使用包含在默认值之前的 mpicc 更新 $PATH 变量。就个人而言,我将 mpich 安装在 /usr/local/ 目录中。 问候

openmpi 和 mpich 之间的切换最好是使用模块:

$ module load mpich
$ module unload mpich  
$ module load openmpi

http://modules.sourceforge.net/