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())
FLoops.jl
could be a nice options to implement multi-threading. It allows us to switch between serial and parallel computation.