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