MPI:更改CMakelists中的处理器数量
我正在使用CLion.我的CMakeLists.txt看起来像这样:
I'm using CLion. My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.2)
project(MPI)
add_executable(MPI main.cpp)
# Require MPI for this project:
find_package(MPI REQUIRED)
set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
include_directories(MPI_INCLUDE_PATH)
target_link_libraries(MPI ${MPI_LIBRARIES})
MPI-Hello World运行良好.但是如何更改cmakelist中的处理器数量?
The MPI - Hello World runs well. But how do I change the number of the processors in the cmakelists?
我已经尝试将-np 4和-n 4添加到CLion中的程序参数中.但是我还是得到
I already tried to add -np 4 and -n 4 to the program arguments in CLion. But still I just get
Hello World进程1之0
Hello World process 0 of 1
您不能在CMakeLists.txt中指定要使用的进程数.进程数是在使用mpirun执行程序时指定的参数.
You cannot specify number of processes to use in the CMakeLists.txt. Number of processes is an argument you specify when executing the program with mpirun.
要编译一个mpi C项目,请使用以下CMakeLists.txt
To compile a mpi C project I use following CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(hellompi)
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
SET(CMAKE_C_COMPILER mpicc)
SET(CMAKE_CXX_COMPILER mpicxx)
set(SOURCE_FILES main.c)
add_executable(hellompi ${SOURCE_FILES})
为了从Clion中执行程序,我首先更改了(模糊)位置,Clion默认将编译后的文件输出到该位置.您可以在构建,执行和部署"->"CMake"中的设置下为编译文件指定其他位置.我只是将其更改为项目文件夹.
In order to execute the program from Clion, I first changed the (obscure) location which Clion by default outputs compiled files to. You can specify another location for the compiled files under the settings in "Build, Execution and Deployment" -> "CMake". I just changed it to the project folder.
接下来,我编辑了运行配置.运行"->编辑配置"->将可执行文件"设置为mpirun.(mpirun在您计算机上的位置)
Next I edited the run configurations. "Run" -> "Edit Configurations" -> set Executable to mpirun. (the location of mpirun on your machine)
接下来,我将程序参数"编辑为
Next I edited the "Program arguments" to be
-np 4 /home/mitzh/ClionProjects/hellompi/Debug/hellompi
使用4个进程执行我的程序.
To execute my program using 4 processes.