Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-threading with FLoops.jl #5

Closed
scheidan opened this issue Jul 4, 2023 · 1 comment
Closed

Multi-threading with FLoops.jl #5

scheidan opened this issue Jul 4, 2023 · 1 comment

Comments

@scheidan
Copy link
Collaborator

scheidan commented Jul 4, 2023

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
Copy link
Collaborator Author

we use currently Polyester.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant