-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqsub.pl
91 lines (69 loc) · 2.73 KB
/
qsub.pl
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
#!/usr/bin/env perl
# qsub wrapper script
use strict;
use warnings;
use Schedule::DRMAAc qw/ :all /;
use File::Temp();
use Cwd;
use Getopt::Std;
my %opt;
getopts('ho:', \%opt);
my $usage = <<ENDL;
Usage: perl qsub.pl -h -- [qsub args]
-o [file]: check file for non-zero size
ENDL
sub HELP_MESSAGE {
print STDERR $usage;
exit(1);
}
HELP_MESSAGE if $opt{h};
my $scriptFile = File::Temp->new(TEMPLATE => 'tempXXXXX', DIR => '/home/limr/share/tmp', SUFFIX => '.sge');
my $args = join " ", @ARGV;
while (<STDIN>) {
print $scriptFile $_;
}
close $scriptFile;
my ($error, $diagnosis) = drmaa_init(undef);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, my $jt, $diagnosis) = drmaa_allocate_job_template();
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, $diagnosis) = drmaa_set_attribute($jt, $DRMAA_REMOTE_COMMAND, $scriptFile->filename);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, $diagnosis) = drmaa_set_attribute($jt, $DRMAA_NATIVE_SPECIFICATION, $args);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, $diagnosis) = drmaa_set_attribute($jt, $DRMAA_WD, getcwd());
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, my $jobid, $diagnosis) = drmaa_run_job($jt);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, $diagnosis) = drmaa_delete_job_template($jt);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
sub signalHandler {
my ($error, $diagnosis) = drmaa_control($jobid, $DRMAA_CONTROL_TERMINATE);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
die "Received interrupt: terminating job\n";
}
$SIG{INT} = \&signalHandler;
$SIG{TERM} = \&signalHandler;
# loop to give a chance to receive sigint/sigterms
my $stat;
do {
($error, my $jobidOut, $stat, $diagnosis) = drmaa_wait($jobid, 10);
} until ($error != $DRMAA_ERRNO_EXIT_TIMEOUT);
# pull all exit-related codes
($error, my $exitStatus, $diagnosis) = drmaa_wexitstatus($stat);
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, my $aborted, $diagnosis) = drmaa_wifaborted( $stat );
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, my $signaled, $diagnosis ) = drmaa_wifsignaled( $stat );
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, my $coreDumped, $diagnosis ) = drmaa_wcoredump( $stat );
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
($error, $diagnosis) = drmaa_exit();
die drmaa_strerror($error) . "\n" . $diagnosis if $error;
if ($opt{o} && (!-e $opt{o} || !-s $opt{o})) {
sleep 60; # wait for file system to update
system("rm $opt{o}");
#print "File not removed\n" if (-e $opt{o});
die "$opt{o}: file is size 0";
}
exit $exitStatus + $aborted + $signaled + $coreDumped;