Skip to content

Thread-safety #77

@cortner

Description

@cortner

Is it possible that Dierckx.jl is not thread safe? evaluation is fine but derivatives seem to fail; see below for an explanation.

# file mtsplines.jl
using Dierckx, Random, .Threads
let 
   xdat = range(0, 1, length=100)
   spl = Spline1D(xdat, exp.(xdat))
   Random.seed!(0)
   r = rand(10_000)
   s = zeros(nthreads())
   @threads for n = 1:length(r)
      s[threadid()] += Dierckx.derivative(spl, r[n])
   end
   @show sum(s) / length(r)
end

This script yields the following output:

(base) Fuji-2:temp ortner$ j16 --threads=1 mtsplines.jl 
sum(s) / length(r) = 1.7170295968665945
(base) Fuji-2:temp ortner$ j16 --threads=1 mtsplines.jl 
sum(s) / length(r) = 1.7170295968665945
(base) Fuji-2:temp ortner$ j16 --threads=4 mtsplines.jl 
sum(s) / length(r) = -792.7283310922177
(base) Fuji-2:temp ortner$ j16 --threads=4 mtsplines.jl 
sum(s) / length(r) = -104735.52438361687

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