-
Notifications
You must be signed in to change notification settings - Fork 7
/
pytest-mpi
executable file
·105 lines (94 loc) · 3.23 KB
/
pytest-mpi
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
#!/bin/bash
NPROCS=5
VERBOSE=0
CAPTURE=0
SUMMARY=0
EXITFIRST=0
UNMUTE=-1
ORDEROUTPUT=0
COVERAGE=0
COVERAGE_APPEND=0
HELP=0
LOGCLI=0
while [[ "$#" -gt 0 ]]; do
case $1 in
-n|--nprocs) NPROCS="$2"; shift ;;
-u|--unmute) UNMUTE="$2"; shift ;;
-v|--verbose) VERBOSE=1 ;;
-s|--capture=no) CAPTURE=1 ;;
-x|--exitfirst) EXITFIRST=1 ;;
-ns|--no-summary) SUMMARY=1 ;;
-c|--coverage) COVERAGE=1 ;;
-ca|--cov-append) COVERAGE_APPEND=1 ;;
-oo|--order-output) ORDEROUTPUT=1 ;;
-lc|--log-cli) LOGCLI=1 ;;
-h|--help) HELP=1 ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [ "${HELP}" -eq 1 ]
then
echo "usage: pytest-mpi [options]"
echo ""
echo "positional arguments:"
echo " none"
echo ""
echo "general options:"
echo " -h --help Show help commands."
echo " -n --nprocs <nprocs> Specify the number of MPI processes."
echo " -v --verbose Pass --verbose to pytest."
echo " -s --capture=no Pass --capture=no to pytest."
echo " -x --exitfirst Pass --exitfirst to pytest."
echo " -ns --no-summary Pass --no-summary to pytest."
echo " -c --coverage Pass --cov=./ to pytest."
echo " -ca --cov-append Pass --cov-append to pytest."
echo " -oo --order-output Dump output from ranks in order."
echo " -lc --log-cli Pass --log-cli=true to pytest."
echo " -u --unmute Unmute (show output from) only a specfic MPI rank."
else
# Note: fails if (for some reason) `utils/mute_all_ranks_except.sh` is not
# marked as executable `chmod +x utils/mute_all_ranks_except.sh`
PYTEST_ARGS=""
if [ "${VERBOSE}" -eq 1 ]; then
PYTEST_ARGS="${PYTEST_ARGS} --verbose"
fi
if [ "${CAPTURE}" -eq 1 ]; then
PYTEST_ARGS="${PYTEST_ARGS} --capture=no"
fi
if [ "${SUMMARY}" -eq 1 ]; then
PYTEST_ARGS="${PYTEST_ARGS} --no-summary"
fi
if [ "${EXITFIRST}" -eq 1 ]; then
PYTEST_ARGS="${PYTEST_ARGS} --exitfirst"
fi
if [ "${COVERAGE}" -eq 1 ]; then
PYTEST_ARGS="${PYTEST_ARGS} --cov=./"
fi
if [ "${COVERAGE_APPEND}" -eq 1 ]; then
PYTEST_ARGS="${PYTEST_ARGS} --cov-append"
fi
if [ "${LOGCLI}" -eq 1 ]; then
PYTEST_ARGS="-o log_cli=true ${PYTEST_ARGS}"
fi
if [ "${ORDEROUTPUT}" -eq 1 ]; then
mpirun -n ${NPROCS} --oversubscribe --output-filename outtest pytest ${PYTEST_ARGS} --only-mpi >/dev/null
exit_code=$?
for ((RANK=0; RANK<${NPROCS}; RANK++)); do
RANKFILE="outtest/1/rank.${RANK}/stdout"
echo ""
echo "################################################################################"
echo "################################# RANK ${RANK} / ${NPROCS} ###################################"
echo "################################################################################"
cat ${RANKFILE}
done
rm -r outtest
elif [ "${UNMUTE}" -eq -1 ]; then
mpirun -n ${NPROCS} --oversubscribe pytest ${PYTEST_ARGS} --only-mpi
exit_code=$?
else
mpirun -n ${NPROCS} --oversubscribe utils/mute_all_ranks_except.sh ${UNMUTE} pytest ${PYTEST_ARGS} --only-mpi
exit_code=$?
fi
fi
exit "$exit_code"