Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3d735c8

Browse files
committedMar 13, 2023
#3060: add jasmin-env again
1 parent 80f7d48 commit 3d735c8

File tree

1 file changed

+55
-0
lines changed
  • esmvaltool/utils/recipe_test_workflow/recipe_test_workflow/site

1 file changed

+55
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash -l
2+
#
3+
# Usage metoffice-env COMMAND
4+
#
5+
# ENVIRONMENT
6+
# MODULE_NAME The name of the module to load
7+
# PYTHONPATH_PREPEND The path to prepend to PYTHONPATH after loading the
8+
# module
9+
# QUIET_MODE Don't print confirmation messages
10+
#
11+
# OPTIONS
12+
# COMMAND The command to execute with options
13+
set -eu
14+
15+
module_count(){
16+
module list -t 2>&1 | wc -l
17+
}
18+
19+
safe_load(){
20+
PRE_LOAD_COUNT=$(module_count)
21+
22+
module load "${1}"
23+
# Check module count to determine whether module load was successful.
24+
if (( PRE_LOAD_COUNT == $(module_count) )); then
25+
echo "[ERROR] Failed to load: ${1}"
26+
exit 1
27+
fi
28+
}
29+
30+
# Must be run before importing numpy, see
31+
# https://www-avd/sci/dask_best_practice/numpy-threads.html.
32+
export OMP_NUM_THREADS=1
33+
export OPENBLAS_NUM_THREADS=1
34+
export MKL_NUM_THREADS=1
35+
export VECLIB_MAXIMUM_THREADS=1
36+
export NUMEXPR_NUM_THREADS=1
37+
38+
# Ensure '~/.local' isn't added to 'sys.path'.
39+
export PYTHONNOUSERSITE=True
40+
41+
safe_load "${MODULE_NAME}"
42+
43+
# If PYTHONPATH_PREPEND has been set, prepend it to PYTHONPATH to extend the
44+
# Python environment.
45+
if [[ ! -z ${PYTHONPATH_PREPEND:-} ]]; then
46+
echo "[INFO] Prepending the following to PYTHONPATH: ${PYTHONPATH_PREPEND}"
47+
export PYTHONPATH=${PYTHONPATH_PREPEND}:${PYTHONPATH:-}
48+
fi
49+
50+
if [[ -z ${QUIET_MODE:-} ]]; then
51+
echo "[OK] Modules loaded."
52+
fi
53+
54+
command="/usr/bin/time -v -o ${CYLC_TASK_LOG_ROOT}.time $@"
55+
exec ${command}

0 commit comments

Comments
 (0)
Please sign in to comment.