-
Notifications
You must be signed in to change notification settings - Fork 0
/
poptbench
executable file
·163 lines (141 loc) · 3.76 KB
/
poptbench
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#
# script to benchmark COPASI's parallel optimization
# make sure that the .cps files passed on to this script are set
# executable for parameter estimation or optimization and that the
# correct optimization algorithm is selected
# PARAMETERS (edit as needed)
# the executable with serial algorithm
OPTSER=/usr/bin/CopasiSE
# the executable with parallel algorithm
OPTPAR=/usr/local/COPASI-DEVEL/bin/CopasiSE
# CopasiSE options
CLOPT="--nologo"
# default number of iterations
RUNITER=20
# default number of threads
THREADS=4
#DON'T EDIT BELOW THIS LINE
# check command line options
if [[ $# -ge 1 ]]; then
INFILE=$1
if [[ "$1" =~ ^-h$ ]]; then
printf "usage: poptbench infile [iterations [threads [serial|parallel]]]\n"
exit 0
fi
else
printf "usage: poptbench infile [iterations [threads [serial|parallel]]]\n"
exit 1
fi
if [[ $# -ge 2 ]]; then
if [[ "$2" =~ ^[0-9]+$ ]]; then
RUNITER=$2
else
printf "usage: poptbench infile [iterations [threads [serial|parallel]]]\n"
printf "error: iterations must be an integer"
exit 1
fi
fi
if [[ $# -ge 3 ]]; then
if [[ "$3" =~ ^[0-9]+$ ]]; then
THREADS=$3
else
printf "usage: poptbench infile [iterations [threads [serial|parallel]]]\n"
printf "error: threads must be an integer\n"
exit 1
fi
fi
if [ $# -ge 4 ]; then
SERIAL=0
PARALLEL=0
if [[ "$4" == "serial" ]]; then
SERIAL=1
else
if [[ "$4" == "parallel" ]]; then
PARALLEL=1
else
printf "usage: poptbench infile [iterations [threads [serial|parallel]]]\n"
printf '%s\n' "error: option '$4' not allowed"
exit 1
fi
fi
else
SERIAL=1
PARALLEL=1
fi
# OMP directives,number of threads to be used, etc
export OMP_THREAD_LIMIT=$THREADS
export OMP_NUM_THREADS=$OMP_THREAD_LIMIT
export OMP_SCHEDULE=guided
#find the name of the outfile in the parameter estimation report
line=$(grep -A 1 "name=\"Parameter Estimation" $INFILE)
# Check if "target=" is present in the result
if [[ $line == *"target="* ]]; then
OUTFILE=$(echo $line | sed 's/.*target="\([^"]*\)".*/\1/')
fi
#check if variable is empty
if [[ -z "$OUTFILE" ]]; then
#maybe it's in the optimization report?
line=$(grep -A 1 "name=\"Optimization" $INFILE)
# Check if "target=" is present in the result
if [[ $line == *"target="* ]]; then
OUTFILE=$(echo $line | sed 's/.*target="\([^"]*\)".*/\1/')
fi
if [[ -z "$OUTFILE" ]]; then
printf "No output file specified, aborting.\n"
exit 1
else
TASK="Optimization"
fi
else
TASK="Parameter Estimation"
fi
printf "started on "
date
printf '%s\n' "$TASK writing output to $OUTFILE"
# keep a backup of OUTFILE if it exists
if [[ -e $OUTFILE ]]; then
mv $OUTFILE $OUTFILE.bak
fi
#write a header
date >> $OUTFILE
echo "$0 $@" >> $OUTFILE
grep -m 1 "model name" /proc/cpuinfo >> $OUTFILE
grep -m 1 "bogomips" /proc/cpuinfo >> $OUTFILE
grep -m 1 "cpu cores" /proc/cpuinfo >> $OUTFILE
printf 'threads used\t: %s\n' "$OMP_THREAD_LIMIT" >> $OUTFILE
printf "\n" >> $OUTFILE
# run the serial version
if [[ $SERIAL == 1 ]]; then
printf '%s' "running serial PS $RUNITER times "
printf "SERIAL\n" >> $OUTFILE
for ((i=1;i<=$RUNITER;i++));
do
$OPTSER $CLOPT $INFILE 2>&1 > /dev/null
if [ $((i % 10)) -eq 0 ]; then
printf "|"
else
printf "."
fi
done
# add empty line to report file
echo >> $OUTFILE
# and to the console
echo
fi
# run the parallel version (the "!" is used to make sure script doesn't abort)
if [[ $PARALLEL == 1 ]]; then
printf '%s' "running parallel PS $RUNITER times "
printf 'PARALLEL %d THREADS\n' $THREADS >> $OUTFILE
for ((i=1;i<=$RUNITER;i++));
do
! $OPTPAR $CLOPT $INFILE 2>&1 > /dev/null
if [ $((i % 10)) -eq 0 ]; then
printf "|"
else
printf "."
fi
done
fi
printf "\nfinished on "
date