笔者手头有一前辈所留的C++的MPI并行程序源代码,采用CMake构建的。笔者在编译的时候,系统提示错误如下
[cmake] -- Could NOT find MPI_CXX (missing: MPI_CXX_WORKS)
[cmake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake] Could NOT find MPI (missing: MPI_CXX_FOUND)
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake] C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindMPI.cmake:1741 (find_package_handle_standard_args)
[cmake] CMakeLists.txt:6 (find_package)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
查看CMakeLists.txt,如下
cmake_minimum_required(VERSION 2.8)
project(DRLab CXX)
SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_CXX_FLAGS "-std=c++11")
find_package(MPI REQUIRED)
set(SRC_DIR src/)
set(APP_DIR apps/)
set(TEST_DIR tests/)
set(INC_DIR ${PROJECT_SOURCE_DIR}/inc/)
#add includes
include_directories(${MPI_CXX_INCLUDE_PATH})
set(INCS algorithm core grid helper io lbm parallelism pipt)
foreach(inc ${INCS})
include_directories(${INC_DIR}${inc}/)
endforeach(inc)
add_subdirectory(${SRC_DIR})
add_subdirectory(${APP_DIR})
add_subdirectory(${TEST_DIR})
第6行的意思是,CMake在系统上查找mpi的sdk.报错的原因就很清楚了,CMake在系统上未发现mpi的sdk,因此,要安装mpi并将mpi的路径暴露给Cmake。
常用的mpi sdk,其中openmpi适合于单机多核并行,mpich适合于集群并行。
- msmpi:
- Download Microsoft MPI v10.0 from Official Microsoft Download Center
- 下载两个文件,都安装,一个是mpi sdk,一个是mpi的mpiexex执行程序
- openmpi:
- Open MPI: Open Source High Performance Computing (open-mpi.org)
- mpich:
- MPICH | High-Performance Portable MPI
windows下建议安装msmpi,linux下根据单机并行或者集群并行进行相应的选择。
安装完成后,sdk的默认位置是
MSMPI的可执行文件在
OK,关闭VSCode,再次打开,选择Visual Studio 的amd64编译器,重新编译
[build] Build finished with exit code 0
编译成功