Reduce Sauter-Schwab assembly allocations - #207
Conversation
Introduce reusable quadrature buffers for Sauter-Schwab reorder work arrays and thread them through moment-integral assembly. Replace the quadrule -> momintegrals! hot path with a callback-based dispatch path so quadrature selection can directly apply the moment integral without returning unstable rule unions through the caller. Update Sauter-Schwab quadrature call sites to use reorder! and explicit qbuffer arguments, and make wrapper quadrature strategies delegate to the callback implementation to avoid duplicated rule-selection logic. Require SauterSchwabQuadrature v2.5.0 for the new in-place reorder API.
|
The main thing I need convincing of is the Dispatch now happens in If we go this way, we need to come up with better names to make the code at least somewhat readable. And a page in the docs to explain the ideas here. Maybe: This is a bit longer, but:
I would also insist on removing the type ApplyMomintegrals from the assembly loop. Given the overlap in fields of ApplyMomintegrals and the arguments to quadrule, maybe it can be removed altogether. So maybe just: User want a new strategy: overload the first and a corresponding pair
I suppose this would introduce the allocations you try to combat... |
This PR reduces allocations in BEAST’s Sauter-Schwab assembly code.
The main idea is to reuse small temporary arrays instead of allocating them again and again during assembly. It also changes the quadrature dispatch so that
quadrulecan directly callmomintegrals!, instead of first returning a quadrature rule that is passed on later.This PR depends on the accompanying SauterSchwabQuadrature.jl PR krcools/SauterSchwabQuadrature.jl#10, which adds the in-place
reorder!function.Changes
quadraturebuffer(quadstrat)for reusable temporary arrays.I,J,K, andLarrays needed byreorder!.QuadruleCallback,ApplyMomintegrals, andApplyLocalMomintegrals.quadruledirectly applymomintegrals!in the assembly hot path.qbufferexplicitly throughmomintegrals!.SauterSchwabQuadrature.reorder!instead of allocating inreorder.qbufferargument.2.11.0.SauterSchwabQuadrature = "2.5.0".Motivation
Profiling showed many small allocations during singular and near-singular assembly. A large part of these came from Sauter-Schwab reordering and from passing many different quadrature rule types through the assembly code.
Reusing buffers and calling
momintegrals!directly fromquadrulereduces these allocations in the assembly.