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
Is it possible that
Dierckx.jlis not thread safe? evaluation is fine but derivatives seem to fail; see below for an explanation.This script yields the following output: