-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswanrun
153 lines (152 loc) · 3.83 KB
/
swanrun
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
#!/bin/sh
#
#-----------------------------------------------------------------------
# initialize procedure parameters
#-----------------------------------------------------------------------
#
input=
npmpi=1
npomp=1
export OMP_NUM_THREADS=1
#
#-----------------------------------------------------------------------
# read procedure parameters from run call
#-----------------------------------------------------------------------
#
while [ $# -ge 2 ]
do
case $1 in
-input) input=`basename $2 .swn`;;
-omp) npomp=$2;;
-mpi) npmpi=$2;;
*) echo unknown parameter: $1
echo ' Usage: swanrun -input file [-omp n | -mpi n]'
echo
exit ;;
esac
shift 2
done
#
#-----------------------------------------------------------------------
# if input file is not given, produce error
#-----------------------------------------------------------------------
#
if [ -z "$input" ]; then
echo
echo '***ERROR: no name SWAN input file given!'
echo
echo ' Usage: swanrun -input file [-omp n | -mpi n]'
echo
exit 1
fi
#
#-----------------------------------------------------------------------
# check whether MPI is available in case of parallel MPI run
#-----------------------------------------------------------------------
#
IFS="${IFS= }"; IFS="${IFS}:"
for dir in $PATH; do
test -z "$dir" && dir=.
if test -f $dir/mpirun; then
mpi=1
break
fi
done
if [ $npmpi -gt 1 -a -z "$mpi" ]; then
echo
echo "***ERROR: MPI is not available!"
echo
exit 1
fi
#
#-----------------------------------------------------------------------
# check whether machinefile is available (if necessary)
#-----------------------------------------------------------------------
#
# Note: no machinefile is needed on small multi-core shared-memory Linux machine or on SGI platform
#
os=`uname -s`
if [ "$os" = Linux ]; then
ncore=`grep -ic ^processor /proc/cpuinfo`
if [ $ncore -le 8 ]; then
nmf=1
fi
fi
os=`echo $os | tr "[a-z]" "[A-Z]" | awk '{print substr($0,1,4)}'`
if [ "$os" = IRIX ]; then
nmf=1
fi
if [ $npmpi -gt 1 -a ! -z "$mpi" -a -z "$nmf" ]; then
if [ ! -f machinefile -a ! -h machinefile ]; then
echo
echo "***ERROR: no machinefile is present in current directory!"
echo
exit 1
fi
fi
#
#-----------------------------------------------------------------------
# run SWAN
#-----------------------------------------------------------------------
#
# adapt PATH to ensure a locally present executable is executed
PATH=.:$PATH
type swan.exe
if [ -r $input.swn ]; then
orig=n
cp $input.swn INPUT
if [ $npomp -gt 1 ]; then
export OMP_NUM_THREADS=$npomp
swan.exe
elif [ $npmpi -gt 1 -o ! -z "$mpi" ]; then
if [ ! -f swan.exe ]; then
ln -s `which swan.exe` swan.exe
orig=y
fi
if [ -z "$nmf" ]; then
if [ $npmpi -gt 1 ]; then
mpirun -np $npmpi -machinefile machinefile swan.exe
else
swan.exe
fi
else
mpirun -np $npmpi swan.exe
fi
else
swan.exe
fi
if [ $npmpi -gt 1 ]; then
inode=0
while [ $inode -lt $npmpi ]; do
inode=`expr $inode + 1`
inode=`echo $inode | awk '{ printf "%03.0f", $0 }'`
if [ -f PRINT-$inode ]; then
mv PRINT-$inode $input.prt-$inode
fi
if [ -r Errfile-$inode ]; then
mv Errfile-$inode $input.erf-$inode
fi
done
else
if [ -f PRINT ]; then
mv PRINT $input.prt
fi
if [ -r Errfile ]; then
mv Errfile $input.erf
fi
fi
if [ -r ERRPTS ]; then
mv ERRPTS $input.erp
fi
if [ -f norm_end ]; then
cat norm_end
fi
if [ -h swan.exe -a "$orig" = y ]; then
rm -f swan.exe
fi
rm -f INPUT
else
echo "file $input.swn does not exist"
exit 1
fi
#