Skip to content

Commit

Permalink
Enable MPI (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcli authored Jul 2, 2023
1 parent ab23f74 commit 0368720
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions cmake/parameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
4 changes: 2 additions & 2 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0368720

Please sign in to comment.