Commit f386ea2f authored by Gary Wong's avatar Gary Wong

Bug fix: usage calculation error in predict.

parent 0acfd445
...@@ -196,6 +196,7 @@ my @timeline = (); ...@@ -196,6 +196,7 @@ my @timeline = ();
my $free = 0; my $free = 0;
my %used = (); my %used = ();
my %reserved = (); my %reserved = ();
my %usedexp = ();
foreach my $reservation ( @$reservations ) { foreach my $reservation ( @$reservations ) {
my $start; my $start;
...@@ -205,30 +206,34 @@ foreach my $reservation ( @$reservations ) { ...@@ -205,30 +206,34 @@ foreach my $reservation ( @$reservations ) {
# A swapped-in experiment. Already using nodes (so no # A swapped-in experiment. Already using nodes (so no
# need to save a start event), and will later release real nodes. # need to save a start event), and will later release real nodes.
my $pid = $reservation->pid(); my $pid = $reservation->pid();
my $eid = $reservation->eid(); my $exp = $reservation->pid() . "/" . $reservation->eid();
my $id = $pidonly ? $pid : "$pid/$eid"; if( !exists( $usedexp{ $exp } ) ) {
if( !exists( $used{ $id } ) ) { $usedexp{ $exp } = 0;
$used{ $id } = 0;
$reserved{ $id } = 0;
} }
$used{ $id } += $reservation->nodes(); if( !exists( $used{ $pid } ) ) {
$end = { 'id' => $id, $used{ $pid } = 0;
$reserved{ $pid } = 0;
}
$used{ $pid } += $reservation->nodes();
$usedexp{ $exp } += $reservation->nodes();
$end = { 'pid' => $pid,
'exp' => $exp,
't' => $reservation->end(), 't' => $reservation->end(),
'used' => -$reservation->nodes(), 'used' => -$reservation->nodes(),
'reserved' => 0 }; 'reserved' => 0 };
} elsif( defined( $reservation->pid() ) ) { } elsif( defined( $reservation->pid() ) ) {
# A reservation. Uses then releases reserved nodes. # A reservation. Uses then releases reserved nodes.
$start = { 'id' => $reservation->pid(), $start = { 'pid' => $reservation->pid(),
't' => $reservation->start(), 't' => $reservation->start(),
'used' => 0, 'used' => 0,
'reserved' => $reservation->nodes() }; 'reserved' => $reservation->nodes() };
$end = { 'id' => $reservation->pid(), $end = { 'pid' => $reservation->pid(),
't' => $reservation->end(), 't' => $reservation->end(),
'used' => 0, 'used' => 0,
'reserved' => -$reservation->nodes() }; 'reserved' => -$reservation->nodes() };
} else { } else {
# Available resources. Provides nodes for all time. # Available resources. Provides nodes for all time.
$free = $reservation->nodes(); $free += $reservation->nodes();
} }
push( @timeline, $start ) if( defined( $start->{'t'} ) ); push( @timeline, $start ) if( defined( $start->{'t'} ) );
...@@ -240,25 +245,37 @@ my @events = sort { $a->{'t'} <=> $b->{'t'} } @timeline; ...@@ -240,25 +245,37 @@ my @events = sort { $a->{'t'} <=> $b->{'t'} } @timeline;
foreach my $event ( @events ) { foreach my $event ( @events ) {
last if( $event->{'t'} > $time ); last if( $event->{'t'} > $time );
my $id = $event->{'id'}; my $pid = $event->{'pid'};
if( !exists( $used{ $id } ) ) { if( !exists( $used{ $pid } ) ) {
$used{ $id } = 0; $used{ $pid } = 0;
$reserved{ $id } = 0; $reserved{ $pid } = 0;
} }
my $oldsum = $used{ $id } + $reserved{ $id }; my $oldsum = $used{ $pid } > $reserved{ $pid } ?
$used{ $pid }: $reserved{ $pid };
$used{ $id } += $event->{ 'used' }; $used{ $pid } += $event->{ 'used' };
$reserved{ $id } += $event->{ 'reserved' }; $reserved{ $pid } += $event->{ 'reserved' };
if( exists( $event->{ 'exp' } ) ) {
$usedexp{ $event->{ 'exp' } } += $event->{ 'used' };
}
my $newsum = $used{ $id } + $reserved{ $id }; my $newsum = $used{ $pid } > $reserved{ $pid } ?
$used{ $pid }: $reserved{ $pid };
$free += $oldsum - $newsum; $free += $oldsum - $newsum;
} }
foreach my $used ( sort { $used{$b} <=> $used{$a} } keys( %used ) ) { if( $pidonly ) {
my $val = $used{ $used }; foreach my $used ( sort { $used{$b} <=> $used{$a} } keys( %used ) ) {
print "$used: $val\n" if( $val > 0 ); my $val = $used{ $used };
print "$used: $val\n" if( $val > 0 );
}
} else {
foreach my $used ( sort { $usedexp{$b} <=> $usedexp{$a} } keys( %usedexp ) ) {
my $val = $usedexp{ $used };
print "$used: $val\n" if( $val > 0 );
}
} }
foreach my $reserved ( sort { $reserved{$b} <=> $reserved{$a} } foreach my $reserved ( sort { $reserved{$b} <=> $reserved{$a} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment