-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_job_acc.sh
executable file
·356 lines (296 loc) · 9.9 KB
/
submit_job_acc.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/bin/bash
###############################################################################
#
# This is an example of a script for submitting AutoCompChem job that can
# contain any number and type sub-jobs.
# Run it with no argument to get the documentation or with option "--help".
# The jobscript is ment for SLURM scheduler.
#
# Usage: run this script with no argument or with -h to get the documentation.
#
# Crated: Marco Foscato - June 2024
#
###############################################################################
# Configuration:
# You want to edit these parameters to adapt this script to your system!
# SLURM account paying for cpu time
account=_you_must_change_this_string_
# Pathname to the AutoCompChem JAR archive
ACCJar=_you_must_change_this_path_/autocompchem-2.0.1-jar-with-dependencies.jar
javaForACC=_you_must_change_this_path_/bin/java
# Pathname to file system location where to actually run the job (work space)
scratchdisk=_you_must_change_this_path_
###############################################################################
#
# Function printing the usage instructions
#
function printUsage() {
cat <<EOF
This is the command for submission of AutoCompChem jobs. These jobs may include
one or more other jobs that can run any what-so-ever sorftware.
Usage
=====
<command> -j <jd> [-f <file>[,<files>]] [...]
Where:
<command> is the command you have already used to get this message, and can
be any link or alias to execute script '$0'.
Options (if omitted, default values will be used):
-h (--help) prints this help message.
-c NN set the number of cores per node to NN (default: 40).
As a rule, when submitting other computational tasks from within
an ACC job, we leave one core to ACC and use the rest for the
chiled task.
-t NN set the walltime to NN hours (default 10 min)
-j FILE specifies that the job details and parameters are to be taken
from file FILE.
-f FILE[,FILE] specifies pathname of the input file (or many files - comma
separated list) to be made available to the job, i.e.,
copied to the work space.
--jobname NAME sets the name of this job. By default, we try to set this name
using either the value of the -j option, or the -f option. If
this is not possible (e.g., no -j and multiple files given to -f)
the job will be gven a unique name starting with "accJob-".
--accargs STRING use this to provide additional comman line argument when
running AutoCompChem.
--tcl FILE requires the generation of a tack-completed label/flag file (i.e.,
the TCL-file) named FILE. The TCL-file is used to signal that the
job has completed, and to provide a list of files that you might
want to recover or transfer somethere else for further processing.
These files are specified, one by line, in the content of the
TCL-file. Use the --tclREGEX to control what files will be added
to the TCL-file.
--tclREGEX REGEX[,REGEX] provide a list of REGEX used to identify which files
to list in the TCL-file. REGEX will be use to match the wholepath
in a "find . -regex" command.
EOF
}
###############################################################################
#
# Main
#
##############################################################################
# Then check input
if [ $# -lt 2 ]
then
echo " "
echo " ERROR! You must give me at least the pathname to the AutoCompChem job details/parameters (e.g., -j <pathname>)."
printUsage
exit 1;
fi
submitDir="$(pwd -P)"
numCores=40
wallTime=01
listInpFiles=""
inpFiles=()
jdFile=""
accArgs="" #NB: we threat them as a single string at this stage
populateTCLRegexString=""
jobName="accJob-$(date +%s)"
# Parse command line options
args=("$@")
for ((i=0; i<$#; i++))
do
arg="${args[$i]}"
case "$arg" in
"-c") numCores=${args[$i+1]};;
"-t") wallTime=${args[$i+1]};;
"-j") jdFile=${args[$i+1]};;
"-f") listInpFiles=${args[$i+1]};;
"--tcl") tclFile=${args[$i+1]};;
"--jobname") jobName=${args[$i+1]};;
"--accargs") accArgs=${args[$i+1]};;
"--tclREGEX") populateTCLRegexString=${args[$i+1]};;
*);;
esac
done
# Process list of input filenames
for inpFile in $(echo "$listInpFiles" | sed 's/,/ /g')
do
inpFiles+=("$inpFile")
done
echo "Found ${#inpFiles[@]} links to input files."
echo "Job name set to '$jobName'"
# Process request to change the REGEX, first set the default
outputExclusionRules=()
outputExclusionRules+=("^xtb.err$")
outputExclusionRules+=("^.*property.txt$")
outputExclusionRules+=("^.*\.charges$")
outputExclusionRules+=("^.*\.prop$")
outputExclusionRules+=("^.*\.lastxtb$")
outputExclusionRules+=("^.*\.lastxtberr$")
outputExclusionRules+=("^.*\.engrad$")
outputExclusionRules+=("^.*\.gradient$")
outputExclusionRules+=("^.*\.proc[0-9]+\..*$")
outputExclusionRules+=("^core\..*$")
outputExclusionRules+=("^fort\.[0-9]$")
outputExclusionRules+=("^tmp$")
outputExclusionRules+=("\.tmp$")
outputExclusionRules+=("^[a-zA-Z0-9]+$")
outputExclusionRules+=("^Gau-.*$")
# Define regex to populate TCL file
rulesToListFilesInTCL=()
if [ ! -z "$populateTCLRegexString" ]
then
rulesToListFilesInTCL=()
for r in $(echo $populateTCLRegexString | sed 's/,/ /g')
do
rulesToListFilesInTCL+=("\"$r\"")
done
fi
#Prepare job file to be submitted to SLURM
cat<<EOF>$jobName.job
#!/bin/bash -l
################## AutoCompChem -- JOB-SCRIPT #####################
#
# SLURM-section
#SBATCH --account=$account
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --mem=80000mb
#SBATCH --cpus-per-task=$numCores
#SBATCH --time=$wallTime:10:00
#SBATCH --job-name=$jobName
#SBATCH --output=$jobName.log
#SBATCH --error=$jobName.log
#
#####################################################################
jobName="$jobName"
jdFile="$jdFile"
listInpFiles="$listInpFiles"
accArgs="$accArgs"
submitDir=$submitDir
scratchdisk=$scratchdisk
tclFile=$tclFile
#####################################################################
echo "########### ACC - Job Start ###########"
machine=\`hostname\`
echo "Job started on \$machine at"
date
echo "The job was submitted from \$submitDir"
# Define and Make working space (scratch directory)
workDir=\$scratchdisk/\$LOGNAME/\$SLURM_JOB_ID/\$jobName
echo "The job will use scratch-directory \$workDir"
mkdir -p "\$workDir"
# Copy input files to scratch directory
if [ ! -z "\$jdFile" ]; then cp "\$jdFile" "\$workDir" ; fi
for f in \$(echo "\$listInpFiles" | sed 's/,/ /g')
do
echo "Copying \$f to work space"
cp "\$f" "\$workDir"
done
#Move to scratch directory
cd "\$workDir"
echo " "
# Call AutoCompChem
echo "********************** Calling ACC ********************"
java -jar $ACCJar --params \$jdFile \$accArgs
echo "********************* done with ACC *******************"
#
ls -Rlt
# We need rules to define what files to list in the TCL file
EOF
# We need to initialize an array of variables
echo "rulesToListFilesInTCL=()" >> $jobName.job
for r in "${rulesToListFilesInTCL[@]}"
do
echo "rulesToListFilesInTCL+=($r)" >> $jobName.job
done
cat<<EOF>>$jobName.job
#
# function that says goodbye
#
function sayGoodbye() {
echo "Job finished on \$machine at"
date
echo " "
scontrol show job \$SLURM_JOB_ID
echo " "
if [ ! -z "\$tclFile" ] ; then
touch "\$submitDir/\${tclFile}_pre"
echo "\$jobName.log" >> "\$submitDir/\${tclFile}_pre"
for query in "\${rulesToListFilesInTCL[@]}"
do
find * -type f -regex "\$query" -print0 | while read -d \$'\0' f
do
echo "Adding \$f to TCL file"
echo "\$f" >> "\$submitDir/\${tclFile}_pre"
done
done
mv "\$submitDir/\${tclFile}_pre" "\$submitDir/\$tclFile"
fi
exit 0
}
# We cannot know what are the actual output files, but we need to bring them back home
# So, we copy all, excluding files that match the REGEX rules.
EOF
# We need to initialize an array of variables
echo "outputExclusionRules=()" >> $jobName.job
for r in "${outputExclusionRules[@]}"
do
echo "outputExclusionRules+=($r)" >> $jobName.job
done
cat<<EOF>>$jobName.job
# If you need to avoid the copying of some crap, just add more exceptions to the list.
# or use the --cleanupREGEX option to reset this list at submission time.
find * -type d | while read d
do
mkdir -p "\$submitDir"/"\$d"
done
echo " "
echo " WARNING:"
echo " We use these REGEX to identify files that are NOT copied back home:"
for regex in "\${outputExclusionRules[@]}"
do
echo " -> \$regex"
done
echo " "
find * -type f -print0 | while read -d \$'\0' f
do
fileName="\$(basename "\$f")"
extension="\${fineName##*.}"
ignoreIt=false
for regex in "\${outputExclusionRules[@]}"
do
if [[ "\$fileName" =~ \$regex ]]
then
ignoreIt=true
break;
fi
done
if \$ignoreIt
then
echo "File '\$f' is NOT copied back home!"
else
cp "\$f" "\$submitDir/\$f"
if [ \$? -gt 0 ]
then
echo " "
echo " WARNING! File \$f could not be copied back home for"
echo " some problem in executing the cp command."
echo " Therefore, I'll not remove the work space directory."
echo " "
sayGoodbye
fi
fi
done
# Move back to the submitDir's home
cd \$submitDir
if [ -d \$workDir ]
then
echo "Removing the scratch-directory with rm -rf"
rm -rf \$workDir
fi
if [ -d \$workDir ]
then
echo "For some strange reason the scratch-directory is still present"
echo "Trying to remove it using rmdir"
rmdir \$workDir
rmdir \$scratchdisk/\$LOGNAME/\$SLURM_JOB_ID/
fi
# All done, leave.
sayGoodbye
EOF
chmod o-rwx "$jobName.job"
chmod g-w "$jobName.job"
sbatch $jobName.job
exit 0