]> AND Private Git Repository - loba.git/blob - Experimentations/run-all
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
638c0a5997ba9f7d7d530087351fc4477a011c0b
[loba.git] / Experimentations / run-all
1 #!/bin/bash
2
3 set -e
4 #set -x
5
6 usage() {
7     cat >&2 <<EOF
8 Usage: $0 [OPTION] <parameters file>
9 Options:
10     -h  print this help
11     -n  dry-run mode (for debugging)
12     -c  (continue) do not overwrite previous results
13 EOF
14     exit $1
15 }
16
17 log() {
18     echo "-#- $@" >&2
19 }
20
21 die() {
22     echo "ERROR: $@" >&2
23     exit 2
24 }
25
26 variable_check() {
27     eval test -n "\${$1}" || die "undefined $1"
28 }
29
30 array_check() {
31     eval test "\${#$1}" -gt 0 || die "undefined $1"
32 }
33
34 # read args
35 overwrite=1
36 debug=0
37 while getopts "chn" c; do
38     case "$c" in
39         'c') overwrite=0 ;;
40         'h') usage 0 ;;
41         'n') debug=1 ;;
42         '?') usage 1 ;;
43     esac
44 done
45 shift $((OPTIND - 1))
46 [ $# -eq 1 ] || usage 1
47 parameters="$1"
48
49 log "Running: $0 $@"
50 log "Hostname: $(hostname -f)"
51
52 declare -a TOPOLOGIES ALGORITHMS PLATFORMS COMMON_OPTS MORE_ARGS
53
54 # read parameters
55 log "Reading parameters from \"$1\"."
56 source "$parameters" || die "cannot read parameters file: \"$parameters\""
57
58 array_check TOPOLOGIES
59 array_check ALGORITHMS
60 array_check PLATFORMS
61 variable_check NHOSTS
62 variable_check LOAD
63 variable_check DEADLINE
64
65 # default values
66 : ${RESULTS:=$PWD/results}
67 : ${LOBA:=$PWD/loba}
68
69 COMMON_OPTS=(
70     --cfg=contexts/factory:raw
71     "${MORE_ARGS[@]}"
72 )
73
74 log "Results put in: \"$RESULTS\"."
75
76 [ $debug = 1 ] && log "Running in dry-run mode"
77
78 outfile() {
79     echo "$*" | sed 's,[^ ]*/,,g;s/\.xml//;y/ /_/'
80 }
81
82 summary() {
83     sed -n '\!^\[main/INFO\] ,----\[ Results \]!,${
84       /send\|recv\|wall clock\|Simulation succeeded/d;p;
85     }' "$1"
86 }
87
88 for plat in "${PLATFORMS[@]}"; do
89     tmp=$(basename "$plat" ".xml")
90     plat_output="$RESULTS/plat_$tmp"
91     for topo in "${TOPOLOGIES[@]}"; do
92         topo_output="$plat_output/topo_$topo"
93         for algo in "${ALGORITHMS[@]}"; do
94             algo_output="$topo_output/algo_$algo"
95             [ $debug = 0 ] && mkdir -p "$algo_output"
96             args=(
97                 -T"$topo"
98                 -a"$algo"
99                 -N"$NHOSTS"
100                 -L"$LOAD"
101                 -t"$DEADLINE"
102                 "$plat"
103             )
104             for bk in "" "-b"; do
105                 tmp=$(outfile "loba" $bk "${args[@]}")
106                 out="$algo_output/$tmp.out"
107                 cmd=( "$LOBA" "${COMMON_OPTS[@]}" $bk "${args[@]}" )
108                 log "Run: ${cmd[@]}"$'\n'"... &> $out"
109                 if [ $overwrite = 0 -a -e "$out" ]; then
110                     log "already run !"
111                     summary "$out"
112                     continue
113                 fi
114                 if [ $debug = 1 ]; then
115                     log "skipped (dry-run)"
116                 else
117                     echo "# ${cmd[@]}" > "$out"
118                     if "${cmd[@]}" >> "$out" 2>&1; then
119                         summary "$out"
120                     else
121                         grep -v '/INFO\]' "$out"
122                     fi
123                 fi
124             done
125         done
126     done
127 done