1 | ###Script to launch several successive jobs on Gnome |
---|
2 | |
---|
3 | # In your directory, you need : |
---|
4 | # - this script |
---|
5 | # - the reference script for Load Leveler, containing the settings of a job (which .def to use, which executable, Load Leveler settings...). |
---|
6 | |
---|
7 | |
---|
8 | #!/bin/bash |
---|
9 | |
---|
10 | ##### MODIFY THIS : |
---|
11 | n=3 #total number of jobs |
---|
12 | ref='launch_128_96_64_ref' #name of the reference script |
---|
13 | |
---|
14 | |
---|
15 | #Following commands are specific to Load Leveler : change them if you use another batch scheduling system |
---|
16 | ini_dir='$LOADL_STEP_INITDIR' # Absolute path to the submission directory, as named in the reference script |
---|
17 | run_dir='$LOADL_STEP_INITDIR/${tmpdir}' #Generic absolute path to the run directory, as named in the reference script (eg. job_name.job_id etc...) |
---|
18 | |
---|
19 | sub_cmd=llsubmit #command to submit a job |
---|
20 | |
---|
21 | ############################################################################################################################## |
---|
22 | |
---|
23 | # THE REFERENCE SCRIPT IS READ : |
---|
24 | |
---|
25 | #we check that the lines about the copy of the startfi.nc follows the one with |
---|
26 | #start.nc |
---|
27 | |
---|
28 | ligne="$(grep -n 'cp .*start.nc' ${ref} | cut -d: -f1)" |
---|
29 | lignefi="$(grep -n 'cp .*startfi.nc' ${ref} | cut -d: -f1)" |
---|
30 | |
---|
31 | if [ ${lignefi} -ne "$(expr ${ligne} \+ 1)" ] |
---|
32 | then |
---|
33 | echo 'Error :' |
---|
34 | echo 'In '${ref}' ,the line about startfi.nc must follow the line about start.nc' |
---|
35 | exit |
---|
36 | fi |
---|
37 | |
---|
38 | #CREATION OF THE 1ST SCRIPT |
---|
39 | cp ${ref} launch1 |
---|
40 | |
---|
41 | #CREATION OF THE LAST SCRIPT |
---|
42 | |
---|
43 | #same as the reference script except that its start*.nc files are the restart*.nc files produced by the second to last simulation |
---|
44 | |
---|
45 | head -n $(expr ${ligne} \- 1 ) launch1 > launch${n} |
---|
46 | echo 'cp -rf ' ${ini_dir}'/zeLAST/restart.nc ' ${run_dir}'/start.nc' >> launch${n} |
---|
47 | echo 'cp -rf ' ${ini_dir}'/zeLAST/restartfi.nc ' ${run_dir}'/startfi.nc' >> launch${n} |
---|
48 | tail -n +$(expr ${lignefi} \+ 1 ) launch1 >> launch${n} |
---|
49 | |
---|
50 | |
---|
51 | #1ST SCRIPT IS COMPLETED AND THE OTHERS (from 2 to n-1 ARE CREATED) |
---|
52 | |
---|
53 | # Scripts 2 to n-1 are created from the last script (as jobs 2 to n-1 must start from restart*.nc produced by the previous job). |
---|
54 | # Commands are added to Scripts 1 to n-1 to launch the next job. |
---|
55 | |
---|
56 | for ((i=1 ; i<=${n}; i+=1)) |
---|
57 | do |
---|
58 | if [ ${i} -ne 1 ] && [ ${i} -ne ${n} ] |
---|
59 | then |
---|
60 | cp launch${n} launch${i} |
---|
61 | fi |
---|
62 | |
---|
63 | #Link toward the repertory of the last simulation |
---|
64 | echo 'cd ' ${ini_dir} >> launch${i} |
---|
65 | echo 'rm -f zeLAST' >> launch${i} |
---|
66 | echo 'lastdir=`ls -ltrd */ | awk' "'{print" '$NF}'"'" '| tail -n 1 `' >> launch${i} |
---|
67 | echo 'ln -sf ${lastdir} zeLAST' >> launch${i} |
---|
68 | echo >> launch${i} |
---|
69 | |
---|
70 | if [ ${i} -ne ${n} ] |
---|
71 | then |
---|
72 | #Launch the next job |
---|
73 | echo '#Lancement du job script suivant' >> launch${i} |
---|
74 | echo 'cd' ${ini_dir} >> launch${i} |
---|
75 | echo ${sub_cmd}' launch'$(expr $i \+ 1) >> launch${i} |
---|
76 | fi |
---|
77 | done |
---|
78 | |
---|
79 | |
---|
80 | #LAST RUN : CREATION OF outputs.txt |
---|
81 | # concatnc.e < outputs.txt will concatenate all the diagfi.nc |
---|
82 | |
---|
83 | echo 'cd '${ini_dir} >> launch${n} |
---|
84 | echo 'find . -maxdepth 2 -name "diagfi.nc" >> outputs.txt' >> launch${n} |
---|
85 | |
---|
86 | echo 'echo >> '${ini_dir}'/outputs.txt' >> launch${n} |
---|
87 | echo 'echo 0 >> '${ini_dir}'/outputs.txt' >> launch${n} |
---|
88 | echo 'echo ls >> '${ini_dir}'/outputs.txt' >> launch${n} |
---|
89 | echo 'echo all >> '${ini_dir}'/outputs.txt' >> launch${n} |
---|
90 | echo 'echo >> '${ini_dir}'/outputs.txt' >> launch${n} |
---|
91 | |
---|
92 | #LAUNCH THE 1ST JOB |
---|
93 | ${sub_cmd} launch1 |
---|
94 | |
---|