Skip to content

Commit

Permalink
Tweak binarytrees-pool based on feedback (#26009)
Browse files Browse the repository at this point in the history
Tweak `binarytrees-pool` based on feedback. Many of the changes are
cosmetic (changing how constants are written) and others improve the
portability (making sure enough memory is available when running with
limited cores).

[Reviewed by @bradcray]
  • Loading branch information
jabraham17 authored Oct 1, 2024
2 parents 0c094d6 + 6ed42d9 commit e94bbc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 19 additions & 17 deletions test/studies/shootout/binary-trees/binarytrees-pool.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,48 @@
Brad Chamberlain
*/

use Allocators;
use Allocators, Math;

config const n = 10, // the maximum tree depth
globalPoolSize = (2 ** 31)-1,
localPoolSize = globalPoolSize;

var globalPool = new bumpPtrMemPool(globalPoolSize, alignment=0);
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
var stats: [depths] (int,int); // stores statistics for the trees
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 strTree = newWithAllocator(globalPool, unmanaged Tree, strDepth, globalPool);
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 llTree = newWithAllocator(globalPool, unmanaged Tree, maxDepth, globalPool);
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);
const iterations = 2**(maxDepth - depth + minDepth),
ps = poolSize(depth, divCeilPos(iterations, here.maxTaskPar));
var sum = 0;

forall i in 1..iterations
forall 1..iterations
with (+ reduce sum,
var localPool = new bumpPtrMemPool(localPoolSize, alignment=0)) {
const t = newWithAllocator(localPool, unmanaged Tree, depth, localPool);
var pool = new bumpPtrMemPool(ps, alignment=0)) {
const t = newWithAllocator(pool, unmanaged Tree, depth, pool);
sum += t.sum();
}
stats[depth] = (iterations, sum);
Expand Down
2 changes: 2 additions & 0 deletions test/studies/shootout/binary-trees/binarytrees-pool.execenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# this value has been shown to cause the most problems for this test
CHPL_RT_NUM_THREADS_PER_LOCALE=3

0 comments on commit e94bbc7

Please sign in to comment.