Skip to content
Snippets Groups Projects
Commit e21e5f3a authored by Danny Auble's avatar Danny Auble
Browse files

Fix bsub to read in from stdin

parent 2323188e
No related branches found
No related tags found
No related merge requests found
...@@ -131,12 +131,16 @@ if ($ARGV[0]) { ...@@ -131,12 +131,16 @@ if ($ARGV[0]) {
foreach (@ARGV) { foreach (@ARGV) {
$script .= "$_ "; $script .= "$_ ";
} }
} else {
#print "script = $script" $interactive = 1;
foreach (<STDIN>) {
chomp($_);
$script .= "$_\n";
}
} }
#print "script = $script";
my $command; my $command = $sbatch;
my $base_command;
if (!$script) { if (!$script) {
if ($interactive) { if ($interactive) {
...@@ -147,17 +151,6 @@ if (!$script) { ...@@ -147,17 +151,6 @@ if (!$script) {
} }
} }
if (_check_script($ARGV[0])) {
$command = $base_command = "$sbatch";
} else {
$command = $base_command = "$srun";
# We need to find out the jobid we got
$command .= " -v";
$interactive = 1;
}
$command .= " -e $err_path" if $err_path; $command .= " -e $err_path" if $err_path;
$command .= " -o $out_path" if $out_path; $command .= " -o $out_path" if $out_path;
...@@ -183,74 +176,41 @@ if ($min_proc) { ...@@ -183,74 +176,41 @@ if ($min_proc) {
$command .= " -t $time" if $time; $command .= " -t $time" if $time;
$command .= " -p $partition" if $partition; $command .= " -p $partition" if $partition;
$command .= " --exclusive" if $exclusive; $command .= " --exclusive" if $exclusive;
$command .= " $script" if $script;
if ($interactive || !_check_script($ARGV[0])) {
$command .=" --wrap=\"$script\"";
} else {
$command .= " $script";
}
#print " command = $command\n"; #print " command = $command\n";
#exit; #exit;
#print "Command to run = $command\n";
# Execute the command and capture its stdout, stderr, and exit status. Note # Execute the command and capture its stdout, stderr, and exit status. Note
# that if interactive mode was requested, the standard output and standard # that if interactive mode was requested, the standard output and standard
# error are _not_ captured. # error are _not_ captured.
# Execute the command and capture the combined stdout and stderr. # Execute the command and capture the combined stdout and stderr.
if ($base_command eq $srun) { #srun my @command_output = `$command 2>&1`;
my $job_id = 0;
my $dispatch_printed = 0; #Save the command exit status.
my $launch_printed = 0; my $command_exit_status = $?;
open(PH, "$command 2>&1 |"); # or with an open pipe
while (<PH>) { # If available, extract the job ID from the command output and print
my $line = $_; # it to stdout, as done in the OpenLava version of bsub.
if ($_ !~ "srun:") { if ($command_exit_status == 0) {
print $line; my @spcommand_output=split(" ",
} elsif (!$dispatch_printed && ($_ =~ /srun: jobid \d/)) { $command_output[$#command_output]);
my @line_words=split(" ", $_); my $job_id = $spcommand_output[$#spcommand_output];
$job_id = $line_words[2]; _print_job_submitted($job_id);
chop($job_id); } else {
$dispatch_printed = 2; print("There was an error running the Slurm sbatch command.\n" .
} elsif (!$dispatch_printed && ($_ =~ /srun: job \d/)) { "The command was:\n" .
my @line_words=split(" ", $_); "'$command'\n" .
$job_id = $line_words[2]; "and the output was:\n" .
$dispatch_printed = 2; "'@command_output'\n");
} elsif (!$launch_printed && ($_ =~ /srun: launching \d/)) {
my @line_words=split(" ", $_);
my $node_name = $line_words[5];
chop($node_name);
print "<<Starting on $node_name>>\n";
$launch_printed = 1;
}
if ($dispatch_printed == 2) {
_print_job_submitted($job_id);
print "<<Waiting for dispatch ...>>\n";
$dispatch_printed = 1;
}
}
close(PH);
} elsif ($base_command eq $sbatch) {
my @command_output = `$command 2>&1`;
#Save the command exit status.
my $command_exit_status = $?;
# If available, extract the job ID from the command output and print
# it to stdout, as done in the OpenLava version of bsub.
if ($command_exit_status == 0) {
my @spcommand_output=split(" ",
$command_output[$#command_output]);
my $job_id = $spcommand_output[$#spcommand_output];
_print_job_submitted($job_id);
} else {
print("There was an error running the Slurm sbatch command.\n" .
"The command was:\n" .
"'$command'\n" .
"and the output was:\n" .
"'@command_output'\n");
}
# Exit with the command return code.
exit($command_exit_status >> 8);
} }
# Exit with the command return code.
exit($command_exit_status >> 8);
sub _get_default_partition_name { sub _get_default_partition_name {
...@@ -283,7 +243,7 @@ sub _print_job_submitted { ...@@ -283,7 +243,7 @@ sub _print_job_submitted {
sub _parse_procs { sub _parse_procs {
my ($procs_range) = @_; my ($procs_range) = @_;
# Get the max process count it if exist # Get the max process count if it exists
if ($procs_range =~ /,/) { if ($procs_range =~ /,/) {
my @sub_parts = split(/,/, $procs_range); my @sub_parts = split(/,/, $procs_range);
return $sub_parts[1]; return $sub_parts[1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment