[torqueusers] set automatically a mem max ressources when the user submits a job with a nodes/cpu param
giggzounet
giggzounet at gmail.com
Tue Sep 28 00:50:59 MDT 2010
Le 28/09/2010 00:38, Gareth.Williams at csiro.au a écrit :
>> ok. but...I don't know perl or Python...perhaps when I will have a
>> boring week-end, i will try it :)
>>
>> thx for the tip!
>> Guillaume
>
> Hi Guillaume,
>
> Here's a starting point for you. It's a bit complicated - and it doesn't actually do anything. It was written to force ncpus to be set to 1 (or unset or reject the job), but that content had been taken out and just the skeleton remains. It takes account of the command line arguments as well as embedded #PBS directives. Nb. command line args override directives - and you can't readily override them with such a filter but you could reject the job and provide feedback.
>
> You would need to add your memory request at:
> # could add directives/content here
> Say (for 2GB vmem per process(or) requested):
> print "#PBS -l vmem=" . $np*2 . "GB\n";
>
> Good luck,
>
> Gareth
>
> #!/usr/bin/env perl
> use strict;
> $^W = 1; # use warnings;
> use Getopt::Long qw(:config pass_through); # for extracting -l options from ARGV
> my $nodestring;
> my $np_default = 1; # default number of ppn allocated in scheduling if not specified
> my $np_header = 0;
> my $ncpus_header = 0;
> my @lresources = ();
> my $lresource;
> my $verbose = 0; # can embed line(s) with #verbose in script to turn verbosity up
> my $debug = 0;
> my $filter = 1;
> my @savedargs = @ARGV;
> print STDERR "qsub filter: filtering script through $0, to check resources requested\n" if $verbose;
> # get requested resources from qsub args (which are also my args)
> GetOptions('l=s' =>\@lresources);
> foreach $lresource (@lresources) {
> print STDERR "qsub filter: in command line arguments found resourcestring '$lresource'\n" if $verbose;
> if ($lresource =~ /(?:^|,)nodes=([^,]+)/) {
> $np_header= &getnprocs($1); # np from nodes string
> print STDERR " found nodestring '$1'\n" if $verbose > 1;
> print STDERR " that would correspond to '$np_header' processes\n" if $verbose > 1;
> }
> if ($lresource =~ /(?:^|,)ncpus=(\d+)/) {
> $ncpus_header= $1; # ncpus if specified
> print STDERR " found ncpus '$1'\n" if $verbose > 1;
> # this is the first opportunity to bail out if $ncpus_header >1
> }
> }
>
> my $head_done = 0; # only parse header - then add extra directives
> my $np = $np_default;
> my $ncpus = 0;
> my $lineno = 0;
> my $header = "";
> while (<STDIN>) {
> $lineno++;
>
> $debug = 1 if /^#debug/; # can embed line(s) with #debug to turn debug on
> $verbose++ if /^#verbose/; # can embed line(s) with #verbose in script to turn verbosity up
> $filter = 1 if /^#filter/; # can embed line(s) with #filter to turn filtering on
> # $filter = 0 if /^#nofilter/; # can embed line(s) with #nofilter to turn filtering off
>
> unless ($filter) { print; next }
> if ($head_done) { print; next } # do not filter after header
> if ($lineno == 1 and /^:/) { print; next } # skip special null command allowed in first line
>
> unless (/^ *#/ or /^ *$/) {
> $head_done=1;
> print STDERR "qsub filter: finished processing script header\n" if $verbose > 1;
> # could add directives/content here
> }
> $header .= $_;
>
> if (/^ *#PBS/) { # parse #PBS lines
> print STDERR "qsub filter: parsing a directive line:$_" if $verbose > 1;
> @ARGV = split; # reconstruct ARGV to use with GetOptions
> shift @ARGV; # drop #PBS sentinel
> @lresources = ();
> GetOptions('l=s' =>\@lresources);
> foreach $lresource (@lresources) {
> print STDERR " found resourcestring '$lresource'\n" if $verbose > 1;
> if ($lresource =~ /(?:^|,)nodes=([^,]+)/) {
> $np = &getnprocs($1); # np from node string
> print STDERR " found nodestring '$1'\n" if $verbose > 1;
> print STDERR " that would correspond to '$np' processes\n" if $verbose > 1;
> }
> if ($lresource =~ /(?:^|,)ncpus=(\d+)/) {
> $ncpus = $1; # ncpus if specified
> print STDERR " found ncpus '$1'\n" if $verbose > 1;
> }
> }
> @ARGV = ();
> }
> # could take action here...
> print;
> }
>
> sub getnprocs {
> my $nodestring = shift;
> my $nprocs = 0;
> my @chunks = split '\+', $nodestring; #nodestring like i:property+j:ppn=k+...
> foreach my $chunk (@chunks) {
> my ($nn, $np) = (1, $np_default);
> if ($chunk =~ /^(\d+)/) {
> $nn = $1;
> }
> if ($chunk =~ /ppn=(\d+)/) {
> $np = $1;
> }
> $nprocs += $nn*$np; # sum of nodes*ppn over chunks
> }
> return $nprocs;
> }
THx a lot! I save your script...and try to modify it when I can.
Best regards,
More information about the torqueusers
mailing list