1#!/usr/local/bin/bash
2#
3#   get_results
4#   ==============================================
5#       Extract the best combinations from all the
6#          directories.
7#
8#    @author: Ruyman Reyes (rreyesc@epcc.ed.ac.uk)
9#
10source config.in
11
12# Number of combinations with the existing options
13Ncomb=$(( 2**$Nopt ))
14
15# Error tolerance
16err_tol="1.0E-10"
17
18# For both collocate (0) and integrate (1)
19for icollo in 0 1; do
20echo "$icollo"
21echo "l - Time - Best Opt"
22echo "l Time Opt" > best_timings
23 for l in `seq 0 $lmax`; do
24 bsf=999999.0
25# First optimisation starts at ONE (all_options[0] is not initialised and generate does not produces valid code)
26  for iopt in `seq 1 $Ncomb`;do
27   # Extract the error
28   tmp=$(cat out_${l}_${iopt}/out_test_${l}_${iopt}_F_${icollo} | tr -s ' ' | grep "largest error" | cut -f 5 -d ' ')
29   test "$tmp" || continue
30   error=$(python -c "print $err_tol>$tmp")
31   # Skip if error is too big
32   if [[ $error == "False" ]]; then
33  #   echo "($error) Error $tmp was too big for $iopt"
34      continue
35   fi
36   # echo "($error) Error was $tmp , accepted $iopt"
37   # Extract the time of the combination
38   tmp=$(cat out_${l}_${iopt}/out_test_${l}_${iopt}_T_${icollo} | tr -s ' ' | grep "best time" | cut -f 5 -d ' ')
39
40   test "$tmp" || continue
41   dif=$(python -c "print $bsf>$tmp")
42
43   if [[ $dif == "True" ]]; then
44     # echo " New bsf is $tmp from $bsf "
45      bsf=$tmp
46      bsf_iopt=$iopt
47   #else
48     # echo " $bsf is lower than $tmp ($dif, print $bsf>$tmp)"
49   fi
50  done # for iopt
51
52   bsf_global[$l]=$bsf
53   bsf_iopt_global[$l]=$bsf_iopt
54
55   echo $l -- ${bsf_global[$l]} -- ${bsf_iopt_global[$l]}
56   echo $l ${bsf_global[$l]} ${bsf_iopt_global[$l]} >> best_timings
57
58 done # for l
59
60if [[ $icollo -eq 0 ]]; then
61   bsf_global_0=("${bsf_global[@]}")
62   bsf_iopt_global_0=("${bsf_iopt_global[@]}")
63else
64   bsf_global_1=("${bsf_global[@]}")
65   bsf_iopt_global_1=("${bsf_iopt_global[@]}")
66fi
67
68done # for icollo
69
70# Generate the input file for generate.x with the optimal combinations for each problem size
71echo " Generating optimal combination "
72(
73   echo $lmax
74    for l in `seq 0 $lmax`; do
75       echo ${bsf_iopt_global_0[$l]}
76    done
77    echo $lmax
78    for l in `seq 0 $lmax`; do
79       echo ${bsf_iopt_global_1[$l]}
80    done
81) > generate_best
82
83