summaryrefslogtreecommitdiff
path: root/Trivac/rtrivac
blob: 5b1bb8fa446a25d17dc7e54eddc34d4c0a2dc35d (plain)
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
164
165
166
#!/bin/sh
#
# author : A. Hebert
# use    : rtrivac [-c:|-q|-w|-p:|-i:] <file.x2m>
# note   : <file.x2m> must be located on directory ./data/
#          If <file.access> exists, it is executed.
#          -c name of compiler
#          -q quiet execution for regression testing
#          -w to execute in console (for debug purpose)
#          -p number of parallel threads (=1 by default)
#          -i name of x2m dataset (by default, use the last argument)
#
if [ $# = 0 ]
   then
   echo "usage: rtrivac [-c:|-q|-w|-p:|-i:] <file.x2m>" 1>&2
   exit 1
fi
System=`uname -s`
Sysx="`echo $System | cut -b -6`"
if [ $Sysx = "CYGWIN" ]; then
   MACH=`uname -o`
elif [ $Sysx = "AIX" ]; then
   MACH=`uname -s`
else
   MACH=`uname -sm | sed 's/[ ]/_/'`
fi

for last; do : ; done
mydata=${last}
typ='custom'
quiet=0
term=0
nomp=0

while getopts ":c:qwi:p:" opt; do
  case $opt in
    c) typ="$OPTARG"
    ;;
    q) quiet=1
    ;;
    w) term=1
    ;;
    p) nomp=$OPTARG
    ;;
    i) mydata=$OPTARG
    ;;
    \?) echo "Invalid option -$OPTARG" >&2
    exit 1
    ;;
  esac

  case $OPTARG in
    -*) echo "Option $opt needs a valid argument"
    exit 1
    ;;
  esac
done

xxx=`basename $mydata .x2m`
Code=`basename "$PWD"`
if [ $quiet = 0 ]; then
  echo 'execute' $xxx 'with' $Code 'on system' $MACH 'with' $typ 'compiler'
fi

if [ -d "$MACH" ]; then
  if [ $quiet = 0 ]; then
    echo 'use the existing directory' $MACH
  fi
else
  echo 'creation of directory' $MACH
  mkdir "$MACH"
fi
CodeDir=$PWD

if [ $Sysx = "AIX" ]; then
  Tmpdir=/usr/tmp
elif [ $Sysx = "SunOS" ]; then
  Tmpdir=/var/tmp
else
  Tmpdir=/tmp
fi
inum=1
while [ -d $Tmpdir/rundir$inum ]
  do
  inum=`expr $inum + 1 `
done
Rundir=$Tmpdir/rundir$inum
mkdir $Rundir
if [ $quiet = 0 ]; then
  echo "RunDirectory:" $Rundir
fi
cd $Rundir

if [ $typ = 'custom' ]; then
  cp "$CodeDir"/bin/"$MACH"/$Code ./code
else
  cp "$CodeDir"/bin/"$MACH"'_'$typ/$Code ./code
fi
cp "$CodeDir"/data/$mydata ./mydata

export NO_STOP_MESSAGE=1
if [ -d "$CodeDir"/data/`echo $xxx`_proc ]; then
  cp "$CodeDir"/data/`echo $xxx`_proc/*.c2m . 2> /dev/null
fi
if [ -f "$CodeDir"/data/$xxx.access ]; then
  if [ $quiet = 0 ]; then
    "$CodeDir"/data/$xxx.access "$CodeDir"
  else
    "$CodeDir"/data/$xxx.access "$CodeDir" > /dev/null
  fi
fi
if [ -f "$CodeDir"/data/assertS.c2m ]; then
  cp "$CodeDir"/data/assertS.c2m .
fi
if [ -f "$CodeDir"/data/assertV.c2m ]; then
  cp "$CodeDir"/data/assertV.c2m .
fi
before=$(date +%s)
if [ $nomp != 0 ]; then
  echo 'number of OpenMP threads=' $nomp
  export OMP_NUM_THREADS=$nomp
  if command -v numactl >&2; then
    numactl --cpunodebind=0 --membind=0 2>/dev/null
    echo "use NUMA memory policy"
  fi
else
  export OMP_NUM_THREADS=1
fi
if [ $term = 0 ]; then
  ./code <mydata >$xxx.result
elif [ $term = 1 ]; then
  ./code <mydata
fi
if [ $quiet = 0 ]; then
  time=$(( $(date +%s) - before))
  printf 'End of execution. Total execution time: %dh %dmin %ds\n' \
    $(($time/3600)) $(($time%3600/60)) $(($time%60))
fi
if [ -f "$CodeDir"/data/$xxx.save ]; then
  if [ $quiet = 0 ]; then
    "$CodeDir"/data/$xxx.save "$CodeDir"
  else
    "$CodeDir"/data/$xxx.save "$CodeDir" > /dev/null
  fi
fi
mv $xxx.result "$CodeDir"/"$MACH"
if [ $quiet = 0 ]; then
  echo 'the listing is located on ./'$MACH
fi

cd "$CodeDir"/"$MACH"
if [ $quiet = 0 ] && [ $term = 0 ]; then
  tail -15 $xxx.result
elif [ $term = 0 ]; then
  RED='\033[0;31m'
  GREEN='\033[0;32m'
  NC='\033[0m' # No Color
  if tail $xxx.result | grep -q "normal end" ; then
    printf "${GREEN}[OK]${NC}\n"
  else
    printf "${RED}[FAILED]${NC}\n"
  fi
fi
chmod -R 777 $Rundir
/bin/rm -r -f $Rundir
cd ..