-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_monte_carlo.sh
executable file
·46 lines (36 loc) · 962 Bytes
/
run_monte_carlo.sh
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
# !/usr/bin/bash
A=0
B=1
MAX=0
MIN=1
RUNS=100
TRUE_RES=0.33333
N_WORKERS=4
#(wget -O - pi.dk/3 || curl pi.dk/3/ || fetch -o - http://pi.dk/3) | bash
#sudo cp bin/* /usr/bin
function lead_zero {
echo $1 | sed -e 's/^\./0./' -e 's/^-\./-0./'
}
DIFF=`bc <<< "scale=10; ($B - $A)/$N_WORKERS"`
touch .tmp
truncate -s 0 .tmp
for i in `seq $N_WORKERS`; do
L=`bc <<< "$A + ($i-1) * $DIFF"`
U=`bc <<< "$A + $i * $DIFF"`
echo -e "$L $U $MAX $MIN $RUNS" >> .tmp
done
if [ -z "$1" ]
then
RES=`parallel --no-notice -a .tmp --colsep ' ' ./cacl_monte_carlo.sh {}`
else
scp cacl_monte_carlo.sh $1:~/
RES=`parallel --no-notice -S $1 -a .tmp --colsep ' ' ./cacl_monte_carlo.sh {}`
fi
RES=`echo $RES | tr ' ' '\n' | awk '{s+=$1} END {print s}'`
RES=`bc <<< "scale=10; $RES/$N_WORKERS"`
RES=`lead_zero $RES`
echo "Result :" $RES
echo "True result :" $TRUE_RES
ERR=$(lead_zero `bc <<< "$RES-$TRUE_RES" | sed "s/^-//"`)
echo "Error :" $ERR
rm .tmp