submit.pl
Go to the documentation of this file.
1 #-------------------------------------------------------------------------------------------
2 # A script to submit a single job so as to avoid the manual creation of batch script files.
3 #
4 # Syntax:
5 # % perl submit.pl <options>
6 #
7 # Options:
8 # --cmd : Command(s) to execute
9 # --version : GENIE version number
10 # [--job-name] : default: tmp-(random_number)
11 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
12 # [--production] : default: routine_validation
13 # [--cycle] : default: 01
14 # [--batch-system] : <PBS, LSF, none>, default: PBS
15 # [--queue] : default: prod
16 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE/
17 # [--jobs-topdir] : top level dir for job files, default: /opt/ppd/t2k/softw/scratch/GENIE/
18 #
19 # Example:
20 # % perl submit.pl
21 # --cmd 'gevgen -p 14 -t 1000260560 -e 1 --cross-sections /some/path/xsec.xml \
22 # --seed 1989298 --r 100; mv gntp.100.ghep.root /some/other/path/' \
23 # --version v2.8.0 \
24 # --job-name numuFe100
25 #
26 # Author:
27 # Costas Andreopoulos <costas.andreopoulos \st stfc.ac.uk>
28 # University of Liverpool & STFC Rutherford Appleton Laboratory
29 #
30 # Copyright:
31 # Copyright (c) 2003-2020, The GENIE Collaboration
32 # For the full text of the license visit http://copyright.genie-mc.org
33 #-------------------------------------------------------------------------------------------
34 
35 #!/usr/bin/perl
36 
37 use File::Path;
38 
39 $iarg=0;
40 foreach (@ARGV) {
41  if($_ eq '--cmd') { $cmd = $ARGV[$iarg+1]; }
42  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
43  if($_ eq '--job-name') { $name = $ARGV[$iarg+1]; }
44  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
45  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
46  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
47  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
48  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
49  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
50  if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
51  $iarg++;
52 }
53 die("** Aborting [Undefined GENIE command. Use the --cmd option]")
54 unless defined $cmd;
55 die("** Aborting [Undefined GENIE version. Use the --version option]")
56 unless defined $genie_version;
57 
58 $random_num = int (rand(999999999));
59 
60 $name = "tmp-$random_num" unless defined $name;
61 $arch = "SL6.x86_64" unless defined $arch;
62 $production = "routine_validation" unless defined $production;
63 $cycle = "01" unless defined $cycle;
64 $batch_system = "PBS" unless defined $batch_system;
65 $queue = "prod" unless defined $queue;
66 $softw_topdir = "/opt/ppd/t2k/softw/GENIE" unless defined $softw_topdir;
67 $jobs_topdir = "/opt/ppd/t2k/scratch/GENIE/" unless defined $jobs_topdir;
68 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
69 $job_dir = "$jobs_topdir/$genie_version-$production\_$cycle-$name";
70 
71 # make the job directory
72 #
73 mkpath ($job_dir, {verbose => 1, mode=>0777});
74 
75 
76 # submit job
77 #
78 
79 # PBS case
80 if($batch_system eq 'PBS') {
81  $batch_script = "$job_dir/$name.pbs";
82  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
83  print PBS "#!/bin/bash \n";
84  print PBS "#PBS -N $name \n";
85  print PBS "#PBS -o $job_dir/$name.pbsout.log \n";
86  print PBS "#PBS -e $job_dir/$name.pbserr.log \n";
87  print PBS "source $genie_setup \n";
88  print PBS "cd $job_dir \n";
89  print PBS "$cmd \n";
90  close(PBS);
91  `qsub -q $queue $batch_script`;
92 } #PBS
93 
94 # LSF case
95 if($batch_system eq 'LSF') {
96  $batch_script = "$job_dir/$name.sh";
97  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
98  print LSF "#!/bin/bash \n";
99  print PBS "#BSUB-j $name \n";
100  print LSF "#BSUB-q $queue \n";
101  print LSF "#BSUB-o $job_dir/$name.lsfout.log \n";
102  print LSF "#BSUB-e $job_dir/$name.lsferr.log \n";
103  print LSF "source $genie_setup \n";
104  print LSF "cd $job_dir \n";
105  print LSF "$cmd \n";
106  `bsub < $batch_script`;
107 } #LSF
108 
109