-
Notifications
You must be signed in to change notification settings - Fork 2
/
bisect-fp
executable file
·70 lines (60 loc) · 1.89 KB
/
bisect-fp
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
#!/opt/maths/bin/perl
use strict;
use warnings;
use lib 'lib';
use List::Util qw{ sum };
use Type;
my $typename = 't';
while (@ARGV && $ARGV[0] =~ /^-/) {
my $arg = shift @ARGV;
last if $arg eq '--';
$typename = $1, next if $arg =~ /^-y(.*)/;
die "Unknown option '$arg'";
}
@ARGV == 4 or die "500 Usage: $0 n k d maxc";
my $type = Type->new($typename);
=head1 bisect-fp: find minimum check for fix_power
Given inputs I<n>, I<k>, I<d> and I<maxc>, attempts to find the
minimum C<-c> value needed to detect a I<fix_power> opportunity
for C<< f(n, k) >= d >> by bisection.
It is assumed a previous run with C<< -c I<maxc> >> did detect
the I<fix_power>, thus giving an upper bound for the bisection.
This is expected to be used by the harness to ensure that as we
refine I<optc> we don't accidentally lose this powerful optimization.
=cut
my($n, $k, $d, $maxc) = @ARGV;
my($bad, $good) = (0, $maxc);
while ($bad + 1 < $good) {
my $mid = ($good + $bad) >> 1;
if (good($type, $mid)) {
$good = $mid;
} else {
$bad = $mid;
}
}
my $time = sum(times());
printf "200 f(%s, %s) needs -c %s to find fix_power (%.2fs)\n",
$n, $k, $good, $time;
exit 0;
sub good {
my($type, $c) = @_;
my $log = sprintf "%s/bfp%s.%s-%s", $type->logpath, $n, $c, $$;
my $lines = $type->invoked('gtauseq', "bfp($n, $k)", [
'-n', $d, '-x', $d, '-c', $c, '-D',
$n, $k,
], $log);
my $good = $lines->{311} ? 1 : 0;
if ($lines->{309}) {
# Prep finished, frequency 36.91 (184.980s)
return $good;
}
if ($lines->{402}) {
# The bisect is irrelevant, because a suitable opt_c shows
# the target is impossible.
printf "402 f(%s, %s) all values disallowed with -c %s (%.2fs)\n",
$n, $k, $c, sum(times());
exit 0;
}
# Not an expected result.
die "501 Error parsing logs from '$log'\n";
}