c:mpi:clion-ide-mpi-config
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| c:mpi:clion-ide-mpi-config [2024/02/21 15:20] – removed - external edit (Unknown date) 127.0.0.1 | c:mpi:clion-ide-mpi-config [2024/02/21 15:20] (current) – ↷ Page moved and renamed from c-lion-ide-mpi-config to c:mpi:clion-ide-mpi-config odefta | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Configure CLion to run an Open MPI project on Windows ====== | ||
| + | |||
| + | ===== Install OpenMPI on Ubuntu | ||
| + | |||
| + | After installing WSL2/ | ||
| + | |||
| + | < | ||
| + | sudo apt-get install openmpi-bin openmpi-common libopenmpi-dev | ||
| + | </ | ||
| + | |||
| + | ===== Configure CLion to use WSL2 ===== | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== Change build directory ===== | ||
| + | |||
| + | Set build directory to the root project folder: | ||
| + | {{: | ||
| + | |||
| + | ===== Include MPI references in CMake file ===== | ||
| + | |||
| + | <code cmake CMakeLists.txt> | ||
| + | cmake_minimum_required(VERSION 3.2) | ||
| + | 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}) | ||
| + | </ | ||
| + | |||
| + | ===== Add source file ===== | ||
| + | |||
| + | <code c main.c> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | int main(int argc, char** argv) { | ||
| + | // Initialize the MPI environment | ||
| + | MPI_Init(NULL, | ||
| + | |||
| + | // Get the number of processes | ||
| + | int world_size; | ||
| + | MPI_Comm_size(MPI_COMM_WORLD, | ||
| + | |||
| + | // Get the rank of the process | ||
| + | int world_rank; | ||
| + | MPI_Comm_rank(MPI_COMM_WORLD, | ||
| + | |||
| + | // Check if the current process is the master process | ||
| + | if (world_rank == 0) { | ||
| + | // Master process prints this message | ||
| + | printf(" | ||
| + | } else { | ||
| + | // All other processes print this message | ||
| + | printf(" | ||
| + | | ||
| + | } | ||
| + | |||
| + | // Finalize the MPI environment. | ||
| + | MPI_Finalize(); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Build the project ===== | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Reload also cmake project if you have issues: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== Add a CLion Run Configuration ===== | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== Run the project ===== | ||
| + | |||
| + | {{: | ||
