From 0368720527e920a4186c42718de9b4ff86fddd59 Mon Sep 17 00:00:00 2001 From: Cheng Li <69489965+chengcli@users.noreply.github.com> Date: Sun, 2 Jul 2023 00:43:54 -0400 Subject: [PATCH] Enable MPI (#11) --- .github/workflows/main.yml | 32 ++++++++++++++++++++++++++++++++ cmake/parameters.cmake | 4 ++++ src/CMakeLists.txt | 8 ++++++++ src/application.cpp | 4 ++-- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ae6744..3f7e3b5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,3 +57,35 @@ jobs: - name: Compare main run: cat ${{github.workspace}}/build/tests/main.out | wc > main.check && diff -b main.check ${{github.workspace}}/tests/main.check + + build-mpi: + runs-on: ubuntu-latest + needs: greeting + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: install python modules + run: sudo pip install -r requirements.txt + + - name: install mpi + run: sudo apt install mpich + + - name: create build directory + run: cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DMPI_OPTION=MPI_PARALLEL -B ${{github.workspace}}/build + + - name: Build + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build/tests + run: ctest -C ${{env.BUILD_TYPE}} + + - name: Compare A + run: cat ${{github.workspace}}/build/tests/A.out | wc > A.check && diff -b A.check ${{github.workspace}}/tests/A.check + + - name: Compare B + run: cat ${{github.workspace}}/build/tests/B.out | wc > B.check && diff -b B.check ${{github.workspace}}/tests/B.check + + - name: Compare main + run: cat ${{github.workspace}}/build/tests/main.out | wc > main.check && diff -b main.check ${{github.workspace}}/tests/main.check diff --git a/cmake/parameters.cmake b/cmake/parameters.cmake index 024818e..a71d2ff 100644 --- a/cmake/parameters.cmake +++ b/cmake/parameters.cmake @@ -13,3 +13,7 @@ SET_IF_EMPTY(MYPATH "") # MPI parallelization (MPI_PARALLEL or NOT_MPI_PARALLEL) SET_IF_EMPTY(MPI_OPTION "NOT_MPI_PARALLEL") + +if(MPI_OPTION STREQUAL "MPI_PARALLEL") + find_package(MPI REQUIRED) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c57393e..48ff831 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,3 +14,11 @@ add_library(${namel}_${buildl} STATIC ${src_files}) set_target_properties(${namel}_${buildl} PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS_${buildu}}) +target_include_directories(${namel}_${buildl} + SYSTEM PRIVATE + ${MPI_CXX_INCLUDE_PATH} + ) + +target_link_libraries(${namel}_${buildl} + ${MPI_CXX_LIBRARIES} + ) diff --git a/src/application.cpp b/src/application.cpp index dd4adf3..82324ea 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -106,12 +106,12 @@ void Application::Start(int argc, char** argv) { // Get process id (rank) in MPI_COMM_WORLD if (MPI_SUCCESS != MPI_Comm_rank(MPI_COMM_WORLD, &(Globals::my_rank))) { - throw RuntimeError("MPI_Comm_rank failed"); + throw RuntimeError("Start", "MPI_Comm_rank failed"); } // Get total number of MPI processes (ranks) if (MPI_SUCCESS != MPI_Comm_size(MPI_COMM_WORLD, &Globals::nranks)) { - throw RuntimeError("MPI_Comm_size failed"); + throw RuntimeError("Start", "MPI_Comm_size failed"); } // Get maximum value of MPI tag