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

reduction with push!! not working (in contrast to append!!)? #83

Open
mauricelanghinrichs opened this issue Jun 7, 2021 · 0 comments
Open

Comments

@mauricelanghinrichs
Copy link

Hey,

I'm currently trying to get into multi-threading and I was excited to find your package/macros to do this. So first thanks for making all this!

Following up on the odds/even floop from the docs I noticed a behaviour where I'm not sure if it's a bug or supposed to be that way. When replacing the append!! with an equivalent push!! code, the output is wrong in multi-threaded execution.

using FLoops
using BangBang
using Random

function run_append(niter; ex=ThreadedEx())
    @floop ex for i in 1:niter
        @init θ = zeros(1)
        θ .= rand()
        @reduce(θsamples = append!!(Vector{Float64}(), θ))
    end
    θsamples
end

# returns Vector{Float64} with 1000 elements as expected
run_append(1000)

function run_push(niter; ex=ThreadedEx())
    @floop ex for i in 1:niter
        @init θ = zeros(1)
        θ .= rand()
        @reduce(θsamples = push!!(Vector{Float64}(), θ[1]))
    end
    θsamples
end

# returns Vector{Any} with some 252 elements (unexpected)
run_push(1000)

# would run correctly in single-thread
run_push(1000, ex=SequentialEx())

Would be really happy to understand what's going on!
Best

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