-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuggest-easyconfigs
executable file
·158 lines (147 loc) · 5.33 KB
/
suggest-easyconfigs
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#! /bin/bash
# Time-stamp: <Tue 2022-04-05 09:26 svarrette>
################################################################################
# suggest-easyconfigs - Suggest an easyconfig for [past] software or pattern
################################################################################
# cosmetics
BOLD="\033[1m"
COLOR_RESET="\033[0m"
# Local variables
TOP_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && git rev-parse --show-toplevel)"
CMD_PREFIX=
MODE=
SUMMARY_MODE=
TOOLCHAIN_VERSION=${RESIF_VERSION_DEVEL:=2020b}
GCC_VERSION=10.2.0
# Software lists
MODULES_AVAILABLE=
SW_AS_MODULE=
SW_NOT_AS_MODULE=
################################################################################
info() { echo -e "${BOLD}$*${COLOR_RESET}"; }
error() { echo -e "${BOLD}*** ERROR *** $*${COLOR_RESET}"; }
print_error_and_exit() { error $*; exit 1; }
usage() {
cat <<EOF
NAME
$(basename $0): Suggest a easyconfig(s) for a given software sets or pattern
passed as argument
Default toolchain/software set version: ${TOOLCHAIN_VERSION}
USAGE
$0 [-v <version] <pattern> # search for <pattern>
OPTIONS
-n --dry-run: Dry run mode
-m --module-list: List modules available
-v VERSION: Force search against toolchain version VERSION
EOF
}
###
# filter/classify list of software from those [module] available and the others
##
filter_software_list() {
[ -z "$1" ] && print_error_and_exit "[$FUNCNAME] missing software list argument"
local list="$*"
local filtered_list=""
# Pre-check: Lmod / Environment Module exists
command -v module >/dev/null || print_error_and_exit "'module' command Not Found"
[ -z "${MODULES_AVAILABLE}" ] && set_module_list
for sw in ${list}; do
module_present="$(echo ${MODULES_AVAILABLE} | grep ${sw})"
[ -n "${module_present}" ] && \
SW_AS_MODULE="${SW_AS_MODULE} $sw" || \
SW_NOT_AS_MODULE="${SW_NOT_AS_MODULE} $sw"
done
total_software=$(echo $list | wc -w)
avail_software=$(echo $SW_AS_MODULE | wc -w)
ratio=$(echo "${avail_software}*100/${total_software}" | bc -l)
printf "%s/%s = %.2f%% software available as modules\n" $avail_software $total_software $ratio
}
set_module_list() {
MODULES_AVAILABLE=$(module -t --redirect avail | tail -n +2 | cut -d '/' -f 2 | sort | uniq )
}
###
# Print a software list (passed as string) in formatted columns
##
print_software_list() {
[ -z "$1" ] && print_error_and_exit "[$FUNCNAME] missing software list argument"
local list="$*"
local i=0
for sw in ${list}; do
printf "%18s" $sw
i=$(( i + 1 ))
[ $(( i % 5 )) == 0 ] && printf "\n"
done
printf "\n"
info "Total: $(echo ${list} | wc -w) entries"
}
###
# print module list
##
print_module_list() {
info "=> List of software available as modules"
[ -z "${MODULES_AVAILABLE}" ] && set_module_list
print_software_list ${MODULES_AVAILABLE}
}
###
# Search for Easyconfigs matching pattern
# Usage: search_easyconfigs <pattern>
##
search_easyconfigs() {
[ -z "$1" ] && print_error_and_exit "[$FUNCNAME] missing pattern argument"
local pattern=$1
eb -S ${pattern} 2>/dev/null | grep '.eb$' | sed 's/.*\///' | grep "^${pattern}" | sort -V | uniq
}
search_easyconfigs_for_toolchain() {
[ -z "$1" ] && print_error_and_exit "[$FUNCNAME] missing pattern argument"
local pattern=$1
found=$(search_easyconfigs ${pattern} | egrep "${TOOLCHAIN_VERSION}|${GCC_VERSION}")
# TODO: filter also on cuda pattern for GPU search
[ -z "${found}" ] && echo "None found" || echo $found | tr ' ' '\n'
}
suggest_easyconfig() {
[ -z "$1" ] && print_error_and_exit "[$FUNCNAME] missing pattern argument"
local pattern=$1
exact_match=$(search_easyconfigs_for_toolchain ${pattern})
if [[ "${exact_match}" != *'None'* ]]; then
echo $exact_match | tr ' ' '\n' | tail -n 1
else
echo "$(search_easyconfigs ${pattern})" | tr ' ' '\n' | tail -n 1
fi
}
################################################################################
# Check for options
while [ $# -ge 1 ]; do
case $1 in
-h | --help) usage; exit 0;;
-n | --noop | --dry-run) CMD_PREFIX=echo;;
-m | --module-list) print_module_list; exit 0;;
-s | --summary) SUMMARY_MODE=$1;;
-v | --version) shift; TOOLCHAIN_VERSION=$1;;
*) PATTERN_LIST="$*"; break;;
esac
shift
done
command -v eb >/dev/null || print_error_and_exit "'eb' command Not Found -- source settings ?"
case $TOOLCHAIN_VERSION in
2019a) GCC_VERSION=8.2.0;;
2019b) GCC_VERSION=8.3.0;;
2020a) GCC_VERSION=9.3.0;;
2020b) GCC_VERSION=10.2.0;;
2021a) GCC_VERSION=10.3.0;;
2021b) GCC_VERSION=11.2.0;;
*) print_error_and_exit "Not supported toolchain version '${TOOLCHAIN_VERSION}'"
esac
# echo "PATTERN_LIST=${PATTERN_LIST}"
for pattern in $(echo ${PATTERN_LIST} | xargs echo); do
if [ -n "${SUMMARY_MODE}" ]; then
printf "%18s: %s\n" ${pattern} $(suggest_easyconfig ${pattern})
continue
fi
info "=> Searching Easyconfigs matching pattern '${pattern}'"
easyconfigs=$(search_easyconfigs ${pattern})
echo $easyconfigs | tr ' ' '\n'
info "Total: $(echo $easyconfigs | wc -w) entries\n"
info "... potential exact match for ${TOOLCHAIN_VERSION} toolchain"
search_easyconfigs_for_toolchain ${pattern}
info " --> suggesting '$(suggest_easyconfig ${pattern})'"
done