Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions binary-trees.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ end library;

define module binary-trees
use common-dylan, exclude: { format-to-string };
use format;
use format-out;
use threads;
end module;

define constant <tree> = false-or(<node>);
Expand Down Expand Up @@ -43,14 +45,27 @@ begin

let long-lived-tree = build(max-depth);

for (d from min-depth to max-depth by 2)
let size = floor/(max-depth - min-depth, 2) + 1;
let messages = make(<vector>, size: size);
let threads = make(<vector>, size: size);
for (i from 0,
d from min-depth to max-depth by 2)
let iterations = ash(1, max-depth - d + min-depth);
for (i from 1 to iterations,
c = 0 then c + build(d).check)
finally
format-out("%d\t trees of depth %d\t check: %d\n", iterations, d, c);
end for;
local method loop()
for (_ from 1 to iterations,
c = 0 then c + build(d).check)
finally
messages[i] := format-to-string("%d\t trees of depth %d\t check: %d", iterations, d, c);
end for;
end;
threads[i] := make(<thread>, function: loop);
end for;
for (thread in threads)
thread & join-thread(thread);
end;
for (message in messages)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the order of the output important for their benchmark harness? If so, I guess you could put pair(i, msg) into messages and sort by i.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I assume the output order is important, but messages are already sorted through their indices (each task stores the result in the i-th message)

format-out("%s\n", message);
end;

format-out("long lived tree of depth %d\t check: %d\n",
max-depth, long-lived-tree.check);
Expand Down