Skip to content

Commit 31758dc

Browse files
manishpaulishpbrubeck
authored andcommitted
tinyasm: avoid copying the block dofmap in BlockJacobi::solve() (#5348)
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.
1 parent 79030a6 commit 31758dc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tinyasm/tinyasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class BlockJacobi {
114114
PetscFunctionBegin;
115115
for(size_t p=0; p<dofsPerBlock.size(); p++) {
116116
dof = dofsPerBlock[p].size();
117-
auto dofmap = dofsPerBlock[p];
117+
const auto& dofmap = dofsPerBlock[p];
118118
PetscCall(MatDenseGetArrayRead(localmats[p],&matvalues));
119119
for(int j=0; j<dof; j++)
120120
workb[j] = b[dofmap[j]];

0 commit comments

Comments
 (0)