forked from bondhugula/pluto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathploog
executable file
·74 lines (57 loc) · 2.02 KB
/
ploog
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
#!/bin/bash
#
# ploog - inserts OpenMP pragmas into CLooG code (where to insert, what
# to insert comes from the pluto core through the .pragmas file
#
# Copyright (C) 2007-2008 Uday Bondhugula
# Available under GNU GPL version 3 or (at your option) any later version
#
if [ $# -ne 2 ]; then
echo "Usage: ./ploog <src file> [all loops = 0 | first loop = 1] "
# third arg: 0 - all loops, 1 - first loop
exit 1
fi
if [ ! -f $1 ]; then
echo "ploog: Input file $1 does not exist"
exit 2
fi
if [ ! -f .pragmas ]; then
echo "[ploog] WARNING: no parallel loops"
exit 0
fi
NUMLINES=`wc -l $1 | awk '{print $1}'`
dirname=`dirname $1`
npar=`wc -l .pragmas | awk '{print $1}'`
PARDIMS=`cat .pragmas | awk '{print $1}'`
i=1
for DIM in $PARDIMS; do
# sometimes the scattering dimension may not appear
grep -q $DIM $1
if [ $? -ne 0 ]; then
break
fi
# Mark all loops of this scattering dimension parallel
# The pragma from .pragmas (generated from Pluto) that corresponds to this loop
grep "$DIM #pragma" .pragmas > .pragma
if [ "$2" == 0 ]; then
LINE_NUMBERS=`grep -n "for ($DIM=" $1 | awk '{split($1,t,":"); print t[1]}'`
else
LINE_NUMBERS=`grep -n "for ($DIM=" $1 | awk '{split($1,t,":"); print t[1]}' | head -n 1`
fi
j=0
for num in $LINE_NUMBERS; do
LOOP=`sed -n -e ''$(($num+3*$j))'p' $1`
sed -n -e '1,'$(($num+3*$j-1))'p' $1 > .header
sed -n -e ''$(($num+3*$j+1))',$p' $1 > .footer
sed -n -e ''$(($num+3*$j))'p' $1 > .parloop
# lower and upper bounds
echo -e "\tlb$i="`awk '{split($2,t,";"); split(t[1],u,"="); print u[2] }' .parloop`";" > .lb
echo -e "\tub$i="`awk '{split($2,t,";"); split(t[2],u,"="); print u[2] }' .parloop`";" > .ub
cat .header .lb .ub .pragma | sed -e "s/$DIM #pragma/#pragma/" > $1
echo -e "\tfor ($DIM=lb$i; $DIM<=ub$i; $DIM++) {" >> $1
cat .footer >> $1
j=$((j+1))
done
i=$((i+1))
done
rm -f .header .footer .ub .lb .parloop .pragma