3 #----------------------------------------------------------------------------------------------------------------
4 # Submit jobs for calculating GENIE free-nucleon cross-section splines which can then be re-used for calculating
5 # nuclear cross-sections. If needed, use the GENIE gspladd utility to merge the job outputs.
8 # shell% perl submit_vN_xsec_calc_jobs.pl <options>
11 # --version : genie version number
12 # [--config-dir] : Config directory, default is $GENIE/config
13 # [--tune] : Select a tune for Genie configuration
14 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
15 # [--production] : default: routine_validation
16 # [--cycle] : default: 01
17 # [--use-valgrind] : default: off
18 # [--batch-system] : <PBS, LyonPBS, LSF, slurm, HTCondor, HTCondor_PBS, none>, default: PBS
19 # [--queue] : default: prod. LyonPBS default: P_gdrnu_genie
20 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE/
21 # [--jobs-topdir] : top level dir for job files, default: $PWD
22 # [--gen-list] : comma separated list of event generator list, default all
23 # [--nu-list] : comma separated list of neutrino. Both PDGs or names are ok, default all
24 # [--e-max] : maxmium energy of the splines in GeV. Default 200 GeV.
25 # [--n-knots] : number of knots per spline. Default 100.
26 # [--with-priority] : (boolean) set a priority to optimize bulk productions. Default false
27 # [--run-one] : (boolean) If called, one of the jobs is run as part of the script instead of submitted
28 # via the batch system. Default all the jobs are submitted
31 # shell% perl submit_vN_xsec_calc_jobs.pl --version v2.6.0
32 # shell% perl submit_vN_xsec_calc_jobs.pl --version v2.6.0
33 # shell% perl submit_vN_xsec_calc_jobs.pl --version v2.6.0
36 # Costas Andreopoulos <costas.andreopoulos \st stfc.ac.uk>
37 # University of Liverpool & STFC Rutherford Appleton Laboratory
40 # Copyright (c) 2003-2020, The GENIE Collaboration
41 # For the full text of the license visit http://copyright.genie-mc.org
42 #-------------------------------------------------------------------------------------------------------------
50 if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
51 if($_ eq '--config-dir') { $config_dir = $ARGV[$iarg+1]; }
52 if($_ eq '--tune') { $tune = $ARGV[$iarg+1]; }
53 if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
54 if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
55 if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
56 if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
57 if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
58 if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
59 if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
60 if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
61 if($_ eq '--gen-list' ) { $req_gen_list = $ARGV[$iarg+1]; }
62 if($_ eq '--nu-list' ) { $req_nu_list = $ARGV[$iarg+1]; }
63 if($_ eq '--e-max' ) { $e_max = $ARGV[$iarg+1]; }
64 if($_ eq '--n-knots' ) { $n_knots = $ARGV[$iarg+1]; }
65 if($_ eq '--with-priority' ) { $priority = 1; }
66 if($_ eq '--run-one' ) { $run_one = 1; }
69 die("** Aborting [Undefined GENIE version. Use the --version option]")
70 unless defined $genie_version;
72 $config_dir = "" unless defined $config_dir;
73 $use_valgrind = 0 unless defined $use_valgrind;
74 $arch = "SL6.x86_64" unless defined $arch;
75 $production = "routine_validation" unless defined $production;
76 $cycle = "01" unless defined $cycle;
77 $batch_system = "PBS" unless defined $batch_system;
78 $queue_default = "prod";
79 if ( $batch_system eq 'LyonPBS' ) {
80 $queue_default = "P_gdrnu_genie" ;
82 $queue = $queue_default unless defined $queue;
83 $softw_topdir = "/opt/ppd/t2k/softw/GENIE/" unless defined $softw_topdir;
84 $jobs_topdir = $ENV{'PWD'} unless defined $jobs_topdir;
85 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
86 $jobs_dir = "$jobs_topdir/$genie_version-$production\_$cycle-xsec\_vN";
87 $priority = 0 unless defined $priority ;
88 $e_max = 200 unless defined $e_max ;
89 $n_knots = 100 unless defined $n_knots ;
92 %nucleons_pdg = ( 'n' => 1000000010,
95 %nucleons_name = ( 1000000010 => 'n' ,
98 @nucleons_proc = ( 'none',
104 %nu_pdg_def = ( 've' => 12,
111 %nu_name_def = ( 12 => 've' ,
118 ##create the list of neutrino to be produced
119 if ( defined $req_nu_list ) {
120 my @nu_temp_list = split( ",", $req_nu_list );
122 foreach my $nu ( @nu_temp_list ) {
123 if ( exists $nu_pdg_def{$nu} ) { push @nu_list, $nu ; }
124 if ( exists $nu_name_def{$nu} ) { push @nu_list, $nu_name_def{$nu} ; }
128 @nu_list = values %nu_name_def;
133 if ( defined $req_gen_list ) {
134 my @proc_temp_list = split( ",", $req_gen_list );
135 @nucleons_proc_list = ();
136 foreach my $proc ( @proc_temp_list ) {
137 if ( grep {$_ eq $proc} @nucleons_proc ) { push @nucleons_proc_list, $proc ; }
141 @nucleons_proc_list = @nucleons_proc;
143 print "Process List: @nucleons_proc_list \n";
146 # make the jobs directory
149 @batch_commands = ();
150 @direct_commands = () ;
152 print "@@ Creating job directory: $jobs_dir \n";
153 mkpath ($jobs_dir, {verbose => 1, mode=>0777});
155 foreach $nu ( @nu_list ) {
156 foreach $tgt ( keys %nucleons_pdg ) {
157 foreach $proc ( @nucleons_proc_list ) {
159 if ( $proc eq "none" ) {
163 if ( $proc eq 'CCQE' ) {
164 if ( ($tgt eq 'n' ) && ( $nu_pdg_def{$nu} < 0 ) ) { next ; }
165 if ( ($tgt eq 'p' ) && ( $nu_pdg_def{$nu} > 0 ) ) { next ; }
168 if ( ( $proc eq 'CCDFR' ) || ( $proc eq 'NCDFR' ) ) {
169 if ( $tgt eq 'n' ) { next ; }
172 if ( $proc eq 'Fast' ) {
173 $event_gen_list = 'FastOn' . ( uc $tgt );
176 $event_gen_list = $proc ;
179 $jobname = $nu."_on_".$tgt."_$proc";
180 $filename_template = "$jobs_dir/$jobname";
182 $grep_pipe = "grep -B 100 -A 30 -i \"warn\\|error\\|fatal\"";
183 $valgrind_cmd = "valgrind --tool=memcheck --error-limit=no --leak-check=yes --show-reachable=yes";
184 $gmkspl_opt = "-p $nu_pdg_def{$nu} -t $nucleons_pdg{$tgt} -n $n_knots -e $e_max -o $filename_template.xml --event-generator-list $event_gen_list ";
185 if ( defined $tune ) {
186 $gmkspl_opt.= " --tune $tune ";
188 $gmkspl_cmd = "gmkspl $gmkspl_opt";
190 print "@@ exec: $gmkspl_cmd \n";
193 $shell_script = "$filename_template.sh";
194 open(COMMANDS, ">$shell_script") or die("Can not create the bash script");
195 print COMMANDS "#!/bin/bash \n";
196 print COMMANDS "cd $jobs_dir \n";
197 print COMMANDS "source $genie_setup $config_dir \n";
198 print COMMANDS "$gmkspl_cmd \n";
201 # set executing privileges to the script
202 `chmod ugo+x $filename_template.sh` ;
204 push( @direct_commands, "bash $filename_template.sh" ) ;
208 if($batch_system eq 'PBS' || $batch_system eq 'HTCondor_PBS') {
209 $batch_script = "$filename_template.pbs";
210 open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
211 print PBS "#!/bin/bash \n";
212 print PBS "#PBS -N $jobname \n";
213 print PBS "#PBS -o $filename_template.pbsout.log \n";
214 print PBS "#PBS -e $filename_template.pbserr.log \n";
215 print PBS "#PBS -p -1 \n" if ( $priority ) ;
216 print PBS "source $shell_script \n";
218 $job_submission_command = "qsub";
219 if($batch_system eq 'HTCondor_PBS') {
220 $job_submission_command = "condor_qsub";
223 push( @batch_commands, "$job_submission_command -q $queue $batch_script" ) ;
224 } #PBS / #HTCondor_PBS
228 if($batch_system eq 'LyonPBS' ) {
229 $batch_script = "$filename_template.pbs";
230 open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
231 print PBS "#!/bin/bash \n";
232 print PBS "#\$ -P $queue \n";
233 print PBS "#\$ -N $jobname \n";
234 print PBS "#\$ -o $filename_template.pbsout.log \n";
235 print PBS "#\$ -e $filename_template.pbserr.log \n";
236 print PBS "#\$ -l ct=8:00:00,sps=1 \n";
237 print PBS "#\$ -p -1 \n" if ( $priority ) ;
238 print PBS "source $shell_script \n";
240 $job_submission_command = "qsub";
242 push( @batch_commands, "$job_submission_command $batch_script " ) ;
247 if($batch_system eq 'LSF') {
248 $batch_script = "$filename_template.sh";
249 open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
250 print LSF "#!/bin/bash \n";
251 print LSF "#BSUB-j $jobname \n";
252 print LSF "#BSUB-q $queue \n";
253 print LSF "#BSUB-o $filename_template.lsfout.log \n";
254 print LSF "#BSUB-e $filename_template.lsferr.log \n";
255 print LSF "source $shell_script \n";
258 push( @batch_commands, "bsub < $batch_script " ) ;
263 if($batch_system eq 'HTCondor') {
264 $batch_script = "$filename_template.htc";
265 open(HTC, ">$batch_script") or die("Can not create the Condor submit description file: $batch_script");
266 print HTC "Universe = vanilla \n";
267 print HTC "Executable = $shell_script \n";
268 print HTC "Log = $filename_template.log \n";
269 print HTC "Output = $filename_template.out \n";
270 print HTC "Error = $filename_template.err \n";
271 print HTC "Request_memory = 2 GB \n";
272 print HTC "priority = -1 \n" if ( $priority ) ;
273 print HTC "requirements = (Opsys =?= \"LINUX\") && (AccessToData =?= True) && (OpSysAndVer =?= \"CentOS7\") \n" ;
274 print HTC "Queue \n";
276 push ( @batch_commands, "condor_submit $batch_script" ) ;
280 if($batch_system eq 'slurm') {
281 $batch_script = "$filename_template.sh";
282 open(SLURM, ">$batch_script") or die("Can not create the slurm batch script");
283 print SLURM "#!/bin/bash \n";
284 print SLURM "#SBATCH-p $queue \n";
285 print SLURM "#SBATCH-o $filename_template.slurmout.log \n";
286 print SLURM "#SBATCH-e $filename_template.slurmerr.log \n";
287 print SLURM "source $shell_script \n";
290 push( @batch_commands, "sbatch --job-name=$jobname $batch_script" ) ;
306 if ( $batch_system eq 'none' ) {
307 ## run all of them interactively
308 for my $run_cmd ( @direct_commands ) {
309 print "Executing: $run_cmd \n" ;
314 ## submit all except the first
315 foreach my $i ( 1 .. $#batch_commands ) {
316 `$batch_commands[$i]` ;
319 # handle the first according to script options
320 if ( defined $run_one ) {
321 print "Executing: $direct_commands[0] \n" ;
322 `$direct_commands[0]` ;
325 `$batch_commands[0]` ;