JuliaDiff/TaylorSeries.jl

Compatibility with Multi-Threading

Closed this issue · 3 comments

Hello,

I am trying to multi-thread some code that uses TaylorSeries.jl. In particular, I am encountering some issues with the differentiate() and integrate() functions.
I have identified that the issue comes from method differentiate(a::HomogeneousPolynomial, r::Int) in calculus.jl, line 128.
There, the entries of coeff_table are modified to find the leading coefficient of the differentiated HomogeneousPolynomial:

function differentiate(a::HomogeneousPolynomial, r::Int)
    [...]
    @inbounds for i = 1:num_coeffs
        iind = coeff_table[a.order+1][i]
        [...]
        iind[r] -= 1
                kdic = in_base(get_order(),iind)
        pos = posTb[kdic]
        coeffs[pos] = n * a[i]
        iind[r] += 1
    end
    [...]
end

This modification of the coeff_table causes a data race causing multi-threading to crash.
Maybe a fix could consist in defining iind = copy(coeff_table[a.order+1][i])?
The respective problem for integration is in method integrate(a::HomogeneousPolynomial, r::Int) at line 354 of calculus.jl.

Thanks a lot for your report and for digging in the problem. This seems indeed a bug, because coeff_table shouldn't be modified at all. Your proposal seems indeed a reasonable solution; give me a bit of time to look onto this.

See (your proposal) in #319.

I am able to reproduce the problem. Yet, can provide an example so I include it in the tests?

Fixed by #319