From d4c453c4220b60b4f8bdf6db3391eb702427aadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 21 Jul 2022 17:30:03 +0200 Subject: [PATCH] Block decomposition: (likely) performance improvement in static file in relation to temp terms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compute temporary terms for derivatives of “evaluate” mode, even though those derivatives are not computed. This is because the temporary terms may be useful for subsequent blocks. By the way, add an explanatory comment for the equivalent code in dynamic file. --- src/DynamicModel.hh | 6 +++++- src/StaticModel.hh | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 491cbeef..7efae9c9 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -740,7 +740,11 @@ DynamicModel::writeDynamicPerBlockHelper(int blk, ostream &output, temporary_ter // The Jacobian if we have to solve the block - // Write temporary terms for derivatives + /* Write temporary terms for derivatives. + Also note that in the case of “evaluate” blocks, derivatives are not + computed in deterministic mode; still their temporary terms must be + computed even in that mode, because they may be needed in subsequent + blocks. */ write_eq_tt(blocks[blk].size); if constexpr(isCOutput(output_type)) diff --git a/src/StaticModel.hh b/src/StaticModel.hh index facb4e09..a67637d7 100644 --- a/src/StaticModel.hh +++ b/src/StaticModel.hh @@ -243,13 +243,20 @@ StaticModel::writeStaticPerBlockHelper(int blk, ostream &output, temporary_terms exit(EXIT_FAILURE); } } + + /* Write temporary terms for derivatives. + This is done even for “evaluate” blocks, whose derivatives are not + computed at runtime; still those temporary terms may be needed by + subsequent blocks (not calling write_eq_tt() would not be a bug though, + because those terms would not be added to temporary_terms_union and would + therefore not be used; still, it’s probably better performance-wise to + use those temporary terms). */ + write_eq_tt(blocks[blk].size); + // The Jacobian if we have to solve the block if (simulation_type != BlockSimulationType::evaluateBackward && simulation_type != BlockSimulationType::evaluateForward) { - // Write temporary terms for derivatives - write_eq_tt(blocks[blk].size); - ostringstream i_output, j_output, v_output; for (int line_counter { ARRAY_SUBSCRIPT_OFFSET(output_type) }; const auto &[indices, d] : blocks_derivatives[blk])