line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HPC::Runner::Command::submit_jobs::Utils::Scheduler::Files; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
486
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
4334
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
66
|
use IO::File; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
155
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#Travis test fails without this |
9
|
1
|
|
|
1
|
|
8
|
use IO::Interactive; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
10
|
1
|
|
|
1
|
|
43
|
use File::Path qw(make_path remove_tree); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
11
|
1
|
|
|
1
|
|
5
|
use File::Copy; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
12
|
1
|
|
|
1
|
|
4
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
13
|
1
|
|
|
1
|
|
4
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
450
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return {}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 Subroutines |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head3 resolve_project |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub resolve_project { |
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $counter = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $jobname; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ( $self->has_project ) { |
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
|
|
|
0
|
1
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
make_path( $self->outdir ) unless -d $self->outdir; |
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
|
|
|
0
|
1
|
|
my $self = shift; |
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
|
|
|
0
|
0
|
|
my $self = shift; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#$DB::single = 2; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my ( $batch_counter, $job_counter ) = $self->prepare_counter; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
make_path( $self->outdir ) unless -d $self->outdir; |
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
|
0
|
|
|
|
|
if ( $self->use_batches ) { |
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
|
|
|
0
|
1
|
|
my $self = shift; |
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
|
0
|
|
|
|
|
if ( !-e $outfile ) { |
174
|
0
|
0
|
|
|
|
|
copy( $self->job_files->{ $self->current_job }->filename, $outfile ) |
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; |