blib/lib/HPC/Runner/Command/submit_jobs/Plugin/SGE.pm

filter: Statementstmt 33.9% 19 / 56 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 2 / 2 totaltotal 32.5% 26 / 80 CC 9 SCAR 29.5
CC
9
Cov
27%
submit_jobs
30.0
update_job_deps
30.0
__ANON__
2.0
CRAP 19.2
« blib/lib/HPC/Runner/Command/Utils/Base.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/ResolveDeps/BuildTaskDeps.pm »
1 package HPC::Runner::Command::submit_jobs::Plugin::SGE;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Temp qw/ tempfile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 with 'HPC::Runner::Command::submit_jobs::Plugin::Role::Log';
11  
12 =head1 HPC::Runner::Command::Plugin::Scheduler::Slurm;
13  
14 =cut
15  
16 1 has 'submit_command' => (
17 is => 'rw',
18 isa => 'Str',
19 default => 'qsub',
20 );
21  
22 has 'template_file' => (
23 is => 'rw',
24 isa => 'Str',
25 default => sub {
26 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
27  
28 0 my ( $fh, $filename ) = tempfile();
29  
30 0 my $tt = <<EOF;
31 #!/usr/bin/env bash
32 #
33 #$ -N [% JOBNAME %]
34 #$ -S /bin/bash
35 #$ -cwd
36 [% IF job.has_queue %]
37 #$-q [% job.queue %]
38 [% END %]
39 #$ -pe smp [% job.cpus_per_task %]
40 [% IF job.has_walltime %]
41 #$ -l h_rt=[% job.walltime %]
42 [% END %]
43 #$ -j y
44 #$ -o [% OUT %]
45 [% IF job.has_mem %]
46 #$ -l mh_vem=[% job.mem %]
47 [% END %]
48 [% IF ARRAY_STR %]
49 #$ -t=[% ARRAY_STR %]
50 [% END %]
51  
52 [% IF AFTEROK %]
53 #$ -hold_jid=[% AFTEROK %]
54 [% END %]
55  
56 [% IF MODULES %]
57 module load [% MODULES %]
58 [% END %]
59  
60 [% IF job.has_conda_env %]
61 source activate [% job.conda_env %]
62 [% END %]
63  
64  
65 [% COMMAND %]
66 EOF
67  
68 0 print $fh $tt;
69 0 return $filename;
70 },
71 1 predicate => 'has_template_file',
72 clearer => 'clear_template_file',
73 documentation =>
74 q{Path to Slurm template file if you do not wish to use the default}
75 );
76  
77 =head2 Subroutines
78  
79 =cut
80  
81 =head3 submit_jobs
82  
83 Submit jobs to slurm queue using PBS.
84  
85 Format is
86  
87 "Your job <job_id> ("<job_name>") has been submitted"
88  
89 =cut
90  
91 sub submit_jobs {
92 0 ▶ my $self = shift;
Subroutine submit_jobs: not called CC=5 SCAR=34.0
Pod documented
93  
94 0 my ( $exitcode, $stdout, $stderr ) =
95 $self->submit_to_scheduler(
96 $self->submit_command . " " . $self->slurmfile );
97 0 sleep(5);
98  
99 0 ▶ if ( $exitcode != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exitcode != 0) 0 0 0
100 0 $self->log->fatal("Job was not submitted successfully");
101 0 ▶ $self->log->warn( "STDERR: " . $stderr ) if $stderr;
Branch: 1 branch
BranchTrueFalseTotal
if $stderr 0 0 0
102 0 ▶ $self->log->warn( "STDOUT: " . $stdout ) if $stdout;
Branch: 1 branch
BranchTrueFalseTotal
if $stdout 0 0 0
103 }
104  
105 # my $jobid = $stdout;
106 0 my $jobid;
107 0 ($jobid) = $stdout =~ m/Your job (\d.*) \(/;
108  
109 0 ▶ if ( !$jobid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $jobid) { } 0 0 0
110 0 $self->job_failure;
111 }
112 else {
113 0 $self->log->debug(
114 "Submited job " . $self->slurmfile . "\n\tWith SGE jobid $jobid" );
115 }
116  
117 0 return $jobid;
118 }
119  
120 =head3 update_job_deps
121  
122 Update the job dependencies if using job_array (not batches)
123  
124 NOTE - Task dependencies may not be supported.
125  
126  
127 =cut
128  
129 sub update_job_deps {
130 0 ▶ my $self = shift;
Subroutine update_job_deps: not called CC=5 SCAR=34.0
Pod documented
131  
132 0 ▶ return unless $self->has_array_deps;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_array_deps 0 0 0
133  
134 0 $self->log->warn('Task dependencies in SGE is still very experimental!');
135 0 $self->log->warn( 'Please raise any problems as an issue at github.' . "\n"
136 . "\thttp://github.com/biosails/HPC-Runner-Command" );
137  
138 0 ▶ while ( my ( $current_task, $v ) = each %{ $self->array_deps } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->array_deps;}) 0 0 0
139  
140 0 my $cmd;
141 0 ▶ if ( $self->use_batches ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_batches) { } 0 0 0
142 0 my $dep_tasks = join( ':', @$v );
143 0 $cmd = "qalter -hold_jid \"$dep_tasks\" $current_task ";
144 }
145 else {
146 0 foreach my $tv ( @{$v} ) {
147 0 my @tmp = split( '_', $tv );
148 0 $tv = $tmp[0] . '[' . $tmp[1] . ']';
149 }
150  
151 0 my @tmp = split( '_', $current_task );
152 0 $current_task = $tmp[0] . '[' . $tmp[1] . ']';
153  
154 0 my $dep_tasks = join( ':', @$v );
155 0 $cmd = "qalter -hold_jid \"$dep_tasks\" \"$current_task\" ";
156 }
157  
158 0 $self->submit_to_scheduler($cmd);
159 }
160 }
161  
162 1 1;
« blib/lib/HPC/Runner/Command/Utils/Base.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/ResolveDeps/BuildTaskDeps.pm »