JuliaFolds / FLoops.jl

Fast sequential, threaded, and distributed for-loops for Julia—fold for humans™
MIT License
307 stars 6 forks source link

thread local variable / storage #127

Open benneti opened 2 years ago

benneti commented 2 years ago

Hi, I'd like to implement something like

@floop for _λ in Iterators.product(1:5,1:5,1:5)
    let λ = [ 1, _λ... ] # TODO it would be nice if we could have one per thread
            λ .= λ ./ sqrt( norm(λ) )
            m = f(λ)
            @reduce() do (_min = Inf; m), (λmin = zeros(4); λ)
                if gm < _min
                    _min = gm
                    λmin .= λ
                end
            end
      end
end

where instead of the let λ I have one λ per thread to minimize garbage collection when the product-space size gets really large.

Is this possible with the implementation of the multithreading?