You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
struct Node
l::Union{Node,Nothing}
r::Union{Node,Nothing}endmake(n) = n ===0?Node(nothing, nothing) :Node(make(n-1), make(n-1))
check(node) = node.l ===nothing?1:1+check(node.l) +check(node.r)
functionbinary_trees(io, n)
print(io, "stretch tree of depth $(n+1)\t check: $(check(make(n+1)))\n")
long_tree =make(n)
results =zeros(Int, Threads.nthreads())
d =4while d <= n
niter =1<< (n - d +4)
Threads.@threadsfor _ in1:niter
tid = Threads.threadid()
results[tid] +=check(make(d))
end
c =sum(results)
print(io, "$niter\t trees of depth $d\t check: $c\n")
d +=2endprint(io, "long lived tree of depth $n\t check: $(check(long_tree))\n")
endisinteractive() ||binary_trees(stdout, parse(Int, ARGS[1]))
performs quite a bit better than the submitted benchmark since it avoids spawning a bunch of workers.
The text was updated successfully, but these errors were encountered:
I'll check your version's perf out, but in past versions of Julia, multithreading binary-trees was slower than non-parallel code much less the distributed version; something to do with how the allocator behaves with multi-threading afaicr.
Something like:
performs quite a bit better than the submitted benchmark since it avoids spawning a bunch of workers.
The text was updated successfully, but these errors were encountered: