You cannot specify the number of processes that will be used in CMakeLists.txt. The number of processes is the argument that you specify when running the program using mpirun.
To compile the mpi C project, I use the 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})
To run the program from Clion, I first changed the (obscure) location that Clion defaults to compiling files. You can specify a different location for the compiled files in the settings "Build, Execution and Deployment" → "CMake". I just changed it to the project folder.
Next, I edited the launch configurations. "Run" → "Edit configurations" → install the executable file in mpirun. (location of mpirun on your computer)
Next, I edited Programmatic Arguments as
-np 4 /home/mitzh/ClionProjects/hellompi/Debug/hellompi
To execute my program using 4 processes.
Michelrandahl
source share