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

Private GIT Repository
Cosmetics.
[loba.git] / Experimentations / run-all2
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 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 : ${RESULTS:=$PWD/results}
70 : ${LOBA:=$PWD/loba}
71
72 COMMON_OPTS=(
73     --cfg=contexts/factory:raw
74     "${MORE_ARGS[@]}"
75 )
76
77 log "Results put in: \"$RESULTS\"."
78
79 [ $debug = 1 ] && log "Running in dry-run mode"
80
81 outfile() {
82     echo "$*" | sed 's,[^ ]*/,,g;s/\.xml//;y/ /_/'
83 }
84
85 summary() {
86     gzip -cdf "$@" \
87                                 | sed -n '\!^\[main/INFO\] ,----\[ Results \]!,${
88         /send\|recv\|wall clock\|Simulation succeeded/d;p;
89       }'
90 }
91
92 if [ $compress = 1 ]; then
93     outsuffix=".gz"
94 else
95     outsuffix=""
96 fi
97
98 for plat in "${PLATFORMS[@]}"; do
99     tmp=$(basename "$plat" ".xml")
100     plat_output="$RESULTS/plat_$tmp"
101     for topo in "${TOPOLOGIES[@]}"; do
102         topo_output="$plat_output/topo_$topo"
103         [ $debug = 0 ] && mkdir -p "$topo_output"
104  #       for lr in "1" "N"; do
105  #           case "$lr" in
106  #               "1") loadinit=( ) ;;
107  #               "N") loadinit=( "-R" "-r42" ) ;;
108  #               *) die "internal error (lr = \"$lr\")" ;;
109  #           esac
110                                                 for mode in "R" "Z"; do
111                                                                 case "$mode" in
112                                                                                 "R") computemode=( );;
113                                                                                 "Z") computemode=( "-Z" );;
114                                                                                 *) die "internal error (mode = \"$mode\")" ;;
115                                                                 esac
116                                                                 for algo in "${ALGORITHMS[@]}"; do
117                                                                                 algo_output="$topo_output/algo_$algo"
118                                                                                 args=(
119                                                                                                 -T"$topo"
120                                                                                                 -a"$algo"
121                                                                                                 -N"$NHOSTS"
122                                                                                                 -L"$LOAD"
123                                                                                                 -t"$DEADLINE"
124 #                                                                                               "${loadinit[@]}"
125                                                                                                 "${computemode[@]}"
126                                                                                                 "$plat"
127                                                                                 )
128
129                                                                                 for bk in "plain" "bookkeeping"; do
130                                                                                                 cmd=( "$LOBA" "${COMMON_OPTS[@]}" )
131                                                                                                 case "$bk" in
132                                                                                                                 "plain") : ;;
133                                                                                                                 "bookkeeping") cmd+=( "-b" ) ;;
134                                                                                                                 *) die "internal error (bk = \"$bk\")" ;;
135                                                                                                 esac
136                                                                                                 out="${algo_output}_${bk}_${mode}.out"
137                                                                                                 outf="$out$outsuffix"
138                                                                                                 cmd+=( "${args[@]}" )
139                                                                                                 log "Run: ${cmd[@]}"$'\n'"... &> $outf"
140                                                                                                 if [ $overwrite = 0 -a -e "$outf" ]; then
141                                                                                                                 log "already run !"
142                                                                                                                 summary "$outf"
143                                                                                                                 continue
144                                                                                                 fi
145                                                                                                 if [ $debug = 1 ]; then
146                                                                                                                 log "skipped (dry-run)"
147                                                                                                                 continue
148                                                                                                 fi
149                                                                                                 rm -f "$outf";
150                                                                                                 echo "# ${cmd[@]}" > "$out"
151                                                                                                 if "${cmd[@]}" >> "$out" 2>&1; then
152                                                                                                                 summary "$out"
153                                                                                                 else
154                                                                                                                 grep -v '/INFO\]' "$out"
155                                                                                                 fi
156                                                                                                 if [ $compress = 1 ]; then
157                                                                                                                 log "Compress output file."
158                                                                                                                 gzip --best "$out"
159                                                                                                 fi
160                                                                                 done
161 #                                                               done
162             done
163         done
164     done
165 done