submit_km3net_xsec_calc_jobs.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 #----------------------------------------------------------------------
4 # Submit jobs for calculating GENIE cross section splines for all the
5 # nuclear targets in the km3net detector geometries,
6 # as requested by Dimitris Lennis.
7 #
8 # Syntax:
9 # shell% perl submit_km3net_xsec_calc_jobs.pl <options>
10 #
11 # Options:
12 # --version : GENIE version number
13 # [--arch] : <SL4_32bit, SL5_64bit>, default: SL5_64bit
14 # [--production] : default: <version>
15 # [--cycle] : default: 01
16 # [--use-valgrind] : default: off
17 # [--batch-system] : <PBS, LSF, slurm>, default: PBS
18 # [--queue] : default: prod
19 # [--softw-topdir] : default: /opt/ppd/t2k/softw/GENIE
20 #
21 # Notes:
22 # * Use GENIE gspladd utility to merge the job outputs
23 #
24 # Tested at the RAL/PPD Tier2 PBS batch farm.
25 #
26 # Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
27 # STFC, Rutherford Appleton Lab
28 #----------------------------------------------------------------------
29 
30 use File::Path;
31 
32 # inputs
33 #
34 $iarg=0;
35 foreach (@ARGV) {
36  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
37  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
38  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
39  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
40  if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
41  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
42  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
43  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
44  $iarg++;
45 }
46 die("** Aborting [Undefined GENIE version. Use the --version option]")
47 unless defined $genie_version;
48 
49 $use_valgrind = 0 unless defined $use_valgrind;
50 $arch = "SL5_64bit" unless defined $arch;
51 $production = "$genie_version" unless defined $production;
52 $cycle = "01" unless defined $cycle;
53 $batch_system = "PBS" unless defined $batch_system;
54 $queue = "prod" unless defined $queue;
55 $softw_topdir = "/opt/ppd/t2k/softw/GENIE" unless defined $softw_topdir;
56 $genie_setup = "$softw_topdir/builds/$arch/$genie_version-setup";
57 $jobs_dir = "$softw_topdir/scratch/xsec\_km3net-$production\_$cycle/";
58 $freenucsplines = "$softw_topdir/data/job_inputs/xspl/gxspl-vN-UHE-$genie_version.xml";
59 $nkots = 100;
60 $emax = 500;
61 $neutrinos = "12,-12,14,-14";
62 %targets = (
63  'B10' => '1000050100',
64  'B11' => '1000050110',
65  'C12' => '1000060120',
66  'Na23' => '1000110230',
67  'O16' => '1000080160',
68  'O18' => '1000080180',
69  'Mg24' => '1000120240',
70  'Mg25' => '1000120250',
71  'Mg26' => '1000120260',
72  'Al27' => '1000130270',
73  'Si28' => '1000140280',
74  'Si29' => '1000140290',
75  'Si30' => '1000140300',
76  'S32' => '1000160320',
77  'S33' => '1000160330',
78  'S34' => '1000160340',
79  'Cl35' => '1000170350',
80  'Cl37' => '1000170370',
81  'K39' => '1000190390',
82  'K41' => '1000190410',
83  'Ca40' => '1000200400',
84  'Ca42' => '1000200420',
85  'Ca44' => '1000200440',
86  'Fe54' => '1000260540',
87  'Fe56' => '1000260560',
88  'Fe57' => '1000260570',
89  'Fe58' => '1000260580' );
90 
91 # make the jobs directory
92 #
93 mkpath ($jobs_dir, {verbose => 1, mode=>0777});
94 
95 #
96 # loop over nuclear targets & submit jobs
97 #
98 while( my ($tgt_name, $tgt_code) = each %targets ) {
99 
100  $fntemplate = "$jobs_dir/job_$tgt_name";
101  $grep_pipe = "grep -B 100 -A 30 -i \"warn\\|error\\|fatal\"";
102  $gmkspl_opt = "-p $neutrinos -t $tgt_code -n $nkots -e $emax --input-cross-sections $freenucsplines --output-cross-sections gxspl_$tgt_name.xml";
103  $gmkspl_cmd = "gmkspl $gmkspl_opt | $grep_pipe &> $fntemplate.mkspl.log";
104  print "@@ exec: $gmkspl_cmd \n";
105 
106  #
107  # submit
108  #
109 
110  # PBS case
111  if($batch_system eq 'PBS') {
112  $batch_script = "$fntemplate.pbs";
113  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
114  print PBS "#!/bin/bash \n";
115  print PBS "#PBS -N $tgt_name \n";
116  print PBS "#PBS -o $fntemplate.pbsout.log \n";
117  print PBS "#PBS -e $fntemplate.pbserr.log \n";
118  print PBS "source $genie_setup \n";
119  print PBS "cd $jobs_dir \n";
120  print PBS "$gmkspl_cmd \n";
121  close(PBS);
122  `qsub -q $queue $batch_script`;
123  } #PBS
124 
125  # LSF case
126  if($batch_system eq 'LSF') {
127  $batch_script = "$fntemplate.sh";
128  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
129  print LSF "#!/bin/bash \n";
130  print LSF "#BSUB-j $tgt_name \n";
131  print LSF "#BSUB-q $queue \n";
132  print LSF "#BSUB-o $fntemplate.pbsout.log \n";
133  print LSF "#BSUB-e $fntemplate.pbserr.log \n";
134  print LSF "source $genie_setup \n";
135  print LSF "cd $jobs_dir \n";
136  print LSF "$gmkspl_cmd \n";
137  close(LSF);
138  `bsub < $batch_script`;
139  } #LSF
140 
141  # slurm case
142  if($batch_system eq 'slurm') {
143  $batch_script = "$fntemplate.sh";
144  open(SLURM, ">$batch_script") or die("Can not create the SLURM batch script");
145  print SLURM "#!/bin/bash \n";
146  print SLURM "#SBATCH-p $queue \n";
147  print SLURM "#SBATCH-o $fntemplate.pbsout.log \n";
148  print SLURM "#SBATCH-e $fntemplate.pbserr.log \n";
149  print SLURM "source $genie_setup \n";
150  print SLURM "cd $jobs_dir \n";
151  print SLURM "$gmkspl_cmd \n";
152  close(SLURM);
153  `sbatch --job-name=$tgt_name $batch_script`;
154  } #slurm
155 }
156