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
A trait type to decide how the final reduction is performed. Essentially,
193
+
OhMyThreads.jl will turn a `tmapreduce(f, op, v)` call into something of
194
+
the form
195
+
```julia
196
+
tasks = map(chunks(v; chunking_kwargs...)) do chunk
197
+
@spawn mapreduce(f, op, chunk)
198
+
end
199
+
final_reduction(op, tasks, ReductionMode)
200
+
```
201
+
where the options for `ReductionMode` are currently
202
+
203
+
* `SerialFinalReduction` is the default option that should be preferred whenever `op` is not the bottleneck in your reduction. In this mode, we use a simple `mapreduce` over the tasks vector, fetching each one, i.e.
204
+
```julia
205
+
function final_reduction(op, tasks, ::SerialFinalReduction)
206
+
mapreduce(fetch, op, tasks)
207
+
end
208
+
```
209
+
210
+
* `ParallelFinalReduction` should be opted into when `op` takes a long time relative to the time it takes to `@spawn` and `fetch` tasks (typically tens of microseconds). In this mode, the vector of tasks is split up and `op` is applied in parallel using a recursive tree-based approach.
@@ -202,16 +253,17 @@ with other multithreaded code.
202
253
- `threadpool::Symbol` (default `:default`):
203
254
* Possible options are `:default` and `:interactive`.
204
255
* The high-priority pool `:interactive` should be used very carefully since tasks on this threadpool should not be allowed to run for a long time without `yield`ing as it can interfere with [heartbeat](https://en.wikipedia.org/wiki/Heartbeat_(computing)) processes.
256
+
- `final_reduction_mode` (default `SerialFinalReduction`). Switch this to `ParallelFinalReduction` or `:parallel` if your reducing operator `op` is significantly slower than the time to `@spawn` and `fetch` tasks (typically tens of microseconds).
205
257
"""
206
-
struct DynamicScheduler{C <:ChunkingMode, S <:Split} <:Scheduler
258
+
struct DynamicScheduler{C <:ChunkingMode, S <:Split, FRM <:FinalReductionMode} <:Scheduler
* Determines how the collection is divided into chunks (if chunking=true).
338
393
* See [ChunkSplitters.jl](https://github.com/JuliaFolds2/ChunkSplitters.jl) for more details and available options. We also allow users to pass `:consecutive` in place of `Consecutive()`, and `:roundrobin` in place of `RoundRobin()`
394
+
- `final_reduction_mode` (default `SerialFinalReduction`). Switch this to `ParallelFinalReduction` or `:parallel` if your reducing operator `op` is significantly slower than the time to `@spawn` and `fetch` tasks (typically tens of microseconds).
339
395
"""
340
-
struct GreedyScheduler{C <:ChunkingMode, S <:Split} <:Scheduler
396
+
struct GreedyScheduler{C <:ChunkingMode, S <:Split, FRM <:FinalReductionMode} <:Scheduler
0 commit comments