-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Threaded Jacobian calls #174
Comments
So I'm multithreading the same jacobian function with different inputs and I'm seeing incorrect behavior as compared to running on a single thread. I'm preallocating a single cache for the jacobian. I'm assuming this is also due to cache overlap. Is there a better workaround other than preallocating a different cache for each function call? (possible a different cache on each thread?) |
Maybe we should consider cacheless forward mode AD. |
This is indeed my situation and I'm very interested in this potential solution! I'm parsing |
FWIW, I just implemented that approach in C++ I'd suggest ignoring # T is the Dual tag to use
# V is the eltype of the wrapped array
# N is the chunk size
struct DualVector{T,V,N,A<:AbstractVector{V}} <: AbstractVector{ForwardDiff.Dual{T,V,N}}
data::A
offset::Int
end
Base.@propagate_inbounds function Base.getindex(A::DualVector{T,V,N}, i::Int) where {T,V,N}
x = A.data[i]
# NOTE: if you modify this, avoid capturing `V` in a closure
# because closures do not specialize on types!
p = ntuple(V∘==(i-offset), Val(N))
ForwardDiff.Dual{T}(x, p)
end
# TODO: rest of array interface, e.g. `size`, `IndexStyle`, etc should forward Basically, you pick a chunk size ( |
It would be good to port over some of the PolyesterForwardDiff threading support onto the loops here. It wouldn't be too hard but the caches would need to be extended so they don't overlap.
Pinging @chriselrod for reference.
The text was updated successfully, but these errors were encountered: