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

Private GIT Repository
Add VARIANTS to ag_parameters. Create ag_parameters1024 for big platforms.
[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 -x "$LOBA" || die "command not found: \"$LOBA\""
78
79 log "Results put in: \"$RESULTS\"."
80
81 [ $debug = 1 ] && log "Running in dry-run mode"
82
83 outfile() {
84     echo "$*" | sed 's,[^ ]*/,,g;s/\.xml//;y/ /_/'
85 }
86
87 summary() {
88     gzip -cdf "$@" \
89     | sed -n '\!^\[main/INFO\] ,----\[ Results \]!,${
90         /send\|recv\|wall clock\|Simulation succeeded/d;p;
91       }'
92 }
93
94 if [ $compress = 1 ]; then
95     outsuffix=".gz"
96 else
97     outsuffix=""
98 fi
99
100 for plat in "${PLATFORMS[@]}"; do
101     tmp=$(basename "$plat" ".xml")
102     plat_output="$RESULTS/plat_$tmp"
103     for topo in "${TOPOLOGIES[@]}"; do
104         topo_output="$plat_output/topo_$topo"
105         [ $debug = 0 ] && mkdir -p "$topo_output"
106         for algo in "${ALGORITHMS[@]}"; do
107             algo_output="$topo_output/algo_$algo"
108             args=(
109                 -T"$topo"
110                 -a"$algo"
111                 -N"$NHOSTS"
112                 -L"$LOAD"
113                 -t"$DEADLINE"
114                 "$plat"
115             )
116             for variant in "${VARIANTS[@]}"; do
117                 cmd=( "$LOBA" "${COMMON_OPTS[@]}" )
118                 case "$variant" in
119                     "plain") : ;;
120                     "bookkeeping") cmd+=( "-b" ) ;;
121                     *) die "unknown variant: \"$variant\"" ;;
122                 esac
123                 out="${algo_output}_${variant}.out"
124                 outf="$out$outsuffix"
125                 cmd+=( "${args[@]}" )
126                 log "Run: ${cmd[@]}"$'\n'"... &> $outf"
127                 if [ $overwrite = 0 -a -e "$outf" ]; then
128                     log "already run !"
129                     summary "$outf"
130                     continue
131                 fi
132                 if [ $debug = 1 ]; then
133                     log "skipped (dry-run)"
134                     continue
135                 fi
136                 rm -f "$outf";
137                 echo "# ${cmd[@]}" > "$out"
138                 if "${cmd[@]}" >> "$out" 2>&1; then
139                     summary "$out"
140                 else
141                     grep -v '/INFO\]' "$out"
142                 fi
143                 if [ $compress = 1 ]; then
144                     log "Compress output file."
145                     gzip --best "$out"
146                 fi
147             done
148         done
149     done
150 done