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

Possible race condition problem when using eigen with @threads in windows? #30460

Closed
atbug opened this issue Dec 20, 2018 · 2 comments
Closed
Labels
multithreading Base.Threads and related functionality system:windows Affects only Windows upstream The issue is with an upstream dependency, e.g. LLVM

Comments

@atbug
Copy link

atbug commented Dec 20, 2018

using LinearAlgebra

function test(H)
    E = zeros(N, Threads.nthreads())
    Threads.@threads for ik = 1:484
        E[:, Threads.threadid()] += eigen(H).values
    end
    Esum=zeros(N)
    for i=1:Threads.nthreads()
        Esum += E[:,i]
    end
    return Esum
end

N = 4
H = rand(N, N)+im*rand(N, N)
H = H+H'

reference = test(H)
for i in 1:20
    if maximum(abs.(test(H)-reference))>1.0e-7
        println("race?")
    end
end

Expected no output. However, with N=2 we get a small chance(~10%) to get the "race?" message. With N=4 almost every execution of test() returns different values.

Note that the problem only occurs on Windows. On linux no output would show up. Here's the test environment:

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
@andreasnoack andreasnoack added system:windows Affects only Windows multithreading Base.Threads and related functionality labels Dec 27, 2018
@andreasnoack andreasnoack added the upstream The issue is with an upstream dependency, e.g. LLVM label Jan 7, 2019
@andreasnoack
Copy link
Member

This seems to be a problem with the thread safety of OpenBLAS's xsymv. I could reduce the problem to

function test2(H, f)
    nn = 484
    E = Vector{Any}(undef, nn)
    Threads.@threads for ik = 1:nn
        E[ik] = f(H)
    end
    return E
end

julia> sum(t -> abs.(t), diff(test2(H, t -> BLAS.symv!('U', 1.0, copy(t), ones(4), 0.0, zeros(4)))))
4-element Array{Float64,1}:
  0.0
  0.04083050218188866
  2.7073001729582646
 17.051752655369707

I'll report it upstream.

@andreasnoack
Copy link
Member

Actually, it looks like the OpenBLAS developers have been working a lot on thread safety lately and indeed this issue fixed with the version of OpenBLAS we use on nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality system:windows Affects only Windows upstream The issue is with an upstream dependency, e.g. LLVM
Projects
None yet
Development

No branches or pull requests

2 participants