The Computer Language
24.04 Benchmarks Game

binary-trees Julia #5 program

source code

# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# Contributed by Adam Beckmeyer. Based on code by Jarret Revels, Alex
# Arslan, Michal Stransky, Jens Adam.

using Distributed

Distributed.addprocs()

@everywhere struct Node
    leaf::Bool
    l::Node
    r::Node
    Node(l, r) = new(false, l, r)
    Node() = new(true)
end

@everywhere make(n) = n === 0 ? Node() : Node(make(n-1), make(n-1))

@everywhere check(node) =
    node.leaf ? 1 : 1 + check(node.l) + check(node.r)

function binary_trees(io, n)
    write(io, "stretch tree of depth $(n+1)\t check: $(check(make(n+1)))\n")

    long_tree = make(n)

    d = 4
    while d <= n
        niter = 1 << (n - d + 4)
        c = @distributed (+) for _ in 1:niter
            check(make(d))
        end
        write(io, "$niter\t trees of depth $d\t check: $c\n")
        d += 2
    end

    write(io, "long lived tree of depth $n\t check: $(check(long_tree))\n")
end

isinteractive() || binary_trees(stdout, parse(Int, ARGS[1]))
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
julia version 1.10.2


 Sun, 03 Mar 2024 19:29:14 GMT

MAKE:
printenv JULIA_NUM_THREADS
4

0.09s to complete and log all make actions

COMMAND LINE:
 /opt/src/julia-1.10.2/bin/julia -O3 --cpu-target=ivybridge --math-mode=ieee -p4 -- binarytrees.julia-5.julia 21

PROGRAM FAILED 


PROGRAM OUTPUT:
stretch tree of depth 22	 check: 8388607
2097152	 trees of depth 4	 check: 65011712
      From worker 4:	
      From worker 4:	[196521] signal (11.1): Segmentation fault
      From worker 4:	in expression starting at none:0
      From worker 4:	Allocations: 10188674 (Pool: 10185946; Big: 2728); GC: 10

ERROR: LoadError: TaskFailedException
Stacktrace:
 [1] wait
   @ ./task.jl:352 [inlined]
 [2] fetch
   @ ./task.jl:372 [inlined]
 [3] preduce(reducer::Function, f::Function, R::UnitRange{Int64})
   @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/macros.jl:274
 [4] binary_trees(io::IOStream, n::Int64)
   @ Main ~/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/binarytrees.julia-5.julia:32
 [5] top-level scope
   @ ~/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/binarytrees.julia-5.julia:42

    nested task error: ProcessExitedException(4)
    Stacktrace:
      [1] try_yieldto(undo::typeof(Base.ensure_rescheduled))
        @ Base ./task.jl:931
      [2] wait()
        @ Base ./task.jl:995
      [3] wait(c::Base.GenericCondition{ReentrantLock}; first::Bool)
        @ Base ./condition.jl:130
      [4] wait
        @ ./condition.jl:125 [inlined]
      [5] take_buffered(c::Channel{Any})
        @ Base ./channels.jl:477
      [6] take!(c::Channel{Any})
        @ Base ./channels.jl:471
      [7] take!(::Distributed.RemoteValue)
        @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:726
      [8] remotecall_fetch(::Function, ::Distributed.Worker, ::Function, ::Vararg{Any}; kwargs::@Kwargs{})
        @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:461
      [9] remotecall_fetch(::Function, ::Distributed.Worker, ::Function, ::Vararg{Any})
        @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:454
     [10] remotecall_fetch
        @ /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:492 [inlined]
     [11] (::Distributed.var"#175#176"{typeof(+), var"#1#2", UnitRange{Int64}, Vector{UnitRange{Int64}}, Int64, Int64})()
        @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/macros.jl:270
in expression starting at /home/dunham/all-benchmarksgame/benchmarksgame_i53330/binarytrees/tmp/binarytrees.julia-5.julia:42
Worker 4 terminated.
UNHANDLED TASK ERROR: EOFError: read end of file
Stacktrace:
 [1] (::Base.var"#wait_locked#739")(s::Sockets.TCPSocket, buf::IOBuffer, nb::Int64)
   @ Base ./stream.jl:947
 [2] unsafe_read(s::Sockets.TCPSocket, p::Ptr{UInt8}, nb::UInt64)
   @ Base ./stream.jl:955
 [3] unsafe_read
   @ ./io.jl:774 [inlined]
 [4] unsafe_read(s::Sockets.TCPSocket, p::Base.RefValue{NTuple{4, Int64}}, n::Int64)
   @ Base ./io.jl:773
 [5] read!
   @ ./io.jl:775 [inlined]
 [6] deserialize_hdr_raw
   @ /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/messages.jl:167 [inlined]
 [7] message_handler_loop(r_stream::Sockets.TCPSocket, w_stream::Sockets.TCPSocket, incoming::Bool)
   @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/process_messages.jl:172
 [8] process_tcp_streams(r_stream::Sockets.TCPSocket, w_stream::Sockets.TCPSocket, incoming::Bool)
   @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/process_messages.jl:133
 [9] (::Distributed.var"#103#104"{Sockets.TCPSocket, Sockets.TCPSocket, Bool})()
   @ Distributed /opt/src/julia-1.10.2/share/julia/stdlib/v1.10/Distributed/src/process_messages.jl:121