-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxpar_bisect.nt
39 lines (37 loc) · 1.42 KB
/
xpar_bisect.nt
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
module xpar_bisect;
import std.string;
void main(string[] args) {
writeln "FCC -xpar bisect tool starting.";
if (args.length != 1) raise new Error "fcc parameter arg expected! ($(args)) ";
string arg = args[0];
bool works(int xpar) {
string cmd = "fcc -o xpar_bisect_test -singlethread $arg -xpar $xpar >/dev/null";
writeln "> fcc -o xpar_bisect_test -singlethread ARGS -xpar $xpar >/dev/null";
if (0 != system toStringz cmd)
// raise new Error "Compilation failed! Aborting. ";
return false;
int res = system toStringz "./xpar_bisect_test";
return eval res == 0;
}
int low = 0, high = 1024;
writeln "Run preliminary tests .. ";
if (works -1) raise new Error "Program does not exhibit error behavior! What do you want me to do here? ";
if (!works low) raise new Error "Program doesn't work even without any optimization steps active! Cannot bisect. ";
writeln "Preliminary tests successful. Beginning search for upper limit .. ";
bool brk;
while (!brk && high) {
if (!works high) brk = true;
else high <<= 1;
}
if (!high) raise new Error "Couldn't find upper limit! ";
writeln "Test range: [$low .. $high]";
while (high != low + 1) {
int pivot = low + (high - low) / 2;
if (works pivot) low = pivot;
else high = pivot;
writeln " => [$low .. $high]";
}
writeln "Last working xpar: $low";
writeln "First broken xpar: $high";
writeln "Have a nice day. ";
}