JuliaMath / JuliaMath/Dierckx.jl
Thread-safety
- Dominant language
- Julia
- Stars
- 173
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
Is it possible that `Dierckx.jl` is not thread safe? evaluation is fine but derivatives seem to fail; see below for an explanation.
```julia
# 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:
```bash
(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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.