Skip to content

Access Violation with multithreading #275

Open
@judober

Description

@judober

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions