-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Parallelization of integrand evaluations #80
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #80 +/- ##
==========================================
+ Coverage 97.87% 98.16% +0.28%
==========================================
Files 5 6 +1
Lines 471 599 +128
==========================================
+ Hits 461 588 +127
- Misses 10 11 +1
☔ View full report in Codecov by Sentry. |
I think we just want to provide the caller with the array of points to evaluate and let them parallelize it (or not) using threads, the GPU, distributed-memory, or whatever. One way to expose this API would be to define as a wrapper around the integrand, e.g.: struct BatchIntegrand{F,X,Y}
f!::F # in-place function f!(y, x) that takes an array of x values and outputs an array of results in-place
max_batch::Int # maximum number of x to supply in parallel (defaults to typemax(Int))
x::Vector{X}
y::Vector{Y}
end
BatchIntegrand(f!::F, ::Type{X}, ::Type{Y}; max_parallel::Integer=typemax(Int)) where {F,X,Y} =
BatchIntegrand{F,X,Y}(f!, max_parallel, X[], Y[])
BatchIntegrand(f!::F, x::Vector{X}, y::Vector{Y}; max_parallel::Integer=typemax(Int)) where {F,X,Y} =
BatchIntegrand{F,X,Y}(f!, max_parallel, x, y) It's a little annoying that it doesn't get BatchIntegrand(f!::F, ::Type{Y}; max_parallel::Integer=typemax(Int)) where {F,Y} =
BatchIntegrand{F,None,Y}(f!, max_parallel, nothing[], Y[]) and then if the |
I wrote a draft implementation of
Introducing
The implementation of |
I simplified the implementation of When refactoring the original adaptation code, I also had to change the return type of If more simplifications are possible, then I can attempt implementing them. Otherwise, it might be possible to reduce allocations in the batching code, but some may be unavoidable due to |
This is looking good! Thanks for working on this! Note that we will also want to add a new section to the manual on this, giving some explanation/motivation and a short example. |
Thanks! I'll start writing a page in the manual and will follow up on the review in another commit |
Examples were added to the manual and the constructors were modified as previously discussed. I also added |
Perhaps the only thing this PR leaves to be desired is a batched and vector-valued integrand combining both |
I was able to implement a batched and inplace integrand via adding additional dimensions to the |
Upon reflection, I think it would be more useful to make (The main purpose of |
I agree that making
to
and removing the errors for small values of |
@stevengj I rebased this pr on master and I think it is ready if it also looks good to you |
Co-authored-by: Steven G. Johnson <[email protected]>
Co-authored-by: Steven G. Johnson <[email protected]>
@stevengj Do you think this is finished? |
@stevengj I updated the docs and made the changes you suggested, so it should be ready to go. There is also a straightforward path for extending this PR to inplace and batched integrands. If the |
Thanks for keeping at it! |
This is a draft pr to parallelize
quadgk
andquadgk!
over evaluation points. Using a procedure similar to the one discussed by Gladwell in "Vectorisation of One-Dimensional Quadrature Codes" (https://doi.org/10.1007/978-94-009-3889-2_24), I remove all the segments in the heap that will need to be refined and then I evaluate the integrand at all the Kronrod points in all of the new segments in parallel. I decided to go for a simpleThreads.@threads
approach since I wasn't sure if using something more sophisticated such asFloops.jl
would provide much more benefit. Here is an example showing some speed up on a simulated costly integrandTODO:
parevalrule
forInplaceIntegrand