diff --git a/Project.toml b/Project.toml index 822be732..e6524dbd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnROOT" uuid = "3cd96dde-e98d-4713-81e9-a4a1b0235ce9" authors = ["Tamas Gal", "Jerry Ling", "Johannes Schumann", "Nick Amin"] -version = "0.7.3" +version = "0.8.0" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" @@ -18,7 +18,6 @@ Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73" Mixers = "2a8e4939-dab8-5edc-8f64-72a8776f13de" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" -Requires = "ae029012-a4dd-5104-9daa-d747884805df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9" @@ -39,7 +38,6 @@ Mixers = "^0.1.0" Parameters = "^0.12.0" Polyester = "^0.5.3" PrettyTables = "^1.2.0" -Requires = "^1" StaticArrays = "^0.12.0, ^1" Tables = "^1.0.0" TypedTables = "^1.0.0" diff --git a/README.md b/README.md index cb662c03..b81f02c3 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,7 @@ julia> for event in mytree end event.Electron_dxy = Float32[0.00037050247] -julia> using Polyester #optional dependency - -julia> @batch for event in mytree # multi-threading +julia> Threads.@threads for event in mytree # multi-threading ... end ``` diff --git a/docs/src/index.md b/docs/src/index.md index 2623912f..3d57fb4b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -33,23 +33,18 @@ julia> for (i, event) in enumerate(mytree) end ``` -Both of which are compostable with `@batch` from `Polyester.jl` for multi-threading: +Both of which are compostable with `@threads` for multi-threading: ```julia -julia> using Polyester # need to install it first as it's an optional dependency - -julia> @batch for event in mytree +julia> Threads.@threads for event in mytree ... end -julia> @batch for (i, event) in enumerate(mytree) +julia> Threads.@threads for (i, event) in enumerate(mytree) ... end ``` -On finer control over `@batch`, such as batch size or per-core/thread, see [Polyester](https://github.com/JuliaSIMD/Polyester.jl)'s page. - Only one basket per branch will be cached so you don't have to worry about running out of RAM. -At the same time, `event` inside the for-loop is not materialized until a field is accessed. If your event -is fairly small or you need all of them anyway, you can `collect(event)` first inside the loop. +At the same time, `event` inside the for-loop is not materialized until a field is accessed. ## Laziness in Indexing, Slicing, and Looping Laziness (or eagerness) in UnROOT generally refers to if an "event" has read each branches of the tree or not. @@ -84,6 +79,6 @@ The laziness of the main interfaces are summarized below: | | `mytree` | `enumerate(mytree)` | | ---------------------- |:-----------:|:-------------------:| | `for X in ...` | 💤 | 💤 | -| `@threads for X in ...`| 🚨 | 💤 | -| `@batch for X in ...` | 💤 | 💤 | -| `getindex()` | 🚨 | 💤 | +| `@threads for X in ...`| 💤 | 💤 | +| `getindex(tree, row::Int)`| 💤 | N/A | +| `getindex(tree, row::Range)`| 🚨 | N/A | diff --git a/docs/src/performancetips.md b/docs/src/performancetips.md index 59ca1f95..555c3edb 100644 --- a/docs/src/performancetips.md +++ b/docs/src/performancetips.md @@ -15,27 +15,3 @@ for evt in mytree calculation(nmu) end ``` - -## `Threads.@threads` should go with `enumerate()` -tl;dr: just use `@batch` provided by [Polyester.jl](https://github.com/JuliaSIMD/Polyester.jl) since UnROOT -can customize behavior. - -Unlike `@batch`, there's not much we can do to customize behavior of `@threads`. It is essentially -calling `getindex()`, which we want to keep eager for regular use (e.v `mytree[120]` is eager). Thus, if for some -reason you want to use `@threads` instead of `@batch`, you should use it with `enumerate`: -```julia -julia> for evt in mytree - @show evt - break - end -evt = "LazyEvent with: (:tree, :idx)" - -julia> Threads.@threads for evt in mytree - @show evt - break - end -evt = (nMuon = 0x00000000, Muon_pt = Float32[]) -evt = (nMuon = 0x00000001, Muon_pt = Float32[3.4505641]) -evt = (nMuon = 0x00000000, Muon_pt = Float32[]) -evt = (nMuon = 0x00000002, Muon_pt = Float32[21.279676, 7.6710315]) -``` diff --git a/src/UnROOT.jl b/src/UnROOT.jl index 18b40412..04b1de76 100644 --- a/src/UnROOT.jl +++ b/src/UnROOT.jl @@ -1,7 +1,7 @@ module UnROOT -using Requires, LazyArrays -export ROOTFile, LazyBranch, LazyTree, @batch +using LazyArrays +export ROOTFile, LazyBranch, LazyTree import Base: close, keys, get, getindex, getproperty, show, length, iterate, position, ntoh, lock, unlock, reinterpret ntoh(b::Bool) = b @@ -30,8 +30,4 @@ include("iteration.jl") include("custom.jl") include("displays.jl") -function __init__() - @require Polyester="f517fe37-dbe3-4b94-8317-1923a5111588" include("polyester.jl") -end - end # module diff --git a/src/iteration.jl b/src/iteration.jl index ff2b83a3..f70eccb7 100644 --- a/src/iteration.jl +++ b/src/iteration.jl @@ -225,11 +225,11 @@ Base.lastindex(lt::LazyTree) = length(lt) Base.eachindex(lt::LazyTree) = 1:lastindex(lt) # allow enumerate() to be chunkable (eg with Threads.@threads) +Base.step(e::Iterators.Enumerate{LazyTree{T}}) where T = 1 Base.firstindex(e::Iterators.Enumerate{LazyTree{T}}) where T = firstindex(e.itr) Base.lastindex(e::Iterators.Enumerate{LazyTree{T}}) where T = lastindex(e.itr) Base.eachindex(e::Iterators.Enumerate{LazyTree{T}}) where T = eachindex(e.itr) -Base.getindex(e::Iterators.Enumerate{LazyTree{T}}, row::Int) where T = (row, first(iterate(e.itr, row))) - +Base.getindex(e::Iterators.Enumerate{LazyTree{T}}, row::Int) where T = (row, LazyEvent(innertable(e.itr), row)) # interfacing Table Base.names(lt::LazyTree) = collect(String.(propertynames(innertable(lt)))) Base.length(lt::LazyTree) = length(innertable(lt)) diff --git a/src/polyester.jl b/src/polyester.jl deleted file mode 100644 index 3f4b0b07..00000000 --- a/src/polyester.jl +++ /dev/null @@ -1,8 +0,0 @@ -# special Requires.jl syntax -import .Polyester: splitloop, combine, NoLoop - -splitloop(t::LazyTree) = NoLoop(), eachindex(t), t -combine(t::LazyTree, ::NoLoop, j) = LazyEvent(innertable(t), j) - -splitloop(e::Base.Iterators.Enumerate{LazyTree{T}}) where T = NoLoop(), eachindex(e.itr), e -combine(e::Iterators.Enumerate{LazyTree{T}}, ::NoLoop, j) where T = @inbounds e[j] diff --git a/test/runtests.jl b/test/runtests.jl index c841539d..08a8c427 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -658,19 +658,6 @@ end @test count(>(0), nmus) > 1 # test @threads is actually threading @test sum(nmus) == 878 - nmus .= 0 - @batch for (i, evt) in enumerate(t) - nmus[Threads.threadid()] += length(evt.Muon_pt) - end - @test count(>(0), nmus) > 1 # test @batch is actually threading - @test sum(nmus) == 878 - - event_nums = zeros(Int, Threads.nthreads()) - @batch for (i, evt) in enumerate(t) - event_nums[Threads.threadid()] += 1 - end - @test count(>(0), event_nums) > 1 # test @batch is actually threading - @test sum(event_nums) == length(t) nmus .= 0 @batch for evt in t @@ -688,7 +675,7 @@ end for j in 1:3 inds = [Vector{Int}() for _ in 1:Threads.nthreads()] - @batch for (i, evt) in enumerate(t) + Threads.@threads for (i, evt) in enumerate(t) push!(inds[Threads.threadid()], i) end @test sum([length(inds[i] ∩ inds[j]) for i=1:length(inds), j=1:length(inds) if j>i]) == 0