CMake:手动设置MPI标头和二进制文件的路径 [英] CMake: set path to MPI headers and binaries manually
问题描述
我正在开发一个MPI应用程序,该应用程序需要与MPI的特定实现一起运行(我们将其称为MPIvA).在我的工作站上,安装了另一种MPI实现(称为MPIvB).
I am developing an MPI application which requires to be run with a specific implementation of MPI (let's call it MPIvA). On my workstation, another implementation of MPI (let's call it MPIvB) is installed.
我的应用程序是使用CMake构建的,而find_library(MPI)
显然指向MPIvB.它可以轻松编译和运行.
My application is built using CMake and the find_library(MPI)
obviously points to MPIvB. It compiles and runs without hassle.
我在工作站上编译了MPIvA.如何使CMake使用这些标头和二进制文件?
I compiled MPIvA on my workstation. How can I make CMake use these headers and binaries?
推荐答案
嗯,这不是新文章,但将来可能对其他人有用.
Well, this is not a new post but it may be useful to others in the future.
即使前面的答案也可以,但我认为更好的方法是使用 CMAKE_PREFIX_PATH 选项,例如
Even though the previous answers can also work, I think that the a better approach is to use the CMAKE_PREFIX_PATH option, ie sth like
CMAKE_PREFIX_PATH=~/my-libs-install-path ccmake ..
现在,其他一些评论:
-
所有MPI库都应可互换,即使用MPI规范的代码应编译并与任何MPI实现一起运行(例如,我假设是intelmpi,openmpi或mpich的MPIvA和MPIvB).
All MPI libraries should be interchangeable, ie code that uses the MPI specification should compile and run with any MPI implementation (eg MPIvA and MPIvB which I am assuming are intelmpi,openmpi or mpich).
关于这个答案(我的名声不允许我发表评论,所以我在这里回复):
Regarding this answer (my reputation doesn't allow me to comment so I reply here):
find_package(MPI REQUIRED)
if (MPI_FOUND)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
else (MPI_FOUND)
message(SEND_ERROR "This application cannot compile without MPI")
endif (MPI_FOUND)
即使该功能大部分与预期的一样,但以下功能等效:
even though the functionality would be mostly as expected, the following is functionally equivalent:
find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
findpackage(需要MPI)命令中的 REQUIRED 部分将导致该命令在未找到MPI的情况下失败,因此 if(MPI_FOUND)部分没有用,else子句实际上永远不会执行.
The REQUIRED part in the findpackage(MPI REQUIRED) command will cause the command to fail if MPI is not found, so the if(MPI_FOUND) part is useless and the else clause will actually never be executed.
-
最后,关于 include_directories 命令,如果您使用目标(例如
Finally, regarding the include_directories command, in my tests was not required if you are using targets, eg
target_link_libraries(my_app PUBLIC MPI :: C)
target_link_libraries(my_app PUBLIC MPI::C)
足够了.
这篇关于CMake:手动设置MPI标头和二进制文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!