JuliaFolds / FLoops.jl

Fast sequential, threaded, and distributed for-loops for Julia—fold for humans™

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom mutating accumulators

antoine-levitt opened this issue · comments

Reposting this question from discourse because it's important in my application (eg here):

Is there any way to support custom mutating reducers? Eg  mul!(accum, x, y, true, true).

Feel free to close if not applicable!

Your question is very relevant! I think what you want to do is doable but if it's not clear from looking at the documentation, it's a "documentation bug."

From looking at the example you linked, it looks like the basic idea is similar to this toy example:

@floop for x in 1:10
    xs = [x, 2x, 3x]
    @reduce() do (ys = zeros(3); xs)
        ys .+= xs
    end
end
@show ys

In this example, ys = zeros(3) is run for each thread (by default) and re-used within the reduction that each thread does.

Is this a good enough starting point for your use-case?

OK indeed I see it now. Thanks, sorry for the noise!