| 1 | package HPC::Runner::Command::submit_jobs::Utils::Scheduler::Files; | ||||||||||
| 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 IO::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | #Travis test fails without this | ||||||||||
| 9 | 1 | ▶ | use IO::Interactive; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use File::Path qw(make_path remove_tree); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | =head1 HPC::Runner::Command::submit_jobs::Utils::Scheduler::Files | ||||||||||
| 16 | |||||||||||
| 17 | Take care of all file operations | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | =head2 Attributes | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | =head3 cmdfile | ||||||||||
| 26 | |||||||||||
| 27 | File of commands for mcerunner | ||||||||||
| 28 | Is cleared at the end of each slurm submission | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 1 | has 'cmdfile' => ( | |||||||||
| 33 | traits => ['String'], | ||||||||||
| 34 | default => q{}, | ||||||||||
| 35 | is => 'rw', | ||||||||||
| 36 | isa => 'Str', | ||||||||||
| 37 | required => 0, | ||||||||||
| 38 | handles => { clear_cmdfile => 'clear', }, | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | =head3 slurmfile | ||||||||||
| 42 | |||||||||||
| 43 | File generated from slurm template | ||||||||||
| 44 | |||||||||||
| 45 | Job submission file | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | 1 | has 'slurmfile' => ( | |||||||||
| 50 | traits => ['String'], | ||||||||||
| 51 | default => q{}, | ||||||||||
| 52 | is => 'rw', | ||||||||||
| 53 | isa => 'Str', | ||||||||||
| 54 | required => 0, | ||||||||||
| 55 | handles => { clear_slurmfile => 'clear', }, | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | has job_files => ( | ||||||||||
| 59 | is => 'rw', | ||||||||||
| 60 | isa => 'HashRef', | ||||||||||
| 61 | default => sub { | ||||||||||
| 62 | 0 | ▶ | return {}; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 63 | } | ||||||||||
| 64 | 1 | ); | |||||||||
| 65 | |||||||||||
| 66 | =head2 Subroutines | ||||||||||
| 67 | |||||||||||
| 68 | =cut | ||||||||||
| 69 | |||||||||||
| 70 | =head3 resolve_project | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | sub resolve_project { | ||||||||||
| 75 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
resolve_project: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 76 | 0 | my $counter = shift; | |||||||||
| 77 | |||||||||||
| 78 | 0 | my $jobname; | |||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | if ( $self->has_project ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | $jobname = $self->project . "_" . $counter . "_" . $self->current_job; | |||||||||
| 82 | } | ||||||||||
| 83 | else { | ||||||||||
| 84 | 0 | $jobname = $counter . "_" . $self->current_job; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | return $jobname; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | =head3 prepare_files | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | #TODO I think we will get rid of this | ||||||||||
| 95 | |||||||||||
| 96 | sub prepare_files { | ||||||||||
| 97 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
prepare_files: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | make_path( $self->outdir ) unless -d $self->outdir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | |||||||||||
| 101 | 0 | $self->prepare_sched_file; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | =head3 prepare_counter | ||||||||||
| 105 | |||||||||||
| 106 | Prepare the counter. It is 001, 002, etc instead of 1, 2 etc | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||
| 109 | |||||||||||
| 110 | sub prepare_counter { | ||||||||||
| 111 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
prepare_counter: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 112 | |||||||||||
| 113 | 0 | my $batch_counter = $self->batch_counter; | |||||||||
| 114 | 0 | $batch_counter = sprintf( "%03d", $batch_counter ); | |||||||||
| 115 | |||||||||||
| 116 | 0 | my $job_counter = $self->job_counter; | |||||||||
| 117 | 0 | $job_counter = sprintf( "%03d", $job_counter ); | |||||||||
| 118 | |||||||||||
| 119 | 0 | return ( $batch_counter, $job_counter ); | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | =head3 prepare_sched_files | ||||||||||
| 123 | |||||||||||
| 124 | =cut | ||||||||||
| 125 | |||||||||||
| 126 | sub prepare_sched_file { | ||||||||||
| 127 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
prepare_sched_file: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 128 | |||||||||||
| 129 | #$DB::single = 2; | ||||||||||
| 130 | |||||||||||
| 131 | 0 | my ( $batch_counter, $job_counter ) = $self->prepare_counter; | |||||||||
| 132 | |||||||||||
| 133 | 0 | ▶ | make_path( $self->outdir ) unless -d $self->outdir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | |||||||||||
| 135 | #If we are using job arrays there will only be one per batch | ||||||||||
| 136 | |||||||||||
| 137 | 0 | my $jobname = $self->resolve_project($job_counter); | |||||||||
| 138 | |||||||||||
| 139 | 0 | ▶ | if ( $self->use_batches ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | 0 | $self->slurmfile( | |||||||||
| 141 | File::Spec->catdir($self->outdir , "$jobname" . "_" . $batch_counter . ".sh") ); | ||||||||||
| 142 | } | ||||||||||
| 143 | else { | ||||||||||
| 144 | 0 | $self->slurmfile( File::Spec->catdir($self->outdir , "$jobname" . ".sh") ); | |||||||||
| 145 | } | ||||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | =head3 prepare_batch_files_array | ||||||||||
| 149 | |||||||||||
| 150 | Write out the batch files | ||||||||||
| 151 | |||||||||||
| 152 | Old method | ||||||||||
| 153 | |||||||||||
| 154 | For job arrays this is 1 per array element | ||||||||||
| 155 | |||||||||||
| 156 | For (legacy) batches 1 file per batch | ||||||||||
| 157 | |||||||||||
| 158 | New method | ||||||||||
| 159 | |||||||||||
| 160 | One file per job - and we just have a counter to make sure we are on the right task | ||||||||||
| 161 | |||||||||||
| 162 | =cut | ||||||||||
| 163 | |||||||||||
| 164 | sub prepare_batch_files_array { | ||||||||||
| 165 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
prepare_batch_files_array: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 166 | |||||||||||
| 167 | # my $job_counter = sprintf( "%03d", $self->job_counter ); | ||||||||||
| 168 | |||||||||||
| 169 | 0 | my $job_counter = "000"; | |||||||||
| 170 | 0 | my $jobname = $self->resolve_project($job_counter); | |||||||||
| 171 | 0 | my $outfile = File::Spec->catfile( $self->outdir, $jobname . '.in' ); | |||||||||
| 172 | |||||||||||
| 173 | 0 | ▶ | if ( !-e $outfile ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 0 | ▶ | copy( $self->job_files->{ $self->current_job }->filename, $outfile ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 175 | or die print "ERROR COPYING $!"; | ||||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | 0 | $self->cmdfile($outfile); | |||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | #TODO Write a file per job - not per task | ||||||||||
| 182 | # sub write_batch_file { | ||||||||||
| 183 | # my $self = shift; | ||||||||||
| 184 | # my $command = shift; | ||||||||||
| 185 | # | ||||||||||
| 186 | # make_path( $self->outdir ) unless -d $self->outdir; | ||||||||||
| 187 | # | ||||||||||
| 188 | # my $fh = IO::File->new( $self->cmdfile, q{>} ) | ||||||||||
| 189 | # or die print "Error opening file " . $self->cmdfile . " " . $! . "\n"; | ||||||||||
| 190 | # | ||||||||||
| 191 | # print $fh $command if defined $fh && defined $command; | ||||||||||
| 192 | # $fh->close; | ||||||||||
| 193 | # } | ||||||||||
| 194 | |||||||||||
| 195 | 1 | 1; | |||||||||