Skip to content

Commit

Permalink
remove Polyester @Batch mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed Oct 8, 2021
1 parent fc43941 commit 63eece6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
19 changes: 7 additions & 12 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
24 changes: 0 additions & 24 deletions docs/src/performancetips.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
```
2 changes: 1 addition & 1 deletion src/UnROOT.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module UnROOT

using LazyArrays
export ROOTFile, LazyBranch, LazyTree, @batch
export ROOTFile, LazyBranch, LazyTree

import Base: close, keys, get, getindex, getproperty, show, length, iterate, position, ntoh, lock, unlock, reinterpret
ntoh(b::Bool) = b
Expand Down

0 comments on commit 63eece6

Please sign in to comment.