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

Access Violation with multithreading #275

Open
judober opened this issue Jul 6, 2023 · 1 comment
Open

Access Violation with multithreading #275

judober opened this issue Jul 6, 2023 · 1 comment

Comments

@judober
Copy link

judober commented Jul 6, 2023

The code (fairly reduced)

using Pkg
Pkg.activate(".")
using LinearAlgebra
using FFTW

function fun1()
    cache = FFT_Cache(830) # simplified

    for no in 1:13267
        # @show no
        execude_fft(cache)
        # do stuff here, not required for error
    end

    return nothing
end

struct FFT_Cache{FFTplanT}
    FFTVals1::Vector{ComplexF64}
    FFTVals2::Vector{ComplexF64}
    iFFTplan::FFTplanT
end

function FFT_Cache(size_FFT)
    FFTVals1 = Vector{ComplexF64}(undef, size_FFT)
    FFTVals2 = Vector{ComplexF64}(undef, size_FFT)
    iFFTplan = plan_ifft(FFTVals1)
    FFT_Cache{typeof(iFFTplan)}(FFTVals1, FFTVals2, iFFTplan)
end

function execude_fft(cache::FFT_Cache)
    (; iFFTplan, FFTVals1, FFTVals2) = cache
    valnumber = 1 # dummy value

    FFTVals1[1:valnumber] .= 1 # dummy value
    FFTVals1[valnumber+1:end] .= 0
    mul!(FFTVals2, iFFTplan, FFTVals1)  #<- commenting this line removes the stack overflow

    return nothing # dummy value
end

# function call
FFTW.set_num_threads(1)
fun1() # works

FFTW.set_num_threads(8) # 4 seems to work
fun1() # stack overflow

results in this access violation:

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x688f888 -- .text at C:\Users\user\.julia\artifacts\b7dd1809d0626eac3bf6f97ba8ccfbb6cc63c509\bin\libfftw3-3.dll (unknown line)
in expression starting at C:\Users\user\path\test.jl:47
.text at C:\Users\user\.julia\artifacts\b7dd1809d0626eac3bf6f97ba8ccfbb6cc63c509\bin\libfftw3-3.dll (unknown line)
#2 at .\threadingconstructs.jl:404
unknown function (ip: 0000023cc9602972)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
start_task at C:/workdir/src\task.c:1092
Allocations: 700577 (Pool: 700003; Big: 574); GC: 1

when julia is started with julia --threads="auto" --startup-file="no" on windows.

julia> versioninfo()
Julia Version 1.9.2
Commit e4ee485e90 (2023-07-05 09:39 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, tigerlake)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_EDITOR = code

with FFTW 1.7.1

Either reducting the threads for FFTW or starting julia without threads solves this issue.

I'm not shure if this belongs here or in base. I will cross post there.

@ovanvincq
Copy link

ovanvincq commented Jan 19, 2024

I get the same problematic behaviour with FFTW 1.7.2 and Julia 1.10 but the problem disappears when using mkl.

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release        
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 28 × Intel(R) Xeon(R) W-2275 CPU @ 3.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, cascadelake)
  Threads: 20 on 28 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 14

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

2 participants