From 970094f8c73d8ef2ebfc714918c17352fc288367 Mon Sep 17 00:00:00 2001 From: Gaurav Dhingra Date: Tue, 25 Mar 2025 18:41:29 +0530 Subject: [PATCH 1/3] CI: run standalone tests with MPI rank 4 as well --- tests/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 5eaaabf..367df3e 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -26,7 +26,7 @@ for file in *.f90; do $FC -c $file $FC mpi_wrapper.o mpi_c_bindings.o mpi.o $filename.o -o $filename -L$CONDA_PREFIX/lib -lmpi -Wl,-rpath,$CONDA_PREFIX/lib - for np in 1 2; do + for np in 1 2 4; do echo -e "${YELLOW}Running $filename with $np MPI ranks...${NC}" if ${MPIEXEC} -np $np ./$filename; then echo -e "${GREEN}Test $filename with $np MPI ranks PASSED!${NC}" From 029762cd6004267a2e8bcfd2bf0f418b68089055 Mon Sep 17 00:00:00 2001 From: Gaurav Dhingra Date: Wed, 26 Mar 2025 09:23:23 +0530 Subject: [PATCH 2/3] use `--oversubscribe` option with Open MPI but not with MPICH --- tests/run_tests.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 367df3e..5a3b427 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -9,6 +9,21 @@ NC='\033[0m' # No Color MPIEXEC=${CONDA_PREFIX}/bin/mpiexec +# Detect MPI implementation +# NOTE: I've noticed that using '--oversubscribe' with Open MPI takes a +# lot of time to run on local machine, than without it +MPI_VERSION=$($MPIEXEC --version 2>&1) +if echo "$MPI_VERSION" | grep -q "Open MPI"; then + MPI_TYPE="openmpi" + MPIEXEC_ARGS="--oversubscribe" +elif echo "$MPI_VERSION" | grep -q "MPICH"; then + MPI_TYPE="mpich" + MPIEXEC_ARGS="" # MPICH usually allows oversubscription by default +else + echo -e "${RED}Unknown MPI implementation!${NC}" + exit 1 +fi + if [[ "$(uname)" == "Linux" ]]; then CC=gcc else @@ -28,7 +43,7 @@ for file in *.f90; do for np in 1 2 4; do echo -e "${YELLOW}Running $filename with $np MPI ranks...${NC}" - if ${MPIEXEC} -np $np ./$filename; then + if ${MPIEXEC} -np $np $MPIEXEC_ARGS ./$filename; then echo -e "${GREEN}Test $filename with $np MPI ranks PASSED!${NC}" else echo -e "${RED}Test $filename with $np MPI ranks FAILED!${NC}" From 5da468d752d6abf6b48948f176ec5deea36643da Mon Sep 17 00:00:00 2001 From: Gaurav Dhingra Date: Wed, 26 Mar 2025 09:39:20 +0530 Subject: [PATCH 3/3] don't use `--oversubscribe` for rank 1 or rank 2 with Open MPI --- tests/run_tests.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 5a3b427..4f510b0 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -9,17 +9,15 @@ NC='\033[0m' # No Color MPIEXEC=${CONDA_PREFIX}/bin/mpiexec -# Detect MPI implementation -# NOTE: I've noticed that using '--oversubscribe' with Open MPI takes a -# lot of time to run on local machine, than without it +# detect MPI implementation MPI_VERSION=$($MPIEXEC --version 2>&1) if echo "$MPI_VERSION" | grep -q "Open MPI"; then MPI_TYPE="openmpi" - MPIEXEC_ARGS="--oversubscribe" elif echo "$MPI_VERSION" | grep -q "MPICH"; then MPI_TYPE="mpich" - MPIEXEC_ARGS="" # MPICH usually allows oversubscription by default else + # we don't yet support other MPI implementations + # like intel MPI etc.0 echo -e "${RED}Unknown MPI implementation!${NC}" exit 1 fi @@ -30,7 +28,7 @@ else CC=clang fi -# Compile C and Fortran sources +# compile C and Fortran sources $CC -I$CONDA_PREFIX/include -c ../src/mpi_wrapper.c $FC -c ../src/mpi_c_bindings.f90 $FC -c ../src/mpi.f90 @@ -42,6 +40,15 @@ for file in *.f90; do $FC mpi_wrapper.o mpi_c_bindings.o mpi.o $filename.o -o $filename -L$CONDA_PREFIX/lib -lmpi -Wl,-rpath,$CONDA_PREFIX/lib for np in 1 2 4; do + # set MPIEXEC_ARGS based on MPI type and number of ranks + # `--oversubscribe` isn't needed with Open MPI when running + # with 1 or 2 ranks + if [[ "$MPI_TYPE" == "openmpi" && $np -gt 2 ]]; then + MPIEXEC_ARGS="--oversubscribe" + else + MPIEXEC_ARGS="" + fi + echo -e "${YELLOW}Running $filename with $np MPI ranks...${NC}" if ${MPIEXEC} -np $np $MPIEXEC_ARGS ./$filename; then echo -e "${GREEN}Test $filename with $np MPI ranks PASSED!${NC}"