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
Note that by chunking `x` we can readily control how many tasks we will use for the parallelisation. One reason why this is useful is that we can reduce the (large) overhead that we would have to pay if we would simply spawn `length(x)` tasks:
Alternatively, we can use `index_chunks` instead of `enumerate(chunks(...))`. Since `index_chunks` directly provides index ranges, it is a natural fit for this use case:
107
+
108
+
```julia-repl
109
+
julia> using ChunkSplitters: index_chunks
110
+
111
+
julia> using Base.Threads: nthreads, @threads
112
+
113
+
julia> function parallel_sum(f, x; n=nthreads())
114
+
psums = Vector{eltype(x)}(undef, n)
115
+
@threads for (i, inds) in enumerate(index_chunks(x; n=n))
0 commit comments