File: mcsub_pbs.in

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (112 lines) | stat: -rwxr-xr-x 4,169 bytes parent folder | download
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
#! /usr/bin/perl
#
# Perl script to generate PBS submission script 
#
# Peter Willendrup, 20161031

use POSIX;
use File::Which;
use File::Basename;
use Cwd 'abs_path';

my $nodes = "1";
my $coresprnode = "8";
my $queue = "express";
my $runtime = 1;;
my $name = "McSub_" . $ENV{'USER'} . "_" . POSIX::strftime("%Y%m%d_%H%M%S", localtime);
my $mailrcpt = "none";
my @cmdline;

for($i = 0; $i < @ARGV; $i++) {
    if($ARGV[$i] =~ /--help|-h$/) {
        $show_help=1;
    } elsif($ARGV[$i] =~ /^--nodes=([0-9\-]+)$/) {
	$nodes = $1;
    } elsif($ARGV[$i] =~ /^--cpn=([0-9\-]+)$/) {
	$coresprnode = $1;
    } elsif($ARGV[$i] =~ /^--name=([a-zA-Z0-9_]+)$/) {
	$name = $1;
    } elsif(($ARGV[$i] =~ /^-q([a-zA-Z0-9_]+)$/) ||
            ($ARGV[$i] =~ /^--queue=([a-zA-Z0-9_]+)$/)) {
        $queue = $1;
    } elsif(($ARGV[$i] =~ /^-r([0-9]+)$/) ||
            ($ARGV[$i] =~ /^--runtime=([0-9]+)$/)) {
        $runtime = $1;
    } elsif(($ARGV[$i] =~ /^-e([0-9a-zA-Z_\.\@]+)$/) ||
            ($ARGV[$i] =~ /^--email=([0-9a-zA-Z_\.\@]+)$/)) {
        $mailrcpt = $1;
    } elsif($ARGV[$i] =~ /@MCCODE_PREFIX@run/) {
	# strip any reference to @MCCODE_PREFIX@run
     } else {
        push @cmdline, $ARGV[$i]; }
}

# Figure out which mcstas/mcxtrace is currently loaded
my $mccode_path = which('@FLAVOR@');
my $mccode_version =  basename(dirname(dirname(abs_path$mccode_path)));

if (@cmdline == 0) { $show_help=1; }
if ($show_help) {
die "$0 generate PBS submission script

Usage: $0 [options] [@MCCODE_PREFIX@run params] 
 -h        --help            Show this help
 -rN       --runtime=N       Specify maximum runtime (hours) [default $runtime]
 -qQNAME   --queue=QNAME     Specify wanted SLURM queue [default '$queue']
 -e<mail>  --email=<mail>    Specify address to notify in reg. sim status [default $mailrcpt]
           --nodes=NUM       Specify wanted number of nodes [default $nodes]
           --coresprnode=NUM Specify wanted number of nodes [default $coresprnode]
           --name=NAME       Specify openPBS job name [default \"McSub_<USERNAME>_<TIMESTAMP>\"]
\n\nAfter running $0 NAME.batch is ready for submission using the sbatch command\n";
} else {
    # Write PBS script to file
    open($OUT,"> $name.batch") || die "Could not write to $name.batch!\n";
    open($OUT,"> $name.batch") || die "Could not write to $name.batch!\n";
    print $OUT "#!/bin/sh\n#\n# PBS queue script generated by $0\n\n";
    print $OUT "### Job name\n";
    print $OUT "#PBS -N $name\n";
    print $OUT "### Number of cpus\n";
    print $OUT "#PBS -lncpus=".$nodes*coresprnode."\n";
    print $OUT "### Maximum walltime\n";
    print $OUT "#PBS -l walltime=$runtime:00:00\n";
    print $OUT "### Output\n";
    print $OUT "#PBS -o $name.OUT\n";
    print $OUT "#PBS -e $name.ERR\n";
    print $OUT "### Queue name\n";
    print $OUT "#PBS -q $queue\n";
    print $OUT "\n\n";
    print $OUT "module load @FLAVOR@/$mccode_version\n";    
    print $OUT "\n";
    print $OUT "### Set up @MCCODE_PREFIX@run line\n";
    print $OUT "cd \$PBS_O_WORKDIR\n";
    print $OUT "@MCCODE_PREFIX@run --mpi=".$nodes*$coresprnode." --machines=\$PBS_NODEFILE ";
    print $OUT join(' ',@cmdline);
    if (!($mailrcpt eq "none")) {
      print $OUT "### Send mail on b)egin e)xit a)bort\n";
      print $OUT "#PBS -m abe\n";
      print $OUT "#PBS -M $mailrcpt\n";

    }
    print $OUT "\n### END of McSub script\n";
    close($OUT);
    
    print "Your batchfile \n\n--> $name.batch\n\n is now ready for submission using sbatch!\n";
    print " \n";
    print "Resources:\n";
    print "  $nodes nodes using all their cores on queue $queue, expected duration $runtime hours \n";
    print " \n";
    print "@MCCODE_PREFIX@run Command to be submitted: \n";
    print "  @MCCODE_PREFIX@run --mpi=".$nodes*coresprnode;
    print join(' ',@cmdline);    print " \n";
    print " \n";
    print "Output/error messages will go to: \n";
    print "  $name.stdout and $name.stderr\n";
    print " \n";
    print "\nNOTE: Please compile your instrumentfile using\n";
    print "        @MCCODE_PREFIX@run --mpi -c -n0 instrument.instr\n";
    print "      before submitting!\n";
    print " \n";
}