3 # ploog - inserts OpenMP pragmas into CLooG code (where to insert, what
4 # to insert comes from the pluto core through the .pragmas file
6 # Copyright (C) 2007-2008 Uday Bondhugula
8 # Available under GNU GPL version 3 or (at your option) any later version
12 echo "Usage: ./ploog <src file> [all loops = 0 | first loop = 1] "
13 # third arg: 0 - all loops, 1 - first loop
18 echo "ploog: Input file $1 does not exist"
22 if [ ! -f .pragmas
]; then
23 echo "[ploog] WARNING: no parallel loops"
27 NUMLINES
=`wc -l $1 | awk '{print $1}'`
29 npar
=`wc -l .pragmas | awk '{print $1}'`
30 PARDIMS
=`cat .pragmas | awk '{print $1}'`
34 for DIM
in $PARDIMS; do
35 # sometimes the scattering dimension may not appear
42 # Mark all loops of this scattering dimension parallel
44 # The pragma from .pragmas (generated from Pluto) that corresponds to this loop
45 grep "$DIM #pragma" .pragmas
> .pragma
47 if [ "$2" == 0 ]; then
48 LINE_NUMBERS
=`grep -n "for ($DIM=" $1 | awk '{split($1,t,":"); print t[1]}'`
50 LINE_NUMBERS
=`grep -n "for ($DIM=" $1 | awk '{split($1,t,":"); print t[1]}' | head -n 1`
55 for num
in $LINE_NUMBERS; do
56 LOOP
=`sed -n -e ''$(($num+3*$j))'p' $1`
57 sed -n -e '1,'$
(($num+3*$j-1))'p' $1 > .header
58 sed -n -e ''$
(($num+3*$j+1))',$p' $1 > .footer
60 sed -n -e ''$
(($num+3*$j))'p' $1 > .parloop
62 # lower and upper bounds
63 echo -e "\tlb$i="`awk '{split($2,t,";"); split(t[1],u,"="); print u[2] }' .parloop`";" > .lb
64 echo -e "\tub$i="`awk '{split($2,t,";"); split(t[2],u,"="); print u[2] }' .parloop`";" > .ub
66 cat .header .lb .ub .pragma |
sed -e "s/$DIM #pragma/#pragma/" > $1
67 echo -e "\tfor ($DIM=lb$i; $DIM<=ub$i; $DIM++) {" >> $1
74 rm -f .header .footer .ub .lb .parloop .pragma