-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·144 lines (123 loc) · 3.69 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·144 lines (123 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
set -e
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
USE_WRAPPERS=1
# Process command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--without-wrappers)
USE_WRAPPERS=0
shift
;;
*)
# Remaining arguments are test files
break
;;
esac
done
# Check if conda is active
if [[ -z "$CONDA_PREFIX" ]]; then
echo -e "${RED}Error: No Conda environment is active. Please activate a conda env with MPI installed.${NC}"
exit 1
fi
# Try locating mpiexec
if [[ -x "${CONDA_PREFIX}/bin/mpiexec" ]]; then
MPIEXEC="${CONDA_PREFIX}/bin/mpiexec"
elif command -v mpiexec &> /dev/null; then
MPIEXEC=$(command -v mpiexec)
else
echo -e "${RED}Error: mpiexec not found. Please install MPI (OpenMPI or MPICH) via Conda or system package manager.${NC}"
exit 1
fi
# detect MPI implementation
MPI_VERSION=$($MPIEXEC --version 2>&1)
if echo "$MPI_VERSION" | grep -q "Open MPI"; then
MPI_TYPE="openmpi"
elif echo "$MPI_VERSION" | grep -q "MPICH"; then
MPI_TYPE="mpich"
else
# we don't yet support other MPI implementations
# like intel MPI etc.0
echo -e "${RED}Unknown MPI implementation!${NC}"
exit 1
fi
if [ $USE_WRAPPERS -eq 0 ]; then
FC=mpif90
else
if [[ "$(uname)" == "Linux" ]]; then
CC=gcc
else
CC=clang
fi
fi
# Define preprocessor flags based on MPI type
FC_FLAGS=""
if [[ "$MPI_TYPE" == "openmpi" ]]; then
FC_FLAGS="-DOPEN_MPI"
fi
echo -e "${RED}Removing all untracked files${NC}"
git clean -dfx
echo -e "#################################"
echo -e "${YELLOW}Using FC=${FC} compiler${NC}"
echo -e "${YELLOW}Using CC=${CC} compiler${NC}"
echo -e "################################"
echo -e
# If user specified a particular test (e.g. ./run_tests.sh bcast.f90),
# then only build & run that file. Otherwise, build & run all *.f90 files.
if [ $# -gt 0 ]; then
TEST_FILES=("$@")
echo -e "${YELLOW}Received argument(s). Will only compile/run: ${TEST_FILES[*]}${NC}"
else
# No arguments, so gather all .f90 test files in the current directory
TEST_FILES=( *.f90 )
echo -e "${YELLOW}No specific test file given. Will compile/run all .f90 tests...${NC}"
fi
if [ $USE_WRAPPERS -eq 1 ]; then
$CC -I"$CONDA_PREFIX/include" -c ../src/mpi_constants.c
$FC $FC_FLAGS -c ../src/mpi_c_bindings.f90
$FC $FC_FLAGS -c ../src/mpi.f90
fi
start_time=$(date +%s)
# Now compile & run each requested test
for file in "${TEST_FILES[@]}"; do
if [[ ! -f "$file" ]]; then
echo -e "${RED}Test file '$file' not found! Skipping...${NC}"
continue
fi
filename=$(basename "$file" .f90)
echo -e "${YELLOW}Compiling $filename...${NC}"
$FC -c "$file"
if [ $USE_WRAPPERS -eq 1 ]; then
$FC mpi_constants.o mpi_c_bindings.o mpi.o "$filename.o" \
-o "$filename" -L"$CONDA_PREFIX/lib" -lmpi -Wl,-rpath,"$CONDA_PREFIX/lib"
else
$FC "$filename.o" -o "$filename"
fi
# Test with 1, 2, and 4 ranks
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}"
else
echo -e "${RED}Test $filename with $np MPI ranks FAILED!${NC}"
exit 1
fi
done
done
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo ""
echo -e "${YELLOW}... Running standalone tests took ${elapsed_time} seconds ...${NC}"
echo ""