Skip to content

tinyasm: avoid copying the block dofmap in BlockJacobi::solve() - #5348

Draft
manishpaulish wants to merge 1 commit into
firedrakeproject:mainfrom
manishpaulish:perf/tinyasm-dofmap-copy
Draft

tinyasm: avoid copying the block dofmap in BlockJacobi::solve()#5348
manishpaulish wants to merge 1 commit into
firedrakeproject:mainfrom
manishpaulish:perf/tinyasm-dofmap-copy

Conversation

@manishpaulish

Copy link
Copy Markdown

dofsPerBlock is a vector<vector<PetscInt>>, so

auto dofmap = dofsPerBlock[p];

deduces by value and heap-allocates plus copies the block's dofmap on every block, on every application of the preconditioner. solve() runs once per Krylov iteration and block counts are typically in the thousands, so this is on the order of a million small allocations per linear solve.

Binding by const reference instead. No behavioural change, dofmap is only read.

A standalone microbenchmark mirroring the loop structure (20k blocks, dof in [4, 20], 50 applications, -O2) puts the copy at 11 to 13 percent of solve() runtime, consistent across runs. That is a microbenchmark rather than a real solve, so treat the exact figure as indicative, but the mechanism is straightforward enough.

dofsPerBlock is a vector<vector<PetscInt>>, so `auto dofmap =
dofsPerBlock[p]` deduces by value and heap-allocates + copies the block's
dofmap on every block, on every application of the preconditioner.
solve() runs once per Krylov iteration and block counts are typically in
the thousands, so this is on the order of a million small allocations per
linear solve.

Bind by const reference instead. No behavioural change: dofmap is only
read.

A standalone microbenchmark mirroring the loop structure (20k blocks,
dof in [4,20], 50 applications, -O2) measures the copy at 11-13% of
solve() runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant