forked from SmileiPIC/Smilei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smilei.sh
executable file
·103 lines (91 loc) · 2.28 KB
/
smilei.sh
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
#!/bin/bash
MPIEXEC=mpirun
H=$PWD # current dir
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # dir of this script
smilei=$DIR/smilei # path to the smilei executable
script=$0 # name of this script
# Function to explain usage
usage () {
echo "usage: $script [number_of_procs] namelist1 [namelist2 ...] [-o outdir]"
}
# Check that at least one argument provided
if [ "$#" -lt 1 ]; then
usage
exit 1
fi
# If first argument is a number, this is the number of procs
if [[ $1 =~ ^[0-9]+$ ]]; then
proc=$1
shift
else
proc=1
fi
# Loop additional namelists
namelists=()
namelist_files=()
firstnamelist=""
while [[ $# -ge 1 ]]; do
arg=$1
# If -o option, leave
if [[ $arg == -o* ]]; then
break
fi
# Try to convert to absolute path
absnml="$(cd "$(dirname "$arg")" && pwd)/$(basename "$arg")"
# If file, then add it as namelist
if [ -f $absnml ]; then
echo "Namelist found: "$absnml
namelists+=("`basename $absnml`")
namelist_files+=("$absnml")
# Save the first namelist
if [ -z $firstnamelist ]; then
firstnamelist=$absnml
fi
# Otherwise add it as python commands
else
namelists+=("\"$arg\"")
fi
shift
done
# Error if no namelist
if [ -z $firstnamelist ]; then
echo "$script: At least one namelist must be provided."
usage
exit 1
fi
# Next argument, if exists, is the outdir
base="`basename $firstnamelist .py`" # strip directory and extension of first namelist
outdir=`dirname $firstnamelist`/$base # by default, the outdir is same as first namelist
# otherwise, provided as argument
if [ "$#" -gt 0 ]; then
if [[ $1 == -o ]]; then
shift
if [ "$#" -lt 1 ]; then
usage
exit 1
fi
outdir=$1
shift
fi
fi
# If outdir already exist, error
if [ -d $outdir ]; then
echo "* "
echo "* ERROR: Directory $outdir already exists. Please remove it first."
echo "* "
exit 1
fi
# Error if arguments leftover
if [ "$#" -gt 0 ]; then
usage
exit 1
fi
# Make new directory, go there, and run
mkdir -p $outdir
# copy namelists there
for namelist in "${namelist_files[@]}"; do
cp $namelist $outdir
done
cd $outdir
$MPIEXEC -mca btl tcp,sm,self -np $proc $smilei "${namelists[@]}"
cd $H