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

Private GIT Repository
Handle timeout exception in condition_t::timedwait().
[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     -z  compress output files with gzip
14 EOF
15     exit $1
16 }
17
18 log() {
19     echo "-#- $@" >&2
20 }
21
22 die() {
23     echo "ERROR: $@" >&2
24     exit 2
25 }
26
27 variable_check() {
28     eval test -n "\${$1}" || die "undefined $1"
29 }
30
31 array_check() {
32     eval test "\${#$1}" -gt 0 || die "undefined $1"
33 }
34
35 # read args
36 overwrite=1
37 debug=0
38 compress=0
39 while getopts "chnz" c; do
40     case "$c" in
41         'c') overwrite=0 ;;
42         'h') usage 0 ;;
43         'n') debug=1 ;;
44         'z') compress=1 ;;
45         '?') usage 1 ;;
46     esac
47 done
48 shift $((OPTIND - 1))
49 [ $# -eq 1 ] || usage 1
50 parameters="$1"
51
52 log "Running: $0 $@"
53 log "Hostname: $(hostname -f)"
54
55 declare -a TOPOLOGIES ALGORITHMS PLATFORMS VARIANTS COMMON_OPTS MORE_ARGS
56
57 # read parameters
58 log "Reading parameters from \"$1\"."
59 source "$parameters" || die "cannot read parameters file: \"$parameters\""
60
61 array_check TOPOLOGIES
62 array_check ALGORITHMS
63 array_check PLATFORMS
64 variable_check NHOSTS
65 variable_check LOAD
66 variable_check DEADLINE
67
68 # default values
69 test -n "$VARIANTS" || VARIANTS=( "plain" "bookkeeping" )
70 test -n "$RESULTS"  || RESULTS="$PWD/results"
71 test -n "$LOBA"     || LOBA="$PWD/loba"
72
73 COMMON_OPTS=(
74     "${MORE_ARGS[@]}"
75 )
76
77 test -f "$LOBA" && test -x "$LOBA" || die "command not found: \"$LOBA\""
78 for plat in "${PLATFORMS[@]}"; do
79     test -f "$plat" && test -r "$plat" || die "file not found: \"$plat\""
80 done
81
82 log "Results put in: \"$RESULTS\"."
83
84 [ $debug = 1 ] && log "Running in dry-run mode"
85
86 outfile() {
87     echo "$*" | sed 's,[^ ]*/,,g;s/\.xml//;y/ /_/'
88 }
89
90 summary() {
91     gzip -cdf "$@" \
92     | sed -n '\!^\[main/INFO\] ,----\[ Results \]!,${
93         /send\|recv\|wall clock\|Simulation succeeded/d;p;
94       }'
95 }
96
97 if [ $compress = 1 ]; then
98     outsuffix=".gz"
99 else
100     outsuffix=""
101 fi
102
103 for plat in "${PLATFORMS[@]}"; do
104     tmp=$(basename "$plat" ".xml")
105     plat_output="$RESULTS/plat_$tmp"
106     for topo in "${TOPOLOGIES[@]}"; do
107         topo_output="$plat_output/topo_$topo"
108         [ $debug = 0 ] && mkdir -p "$topo_output"
109         for algo in "${ALGORITHMS[@]}"; do
110             algo_output="$topo_output/algo_$algo"
111             args=(
112                 -T"$topo"
113                 -a"$algo"
114                 -N"$NHOSTS"
115                 -L"$LOAD"
116                 -t"$DEADLINE"
117                 "$plat"
118             )
119             for variant in "${VARIANTS[@]}"; do
120                 cmd=( "$LOBA" "${COMMON_OPTS[@]}" )
121                 case "$variant" in
122                     "plain") : ;;
123                     "bookkeeping") cmd+=( "-b" ) ;;
124                     *) die "unknown variant: \"$variant\"" ;;
125                 esac
126                 out="${algo_output}_${variant}.out"
127                 outf="$out$outsuffix"
128                 cmd+=( "${args[@]}" )
129                 log "Run: ${cmd[@]}"$'\n'"... &> $outf"
130                 if [ $overwrite = 0 -a -e "$outf" ]; then
131                     log "already run !"
132                     summary "$outf"
133                     continue
134                 fi
135                 if [ $debug = 1 ]; then
136                     log "skipped (dry-run)"
137                     continue
138                 fi
139                 rm -f "$outf";
140                 echo "# ${cmd[@]}" > "$out"
141                 if "${cmd[@]}" >> "$out" 2>&1; then
142                     summary "$out"
143                 else
144                     grep -v '/INFO\]' "$out"
145                 fi
146                 if [ $compress = 1 ]; then
147                     log "Compress output file."
148                     gzip --best "$out"
149                 fi
150             done
151         done
152     done
153 done