Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
canu_sge_emulator/qsub
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
121 lines (111 sloc)
2.86 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use strict; | |
use warnings; | |
our $SGE_ROOT=$ENV{'SGE_ROOT'} or die "SGE_ROOT not defined\n"; | |
sub wait_for_group { | |
my ($group_id)=@_; | |
WAIT: | |
while (1) { | |
my $line = `mxqdump -g $group_id`; | |
$? and exit 1; | |
my ($inq) = $line =~ /inq=(\d+)/ or die "can't parse inq from mxqdump output: $line\n"; | |
my ($run) = $line =~ /run_jobs=(\d+)/ or die "can't parse run_jobs from mxqdump output: $line\n"; | |
$inq==0 && $run==0 and return; | |
sleep 5; | |
} | |
} | |
sub sys { | |
my $pid = open my $pipe,"-|"; | |
defined $pid or die "$!\n"; | |
unless ($pid) { | |
exec @_; | |
die "$!\n"; | |
} | |
while (<$pipe>) { | |
print; | |
if (/^mxq_group_id=(\d+)/) { | |
print "Your job $1 (\"noname\") has been submitted\n"; | |
} | |
} | |
close $pipe; | |
$? and exit 1; | |
} | |
our ($environment, $nm); | |
our $job_name; | |
our $cwd; | |
our $stderr_to_stdout; | |
our $output; | |
our $memory; | |
our $slots; | |
our ($ary_low,$ary_high); | |
our $hold; | |
while (1) { | |
@ARGV or last; | |
substr($ARGV[0], 0, 1) eq '-' or last; | |
my $opt=shift; | |
if ($opt eq '--') { | |
last; | |
} elsif ($opt eq '-pe') { | |
($environment, $nm)=(shift, shift); | |
$environment eq 'fake0' or die "$environment: unknown environment\n"; | |
$nm =~ /^(\d+)$/ or die "unsupported slot format\n"; | |
$slots = $nm; | |
} elsif ($opt eq '-l') { | |
my $res_value_list=shift; | |
for my $res_value (split (",", $res_value_list)) { | |
my ($res,$value) = $res_value =~ /([^=]+)=(.+)/ or next; | |
if ($res eq 'h_vmem') { | |
if ($value =~ /(\d+)m/) { | |
$memory = $1*1024; | |
} elsif ($value =~ /(\d+)g/) { | |
$memory = $1*1024*1024; | |
} else { | |
die "can't parse h_vmem value $value\n"; | |
} | |
} | |
} | |
} elsif ($opt eq '-cwd') { | |
$cwd = 1; | |
} elsif ($opt eq '-N') { | |
$job_name=shift; | |
} elsif ($opt eq '-j') { | |
my $bool=shift; | |
if ($bool && $bool =~ /^y/) { | |
$stderr_to_stdout = 1; | |
} | |
} elsif ($opt eq '-o') { | |
$output=shift; | |
} elsif ($opt eq '-t') { | |
my $range=shift; | |
($ary_low,$ary_high) = $range =~ /^(\d+).(\d+)$/ or die "range value $range unimplemented\n"; | |
} elsif ($opt eq '-hold_jid') { | |
$hold = shift; | |
$hold =~ /^(\d+)$/ or die "-hold_jid format $hold not supported\n"; | |
} else { | |
die "$0: opt $opt unimplemented\n"; | |
} | |
}; | |
defined $output or die "submit without output unimplemented\n"; | |
defined $cwd or die "qsub without --cwd not implemented\n"; | |
defined $stderr_to_stdout or die "qsub without -j yes not implemented\n"; | |
if ($hold) { | |
wait_for_group($hold); | |
} | |
$memory = $slots * $memory if $slots && $memory; | |
$memory *= 2; | |
my @cmd=( | |
'mxqsub', | |
'--runtime', '3d', | |
$slots ? ('--threads', $slots) : (), | |
$memory ? ('--memory', $memory."K") : (), | |
'--group-name', $job_name, | |
); | |
if (!defined $ary_low) { | |
sys(@cmd, '--stdout', $output, '--', "$SGE_ROOT/job_startup", @ARGV); | |
} else { | |
for (my $i=$ary_low ; $i<=$ary_high ; $i++) { | |
my $ary_output=$output; | |
$ary_output =~ s/\$TASK_ID\b/$i/; | |
sys(@cmd, '--stdout', $ary_output, '--', "$SGE_ROOT/job_startup", '--ary_index', $i, @ARGV); | |
} | |
} |