« blib/lib/HPC/Runner/Command/submit_jobs/Plugin/SGE.pm
↑ Summary
blib/lib/HPC/Runner/Command/stats/Logger/JSON/Long.pm »
| 1 | package HPC::Runner::Command::submit_jobs::Utils::Scheduler::ResolveDeps::BuildTaskDeps; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Memoize; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use List::MoreUtils qw(first_index); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Array::Compare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use List::Util qw(first); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 HPC::Runner::Command::submit_jobs::Utils::Scheduler::ResolveDeps::BuildTaskDeps | ||||||||||
| 11 | |||||||||||
| 12 | Iterate over the batches and get the the matching TASK_TAGS | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | =head3 process_all_batch_deps | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | sub process_all_batch_deps { | ||||||||||
| 21 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
process_all_batch_deps: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | return if $self->jobs->{ $self->current_job }->submission_failure; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | ▶ | return unless $self->jobs->{ $self->current_job }->submit_by_tags; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | ▶ | return unless $self->jobs->{ $self->current_job }->has_deps; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 0 | my $batch_tags = $self->batch_tags->{ $self->current_job }; | |||||||||
| 28 | 0 | my $scheduler_index = {}; | |||||||||
| 29 | |||||||||||
| 30 | 0 | foreach my $dep ( @{ $self->jobs->{ $self->current_job }->deps } ) { | |||||||||
| 31 | 0 | ▶ | next unless $self->jobs->{$dep}->submit_by_tags; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | my $dep_tags = $self->batch_tags->{$dep}; | |||||||||
| 33 | |||||||||||
| 34 | ##If they are the same AND UNIQ - and they probably are - | ||||||||||
| 35 | ## each element of the array depends upon the same index in the dep array | ||||||||||
| 36 | # if ( check_equal_batch_tags( $batch_tags, $dep_tags ) ) { | ||||||||||
| 37 | # my $sched_array = build_equal_batch_tags( scalar @{$batch_tags} ); | ||||||||||
| 38 | # $scheduler_index->{$dep} = $sched_array; | ||||||||||
| 39 | # } | ||||||||||
| 40 | # else { | ||||||||||
| 41 | # my $sched_array = | ||||||||||
| 42 | # build_unequal_batch_tags( $batch_tags, $dep_tags ); | ||||||||||
| 43 | # $scheduler_index->{$dep} = $sched_array; | ||||||||||
| 44 | # } | ||||||||||
| 45 | 0 | my $sched_array = | |||||||||
| 46 | build_unequal_batch_tags( $batch_tags, $dep_tags ); | ||||||||||
| 47 | 0 | $scheduler_index->{$dep} = $sched_array; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | return $scheduler_index; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | ##TODO Task Tags should go in its own module | ||||||||||
| 54 | |||||||||||
| 55 | =head3 build_unequal_batch_tags | ||||||||||
| 56 | |||||||||||
| 57 | When they are not the same we have to search | ||||||||||
| 58 | |||||||||||
| 59 | =cut | ||||||||||
| 60 | |||||||||||
| 61 | 1 | memoize('build_unequal_batch_tags'); | |||||||||
| 62 | |||||||||||
| 63 | sub build_unequal_batch_tags { | ||||||||||
| 64 | 0 | ▶ | my $batch_tags = shift; | ||||||||
|
Subroutine
build_unequal_batch_tags: not called CC=4 SCAR=30.0
| |||||||||||
| 65 | 0 | my $dep_tags = shift; | |||||||||
| 66 | |||||||||||
| 67 | 0 | my @sched_array = (); | |||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | for ( my $x = 0 ; $x < scalar @{$batch_tags} ; $x++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | my $batch_tag = $batch_tags->[$x]; | |||||||||
| 71 | 0 | my @tarray = (); | |||||||||
| 72 | 0 | ▶ | for ( my $y = 0 ; $y < scalar @{$dep_tags} ; $y++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | my $dep_tag = $dep_tags->[$y]; | |||||||||
| 74 | 0 | ▶ | push( @tarray, $y ) if search_tags( $batch_tag, $dep_tag ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | } | ||||||||||
| 76 | 0 | push( @sched_array, \@tarray ); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | return \@sched_array; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | =head3 build_equal_batch_tags | ||||||||||
| 83 | |||||||||||
| 84 | If the arrays are equal, each element depends upon the same element previously | ||||||||||
| 85 | |||||||||||
| 86 | #TODO Update this - it does not work when we have groups! | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||
| 90 | 1 | memoize('build_equal_batch_tags'); | |||||||||
| 91 | |||||||||||
| 92 | sub build_equal_batch_tags { | ||||||||||
| 93 | 0 | ▶ | my $len = shift; | ||||||||
|
Subroutine
build_equal_batch_tags: not called CC=1 SCAR=6.9
| |||||||||||
| 94 | |||||||||||
| 95 | 0 | $len = $len - 1; | |||||||||
| 96 | 0 | my @array = map { [$_] } ( 0 .. $len ); | |||||||||
| 97 | 0 | return \@array; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | =head3 check_equal_batch_tags | ||||||||||
| 101 | |||||||||||
| 102 | If they are the same AND unique each element depends upon the same element from | ||||||||||
| 103 | the other array | ||||||||||
| 104 | |||||||||||
| 105 | TODO - add back in this method to check for unique | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||
| 108 | |||||||||||
| 109 | 1 | memoize('check_equal_batch_tags'); | |||||||||
| 110 | |||||||||||
| 111 | sub check_equal_batch_tags { | ||||||||||
| 112 | 0 | ▶ | my $batch_tags = shift; | ||||||||
|
Subroutine
check_equal_batch_tags: not called CC=4 SCAR=30.0
| |||||||||||
| 113 | 0 | my $dep_tags = shift; | |||||||||
| 114 | |||||||||||
| 115 | 0 | ▶ | if ( scalar @{$batch_tags} != scalar @{$dep_tags} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 0 | return 0; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | my $comp = Array::Compare->new; | |||||||||
| 120 | 0 | ▶ | for ( my $x = 0 ; $x < scalar @{$batch_tags} ; $x++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 0 | my $tbatch_tags = $batch_tags->[$x]; | |||||||||
| 122 | 0 | my $tdep_tags = $dep_tags->[$x]; | |||||||||
| 123 | 0 | ▶ | if ( !$comp->compare( $tbatch_tags, $tdep_tags ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | return 0; | |||||||||
| 125 | } | ||||||||||
| 126 | } | ||||||||||
| 127 | 0 | return 1; | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | #TODO separate out all batches vs arrays/tasks | ||||||||||
| 131 | |||||||||||
| 132 | =head3 process_batch_deps | ||||||||||
| 133 | |||||||||||
| 134 | If a job has one or more job tags it is possible to fine tune dependencies | ||||||||||
| 135 | |||||||||||
| 136 | #HPC jobname=job01 | ||||||||||
| 137 | #HPC commands_per_node=1 | ||||||||||
| 138 | #TASK tags=Sample1 | ||||||||||
| 139 | gzip Sample1 | ||||||||||
| 140 | #TASK tags=Sample2 | ||||||||||
| 141 | gzip Sample2 | ||||||||||
| 142 | |||||||||||
| 143 | #HPC jobname=job02 | ||||||||||
| 144 | #HPC jobdeps=job01 | ||||||||||
| 145 | #HPC commands_per_node=1 | ||||||||||
| 146 | #TASK tags=Sample1 | ||||||||||
| 147 | fastqc Sample1 | ||||||||||
| 148 | #TASK tags=Sample2 | ||||||||||
| 149 | fastqc Sample2 | ||||||||||
| 150 | |||||||||||
| 151 | job01 - Sample1 would be submitted as schedulerid 1234 | ||||||||||
| 152 | job01 - Sample2 would be submitted as schedulerid 1235 | ||||||||||
| 153 | |||||||||||
| 154 | job02 - Sample1 would be submitted as schedulerid 1236 - with dep on 1234 (with no job tags this would be 1234, 1235) | ||||||||||
| 155 | job02 - Sample2 would be submitted as schedulerid 1237 - with dep on 1235 (with no job tags this would be 1234, 1235) | ||||||||||
| 156 | |||||||||||
| 157 | ##DEPRACATED - process_all_batch_deps | ||||||||||
| 158 | |||||||||||
| 159 | =cut | ||||||||||
| 160 | |||||||||||
| 161 | sub process_batch_deps { | ||||||||||
| 162 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
process_batch_deps: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 163 | 0 | my $batch = shift; | |||||||||
| 164 | |||||||||||
| 165 | 0 | ▶ | return if $self->jobs->{ $self->current_job }->submission_failure; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | 0 | ▶ | return unless $self->jobs->{ $self->current_job }->submit_by_tags; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | 0 | ▶ | return unless $self->jobs->{ $self->current_job }->has_deps; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 168 | |||||||||||
| 169 | 0 | my $tags = $batch->batch_tags; | |||||||||
| 170 | |||||||||||
| 171 | 0 | return $self->search_batches( $self->jobs->{ $self->current_job }->deps, | |||||||||
| 172 | $tags ); | ||||||||||
| 173 | } | ||||||||||
| 174 | |||||||||||
| 175 | =head3 search_batches | ||||||||||
| 176 | |||||||||||
| 177 | search the batches for a particular scheduler id | ||||||||||
| 178 | |||||||||||
| 179 | #TODO update this to search across all batches - they are usually the same | ||||||||||
| 180 | instead of per batch, create an array of array for all batches | ||||||||||
| 181 | |||||||||||
| 182 | |||||||||||
| 183 | [['Sample01'], ['Sample03']] | ||||||||||
| 184 | |||||||||||
| 185 | =cut | ||||||||||
| 186 | |||||||||||
| 187 | sub search_batches { | ||||||||||
| 188 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
search_batches: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 189 | 0 | my $job_deps = shift; | |||||||||
| 190 | 0 | my $tags = shift; | |||||||||
| 191 | |||||||||||
| 192 | 0 | my $scheduler_ref = {}; | |||||||||
| 193 | |||||||||||
| 194 | 0 | foreach my $dep ( @{$job_deps} ) { | |||||||||
| 195 | 0 | ▶ | next unless $self->jobs->{$dep}->submit_by_tags; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 196 | 0 | my $dep_batches = $self->jobs->{$dep}->batches; | |||||||||
| 197 | 0 | $scheduler_ref->{$dep} = search_dep_batch_tags( $dep_batches, $tags ); | |||||||||
| 198 | } | ||||||||||
| 199 | |||||||||||
| 200 | 0 | return $scheduler_ref; | |||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | =head3 search_dep_batch_tags | ||||||||||
| 204 | |||||||||||
| 205 | =cut | ||||||||||
| 206 | |||||||||||
| 207 | 1 | memoize('search_dep_batch_tags'); | |||||||||
| 208 | |||||||||||
| 209 | sub search_dep_batch_tags { | ||||||||||
| 210 | 0 | ▶ | my $dep_batches = shift; | ||||||||
|
Subroutine
search_dep_batch_tags: not called CC=3 SCAR=24.8
| |||||||||||
| 211 | 0 | my $tags = shift; | |||||||||
| 212 | |||||||||||
| 213 | 0 | my @scheduler_index = (); | |||||||||
| 214 | 0 | my $x = 0; | |||||||||
| 215 | 0 | foreach my $dep_batch ( @{$dep_batches} ) { | |||||||||
| 216 | 0 | ▶ | push( @scheduler_index, $x ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 217 | if search_tags( $dep_batch->batch_tags, $tags ); | ||||||||||
| 218 | 0 | $x++; | |||||||||
| 219 | } | ||||||||||
| 220 | |||||||||||
| 221 | 0 | return \@scheduler_index; | |||||||||
| 222 | } | ||||||||||
| 223 | |||||||||||
| 224 | =head3 search_tags | ||||||||||
| 225 | |||||||||||
| 226 | #TODO Update this - we shouldn't check for searches and search separately | ||||||||||
| 227 | Check for matching tags. We match against any | ||||||||||
| 228 | |||||||||||
| 229 | job02 depends on job01 | ||||||||||
| 230 | |||||||||||
| 231 | job01 batch01 has tags Sample1,Sample2 | ||||||||||
| 232 | job01 batch02 has tags Sample3 | ||||||||||
| 233 | |||||||||||
| 234 | job02 batch01 has tags Sample1 | ||||||||||
| 235 | |||||||||||
| 236 | job02 batch01 depends upon job01 batch01 - because it has an overlap | ||||||||||
| 237 | But not job01 batch02 | ||||||||||
| 238 | |||||||||||
| 239 | =cut | ||||||||||
| 240 | |||||||||||
| 241 | 1 | memoize('search_tags'); | |||||||||
| 242 | |||||||||||
| 243 | sub search_tags { | ||||||||||
| 244 | 0 | ▶ | my $batch_tags = shift; | ||||||||
|
Subroutine
search_tags: not called CC=3 SCAR=24.8
| |||||||||||
| 245 | 0 | my $search_tags = shift; | |||||||||
| 246 | |||||||||||
| 247 | 0 | foreach my $batch_tag ( @{$batch_tags} ) { | |||||||||
| 248 | 0 | ▶ | my $s = first { "$_" eq $batch_tag } @{$search_tags}; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 249 | 0 | ▶ | return $s if $s; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 250 | } | ||||||||||
| 251 | |||||||||||
| 252 | 0 | return 0; | |||||||||
| 253 | } | ||||||||||
| 254 | |||||||||||
| 255 | 1 | 1; | |||||||||