[Bio] / FortyEight / PipelineUtils.pm Repository:
ViewVC logotype

View of /FortyEight/PipelineUtils.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Wed Jan 27 17:25:32 2010 UTC (9 years, 10 months ago) by olson
Branch: MAIN
Changes since 1.1: +7 -1 lines
More tweaks.

package PipelineUtils;
use strict;

use base 'Exporter';

our @EXPORT = qw(sge_submit get_sge_deadline_arg find_fs_resource get_sge_priority);

sub sge_submit
{
    my($meta, $sge_args, $cmd) = @_;

    my @sge_opts;
    if (my $res = $meta->get_metadata("lustre_resource"))
    {
	push @sge_opts, -l => $res;
    }
    #
    # Require any node we run on to have the rast_qualified attribute.
    # This makes sure the operating environment on the node
    # has everything we need.
    #
    push(@sge_opts, -l => "rast_qualified");
    push(@sge_opts, get_sge_deadline_arg($meta));
    push(@sge_opts, get_sge_user_priority($meta));
    if (my $res = $meta->get_metadata("sge_priority"))
    {
	if (ref($res) eq 'ARRAY')
	{
	    push @sge_opts, @$res;
	}
	elsif (!ref($res))
	{
	    push @sge_opts, split(/\s+/, $res);
	}
    }

    my $sge_cmd = "qsub @sge_opts $sge_args $cmd";
    
    $meta->add_log_entry($0, $sge_cmd);

    if (!open(Q, "$sge_cmd 2>&1 |"))
    {
	die "Qsub failed: $!";
    }
    my $sge_job_id;
    my $submit_output;
    while (<Q>)
    {
	$submit_output .= $_;
	print "Qsub: $_";
	if (/Your\s+job\s+(\d+)/)
	{
	    $sge_job_id = $1;
	}
	elsif (/Your\s+job-array\s+(\d+)/)
	{
	    $sge_job_id = $1;
	}
    }
    $meta->add_log_entry($0, ["qsub_output", $submit_output]);
    if (!close(Q))
    {
	die "Qsub close failed: $!";
    }

    if (!$sge_job_id)
    {
	die "did not get job id from qsub";
    }

    return $sge_job_id;
}

sub get_sge_deadline_arg
{
    my($meta) = @_;
    if ($FIG_Config::use_deadline_scheduling)
    {
	my $dl = $meta->get_metadata("sge_deadline");
	if ($dl ne '')
	{
	    if (wantarray)
	    {
		return("-dl",  $dl);
	    }
	    else
	    {
		return "-dl $dl";
	    }
	}
    }
    return;
}

sub get_sge_user_priority
{
    my($meta) = @_;
    if ($FIG_Config::use_priority_scheduling)
    {
	my $prio = $meta->get_metadata("sge_priority");
	if (defined($prio))
	{
	    return $prio;
	}
	else
	{
	    return;
	}
    }
}

sub find_fs_resource
{
    my($job) = @_;
    my $fs_resource;
    if (my $fileserver = $job->find_job_fileserver())
    {
	if ($fileserver eq 'rast.mcs.anl.gov')
	{
	    $fs_resource = "-l local_rast";
	}
	elsif ($fileserver eq 'cgat.mcs.anl.gov')
	{
	    $fs_resource = "-l local_cgat";
	}
	elsif ($fileserver eq 'lustre')
	{
	    $fs_resource = "-l lustre_lustre1";
	}
    }

    return $fs_resource;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3