- Download and install MPI from Microsoft Website. You need to download both
msmpisetup.exeandmsmpisdk.msi.
Note that you shouldn't have spaces or cyrillic characters in path to MPI installation.
- Open Windows Terminal and try running
mpiexec:
Microsoft MPI Startup Program [Version 10.1.12498.18]
...If the mpiexec command isn't recognised by your system try restarting your PC and check if MPI system variables are installed correctly:
| Name | Value |
|---|---|
| MSMPI_BENCHMARKS | path_to_mpi\Benchmarks\ |
| MSMPI_BIN | path_to_mpi\Bin\ |
| MSMPI_INC | path_to_mpi\SDK\Include\ |
| MSMPI_LIB32 | path_to_mpi\SDK\Lib\x86\ |
| MSMPI_LIB64 | path_to_mpi\SDK\Lib\x64\ |
And path_to_mpi\Bin\ path is added to Path variable.
To view system variables open Windows Search -> Input "Variables" -> Click on "Edit the system environment variables" -> Click on "Environemnt Variables on "System Properties" Window.
path_to_mpiis a path to your Microsoft MPI installation.
-
Open CLion and create new
C++ ExecutableProject. -
Open
CMakeLists.txtwhere you should see something like this: (MY_PROJECTis project name)
cmake_minimum_required(VERSION 3.20)
project(MY_PROJECT)
set(CMAKE_CXX_STANDARD 14)
add_executable(MY_PROJECT main.cpp)
- Add MPI Package and MPI Library to project
cmake_minimum_required(VERSION 3.20)
project (MY_PROJECT)
set(CMAKE_CXX_STANDARD 14)
# Add MPI Package to Project
find_package(MPI REQUIRED)
add_executable(MY_PROJECT main.cpp)
# Add libraries for code completion and compiling
target_link_libraries(MY_PROJECT PUBLIC MPI::MPI_CXX)- Add following run configurations:
1) CMake Application
| Property | Value |
|---|---|
| Name | Compile |
| Tagret | MY_PROJECT |
| Executable | MY_PROJECT |
IMPORTANT! Replace
MY_PROJECTwith the name of your project!
2) Shell Script
| Property | Value |
|---|---|
| Name | 2 Cores |
| Execute | Script text |
| Script text | mpiexec -n 2 ./cmake-build-debug/MY_PROJECT |
| Working directory | project_directory/MY_PROJECT |
| Execute in the terminal | true |
Add more shell scripts for number of cores you would like to use while executing your project. Replace number
2inNameandScript textproperties with number of cores you would like to use.
MY_PROJECTis a name of.exefile in./cmake-build-debugfolder.
- Add following code to
main.cpp:
#include <mpi.h>
#include <cstdio>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}-
Setup CMake "Release" configuration. Go to
Settings->Build, Execution, Deployment->CMake. Click on "Plus" sign and a new "Release" configuration should be created. Click on "OK" or "Apply". -
Select "Release" under "Configurations" dropdown.
-
Run
Compileconfiguration before executing any ofX Coresconfigurations.
If you are getting an error "Cannot start process, the working directory '../cmake-build-release' does not exist" then RMC on your project folder and select "Reload CMake Project".
To get this working standard C, use the following CMakeLists.txt template instead: