Eawag-SIAM / SimulatedAnnealingABC.jl

Approximate Bayesian Computation algorithm based on simulated annealing
GNU General Public License v3.0
1 stars 0 forks source link

Multi-threading with `FLoops.jl` #5

Closed scheidan closed 3 weeks ago

scheidan commented 1 year ago

FLoops.jl could be a nice options to implement multi-threading. It allows us to switch between serial and parallel computation.

using FLoops

function bar(n, executor)
    X = zeros(n)
    @floop executor for i in 1:n
        sleep(0.1)
        if rand() < 0.3
            X[i] = X[i] + 1
            @reduce(k +=1)
        end
    end
    (X, k)
end

x, k = bar(20, SequentialEx())
sum(x)
x, k = bar(20, ThreadedEx())
sum(x)

@time bar(20, SequentialEx())
@time bar(20, ThreadedEx())
scheidan commented 3 weeks ago

we use currently Polyester.jl