-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJob.pm
368 lines (284 loc) · 8.34 KB
/
Job.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package Job;
use strict;
use warnings;
use List::Util qw(min max);
use POSIX;
use Carp;
use Data::Dumper;
use Util qw($config);
use overload '""' => \&stringification;
my @svg_colors = (
'orange',
'green',
undef,
undef,
undef,
'red',
);
my @svg_colors_platform = (
'blue',
'green',
'yellow',
'orange',
'red',
'purple',
'brown',
);
use Exporter;
our @ISA = qw(Exporter);
use constant {
JOB_STATUS_COMPLETED => 1,
JOB_STATUS_FAILED => 0,
JOB_STATUS_CANCELED => 5,
};
our @EXPORT = qw(JOB_STATUS_COMPLETED JOB_STATUS_FAILED JOB_STATUS_CANCELED);
sub stringification {
my ($self) = @_;
return join(' ',
map {(defined $_ ? $_ : '?')} (
$self->{job_number},
$self->{submit_time},
#(defined $self->wait_time() ? $self->wait_time() : $self->original_wait_time()),
$self->{original_wait_time},
$self->{run_time},
$self->{allocated_cpus},
$self->{avg_cpu_time},
$self->{used_mem},
$self->{requested_cpus},
$self->{requested_time},
$self->{requested_mem},
$self->{status},
$self->{uid},
$self->{gid},
$self->{exec_number},
$self->{queue_number},
$self->{partition_number},
$self->{prec_job_number},
$self->{think_time_prec_job}
)
);
}
# Constructors and destructors
sub new {
my (
$class,
$job_number,
$submit_time,
$original_wait_time,
$run_time,
$allocated_cpus,
$avg_cpu_time,
$used_mem,
$requested_cpus,
$requested_time,
$requested_mem,
$status,
$uid,
$gid,
$exec_number,
$queue_number,
$partition_number,
$prec_job_number,
$think_time_prec_job,
) = @_;
my $self = {
job_number => $job_number, #1
submit_time => $submit_time, #2
original_wait_time => $original_wait_time, #3
run_time => $run_time, #4
allocated_cpus => $allocated_cpus, #5
avg_cpu_time => $avg_cpu_time, #6
used_mem => $used_mem, #7
requested_cpus => $requested_cpus, #8
requested_time => $requested_time, #9
requested_mem => $requested_mem, #10
status => $status, #11, 0 = failed, 5 = cancelled, 1 = completed
uid => $uid, #12
gid => $gid, #13
exec_number => $exec_number, #14
queue_number => $queue_number, #15
partition_number => $partition_number, #16
prec_job_number => $prec_job_number, #17
think_time_prec_job => $think_time_prec_job, #18
};
# sanity checks for some of the job fields
#$self->{status} = JOB_STATUS_CANCELED if (($self->{run_time} == 0) and ($self->{status} == JOB_STATUS_COMPLETED));
#$self->{status} = JOB_STATUS_CANCELED if $self->{status} == JOB_STATUS_FAILED;
#$self->{allocated_cpus} = $self->{requested_cpus} if ($self->{allocated_cpus} != $self->{requested_cpus});
#$self->{run_time} = $self->{requested_time} if ($self->{requested_time} < $self->{run_time});
bless $self, $class;
return $self;
}
sub copy {
my ($class, $original) = @_;
my $self = {};
%{$self} = %{$original};
bless $self, $class;
return $self;
}
sub DESTROY {
my ($self) = @_;
$self->{assigned_processors}->free_allocated_memory()
if defined $self->{assigned_processors};
return;
}
# Getters and setters
sub schedule_time {
my ($self, $schedule_time) = @_;
$self->{schedule_time} = $schedule_time if defined $schedule_time;
return $self->{schedule_time};
}
sub requested_cpus {
my ($self) = @_;
return $self->{requested_cpus};
}
sub run_time {
my ($self, $run_time) = @_;
$self->{run_time} = $run_time if (defined $run_time);
return $self->{run_time};
}
sub requested_time {
my ($self, $requested_time) = @_;
$self->{requested_time} = $requested_time if (defined $requested_time);
return $self->{requested_time};
}
sub starting_time {
my ($self, $starting_time) = @_;
$self->{starting_time} = $starting_time if defined $starting_time;
return $self->{starting_time};
}
sub submit_time {
my ($self, $submit_time) = @_;
$self->{submit_time} = $submit_time if defined $submit_time;
return $self->{submit_time};
}
sub original_wait_time {
my ($self) = @_;
return $self->{original_wait_time};
}
sub job_number {
my ($self, $job_number) = @_;
$self->{job_number} = $job_number if defined $job_number;
return $self->{job_number};
}
sub status {
my ($self, $status) = @_;
$self->{status} = $status if (defined $status);
return $self->{status};
}
sub assigned_processors {
my ($self) = @_;
return $self->{assigned_processors};
}
sub communication_level {
my ($self, $communication_level) = @_;
$self->{communication_level} = $communication_level if defined $communication_level;
return $self->{communication_level};
}
# Ending time
sub real_ending_time {
my ($self) = @_;
return $self->{starting_time} + $self->{run_time};
}
sub submitted_ending_time {
my ($self) = @_;
return $self->{starting_time} + $self->{requested_time};
}
# Stretch
sub flow_time {
my ($self) = @_;
return $self->{starting_time} - $self->{submit_time} + $self->{run_time};
}
sub bounded_stretch {
my ($self) = @_;
my $bound = $config->param('parameters.stretch_bound');
return max($self->flow_time()/max($self->{run_time}, $bound), 1);
}
sub bounded_stretch_with_cpus_squared {
my ($self, $time_limit) = @_;
$time_limit = 10 unless (defined $time_limit);
return max($self->flow_time()/(max($self->{run_time}, $time_limit) * sqrt($self->{allocated_cpus})), 1);
}
sub bounded_stretch_with_cpus_log {
my ($self, $time_limit) = @_;
$time_limit = 10 unless (defined $time_limit);
return max(($self->wait_time() + $self->{run_time}) /
(max($self->{run_time}, $time_limit) *
($self->{allocated_cpus} == 1) ? 1 : log($self->{allocated_cpus})), 1);
}
sub original_bounded_stretch {
my ($self, $time_limit) = @_;
die 'undefined job parameters' unless defined $self->{original_wait_time} and defined $self->{run_time};
return max(($self->{original_wait_time} + $self->{run_time})/max($self->{run_time}, ((defined $time_limit) ? $time_limit : 10)), 1);
}
sub stretch {
my ($self) = @_;
return $self->wait_time()/$self->{run_time};
}
sub wait_time {
my ($self) = @_;
return unless defined $self->{starting_time};
return $self->{starting_time} - $self->{submit_time};
}
sub original_run_time {
my ($self, $original_run_time) = @_;
$self->{original_run_time} = $original_run_time if defined $original_run_time;
return $self->{original_run_time};
}
# Assignment
sub unassign {
my ($self) = @_;
delete $self->{starting_time};
if (defined $self->{assigned_processors}) {
$self->{assigned_processors}->free_allocated_memory();
delete $self->{assigned_processors};
}
return;
}
sub assign {
my ($self, $starting_time, $assigned_processors) = @_;
$self->{starting_time} = $starting_time;
$self->{assigned_processors}->free_allocated_memory() if defined $self->{assigned_processors};
$self->{assigned_processors} = $assigned_processors;
return;
}
# SVG
sub svg {
my ($self, $fh, $w_ratio, $h_ratio, $current_time, $platform) = @_;
my $job_platform_level = $platform->job_relative_level_distance($self->{assigned_processors}, $self->requested_cpus());
#my $job_platform_level = $platform->job_level_distance($self->{assigned_processors});
$self->{assigned_processors}->ranges_loop(
sub {
my ($start, $end) = @_;
die "$start is after $end" if $end < $start;
#rectangle
my $x = $self->{starting_time} * $w_ratio;
my $w;
if ($self->real_ending_time() <= $current_time) {
$w = $self->{run_time} * $w_ratio;
} else {
$w = $self->{requested_time} * $w_ratio;
}
my $y = $start * $h_ratio;
my $h = $h_ratio * ($end - $start + 1);
#my $color = $svg_colors[$self->{status}];
my $color = $svg_colors_platform[$job_platform_level];
my $sw = min($w_ratio, $h_ratio) / 10;
if ($self->real_ending_time() > $current_time) {
my $x = ($self->{starting_time}+$self->{run_time}) * $w_ratio;
my $w = ($self->{requested_time}-$self->{run_time}) * $w_ratio;
print $fh "\t<rect x=\"$x\" y=\"$y\" width=\"$w\" height=\"$h\" style=\"fill:black;fill-opacity:1.0\"/>\n";
}
print $fh "\t<rect x=\"$x\" y=\"$y\" width=\"$w\" height=\"$h\" style=\"fill:$color;fill-opacity:0.2;stroke:black;stroke-width:$sw\"/>\n";
#label
$x = $w/2 + $self->{starting_time} * $w_ratio;
$y = (($start+$end+1)/2) * $h_ratio;
my $fs = min($h_ratio*($end-$start+1), $w/5);
die "negative font size :$fs ; $end ; $start $h_ratio $w $self->{run_time}" if $fs <= 0;
my $text_y = $y + $fs*0.35;
print $fh "\t<text x=\"$x\" y=\"$text_y\" fill=\"black\" font-family=\"Verdana\" text-anchor=\"middle\" font-size=\"$fs\">$self->{job_number}</text>\n";
}
);
return;
}
1;