fix warnings
[pluto.git] / ploog
blobc12c8c5e7cbc39a69605b97d1d8f414448177865
1 #!/bin/bash
2 #
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
11 if [ $# -ne 2 ]; then
12 echo "Usage: ./ploog <src file> [all loops = 0 | first loop = 1] "
13 # third arg: 0 - all loops, 1 - first loop
14 exit 1
17 if [ ! -f $1 ]; then
18 echo "ploog: Input file $1 does not exist"
19 exit 2
22 if [ ! -f .pragmas ]; then
23 echo "[ploog] WARNING: no parallel loops"
24 exit 0
27 NUMLINES=`wc -l $1 | awk '{print $1}'`
28 dirname=`dirname $1`
29 npar=`wc -l .pragmas | awk '{print $1}'`
30 PARDIMS=`cat .pragmas | awk '{print $1}'`
32 i=1
34 for DIM in $PARDIMS; do
35 # sometimes the scattering dimension may not appear
36 grep -q $DIM $1
38 if [ $? -ne 0 ]; then
39 break
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]}'`
49 else
50 LINE_NUMBERS=`grep -n "for ($DIM=" $1 | awk '{split($1,t,":"); print t[1]}' | head -n 1`
54 j=0
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
68 cat .footer >> $1
69 j=$((j+1))
70 done
71 i=$((i+1))
72 done
74 rm -f .header .footer .ub .lb .parloop .pragma