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
|
#! /usr/bin/perl
#
# Perl script to generate SLURM submission script
#
# Peter Willendrup, 20161031
use POSIX;
use File::Which;
use File::Basename;
use Cwd 'abs_path';
my $nodes = "1";
my $queue = "quark";
my $MPImodule = "openmpi/4.0_gcc831";
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] =~ /^--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] =~ /^--mpimodule=([0-9a-zA-Z_\.\@]+)$/) {
$MPImodule = $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 SLURM 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']
--mpimodule=MODULE Specify wanted MPI module [default '$MPImodule']
-e<mail> --email=<mail> Specify address to notify in reg. sim status [default $mailrcpt]
--nodes=NUM Specify wanted number of nodes [default $nodes]
--name=NAME Specify slurm job name [default \"McSub_<USERNAME>_<TIMESTAMP>\"]
\n\nAfter running $0 NAME.batch is ready for submission using the sbatch command\n";
} else {
# Write slurm script to STDOUT
open($OUT,"> $name.batch") || die "Could not write to $name.batch!\n";
print $OUT "#!/bin/bash\n#\n# SLURM queue script generated by $0\n\n";
print $OUT "#SBATCH --job-name=$name\n";
print $OUT "#SBATCH --error=$name.err\n";
print $OUT "#SBATCH --output=$name.out\n";
print $OUT "#SBATCH --nodes $nodes\n";
print $OUT "#SBATCH --partition $queue\n";
print $OUT "#SBATCH --time=$runtime:00:00\n";
print $OUT "# the --exclusive is needed when running OpenMPI\n";
print $OUT "# it will all cores on the allocated nodes\n";
print $OUT "#SBATCH --exclusive \n";
print $OUT "source /etc/profile.d/modules.sh\n";
print $OUT "module load @FLAVOR@/$mccode_version\n";
print $OUT "module load ${MPImodule}\n";
print $OUT "\n\n";
print $OUT "### Set up @MCCODE_PREFIX@run line\n";
print $OUT "@MCCODE_PREFIX@run --mpi=auto ";
print $OUT join(' ',@cmdline)."\n";
if (!($mailrcpt eq "none")) {
print $OUT "### Set up email status reports \n";
print $OUT "#SBATCH --mail-type=END\n";
print $OUT "#SBATCH --mail-user=$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=\$NUMCORES ";
print join(' ',@cmdline); print " \n";
print " \n";
print "module $MPImodule will be used for MPI compilation/execution\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";
}
|