From 020f1bcc35a3251e19083abe8ba6c9f31278bef3 Mon Sep 17 00:00:00 2001 From: Brad Chamberlain Date: Fri, 13 Dec 2024 14:56:54 -0800 Subject: [PATCH] Add a copy of binarytrees5.chpl to our submitted directory --- Signed-off-by: Brad Chamberlain --- .../submitted/binarytrees-submitted.graph | 6 +- .../shootout/submitted/binarytrees5.chpl | 96 +++++++++++++++++++ .../shootout/submitted/binarytrees5.good | 1 + .../submitted/binarytrees5.perfexecopts | 1 + .../shootout/submitted/binarytrees5.perfkeys | 1 + 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 test/studies/shootout/submitted/binarytrees5.chpl create mode 120000 test/studies/shootout/submitted/binarytrees5.good create mode 100644 test/studies/shootout/submitted/binarytrees5.perfexecopts create mode 120000 test/studies/shootout/submitted/binarytrees5.perfkeys diff --git a/test/studies/shootout/submitted/binarytrees-submitted.graph b/test/studies/shootout/submitted/binarytrees-submitted.graph index 46a57bef0b4c..a2bca43442e9 100644 --- a/test/studies/shootout/submitted/binarytrees-submitted.graph +++ b/test/studies/shootout/submitted/binarytrees-submitted.graph @@ -1,5 +1,5 @@ -perfkeys: real, real, real -graphkeys: release, submitted (3), submitted (4) -files: binarytrees.dat, binarytrees-submitted.dat, binarytrees4.dat +perfkeys: real, real, real, real +graphkeys: release, submitted (3), submitted (4), submitted (5) +files: binarytrees.dat, binarytrees-submitted.dat, binarytrees4.dat, binarytrees5.dat graphtitle: Submitted Binary Trees Shootout Benchmark (n=21) ylabel: Time (seconds) diff --git a/test/studies/shootout/submitted/binarytrees5.chpl b/test/studies/shootout/submitted/binarytrees5.chpl new file mode 100644 index 000000000000..d152250ab16f --- /dev/null +++ b/test/studies/shootout/submitted/binarytrees5.chpl @@ -0,0 +1,96 @@ +/* The Computer Language Benchmarks Game + https://salsa.debian.org/benchmarksgame-team/benchmarksgame/ + + contributed by Jade Abraham + based on the Chapel #3 version by Casey Battaglino, Ben Harshbarger, and + Brad Chamberlain +*/ + +use Allocators, Math; + +config const n = 10; // the maximum tree depth + +proc main() { + const minDepth = 4, // the shallowest tree + maxDepth = max(minDepth + 2, n), // the deepest normal tree + strDepth = maxDepth + 1, // the depth of the "stretch" tree + depths = minDepth..maxDepth by 2, // the range of depths to create + nodeSize = 24; // the size of a node + var stats: [depths] (int,int); // stores statistics for the trees + + inline proc poolSize(depth, num=1) do return num*2**(depth+1)*nodeSize; + + // + // Create the short-lived "stretch" tree, checksum it, and print its stats. + // + { + const pool = new bumpPtrMemPool(poolSize(strDepth), alignment=0), + strTree = newWithAllocator(pool, unmanaged Tree, strDepth, pool); + writeln("stretch tree of depth ", strDepth, "\t check: ", strTree.sum()); + } + + // + // Build the long-lived tree. + // + const pool = new bumpPtrMemPool(poolSize(maxDepth), alignment=0), + llTree = newWithAllocator(pool, unmanaged Tree, maxDepth, pool); + + // + // Iterate over the depths. At each depth, create the required trees in + // parallel, compute their sums, and free them. + // + for depth in depths { + const iterations = 2**(maxDepth - depth + minDepth), + ps = poolSize(depth, divCeilPos(iterations, here.maxTaskPar)); + var sum = 0; + + forall 1..iterations + with (+ reduce sum, + var pool = new bumpPtrMemPool(ps, alignment=0)) { + const t = newWithAllocator(pool, unmanaged Tree, depth, pool); + sum += t.sum(); + } + stats[depth] = (iterations, sum); + } + + // + // Print out the stats for the trees of varying depths. + // + for (depth, (numTrees, checksum)) in zip(depths, stats) do + writeln(numTrees, "\t trees of depth ", depth, "\t check: ", checksum); + + // + // Checksum the long-lived tree, print its stats, and free it. + // + writeln("long lived tree of depth ", maxDepth, "\t check: ", llTree.sum()); +} + + +// +// A simple balanced tree node class +// +class Tree { + var left, right: unmanaged Tree?; + + // + // A Tree-building initializer + // + proc init(depth, pool) { + if depth > 0 { + const d = depth - 1; + left = newWithAllocator(pool, unmanaged Tree, d, pool); + right = newWithAllocator(pool, unmanaged Tree, d, pool); + } + } + + // + // Add up tree node, freeing as we go + // + proc sum(): int { + var sum = 1; + if left { + sum += left!.sum() + right!.sum(); + } + return sum; + } +} diff --git a/test/studies/shootout/submitted/binarytrees5.good b/test/studies/shootout/submitted/binarytrees5.good new file mode 120000 index 000000000000..5db46adf5a9a --- /dev/null +++ b/test/studies/shootout/submitted/binarytrees5.good @@ -0,0 +1 @@ +binarytrees3.good \ No newline at end of file diff --git a/test/studies/shootout/submitted/binarytrees5.perfexecopts b/test/studies/shootout/submitted/binarytrees5.perfexecopts new file mode 100644 index 000000000000..a249098d8a61 --- /dev/null +++ b/test/studies/shootout/submitted/binarytrees5.perfexecopts @@ -0,0 +1 @@ +--n=21 # binarytrees5 diff --git a/test/studies/shootout/submitted/binarytrees5.perfkeys b/test/studies/shootout/submitted/binarytrees5.perfkeys new file mode 120000 index 000000000000..d5c83453d601 --- /dev/null +++ b/test/studies/shootout/submitted/binarytrees5.perfkeys @@ -0,0 +1 @@ +binarytrees3.perfkeys \ No newline at end of file