🐛 Bytecode + block decomposition: temporary terms were not correctly output

Temporary terms computed in previous blocks were not used in the bytecode
output of a given block. This was inefficient (because this means that
expressions already computed and store in the temporary terms vector would be
recomputed), and incidentally it would break the external functions
output (because it would trigger a lookup in the “TEF terms”, which would thus
fail).

Closes: #115
master
Sébastien Villemot 2023-05-12 17:22:02 +02:00
parent 1024b7de42
commit 150547b560
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 8 additions and 5 deletions

View File

@ -209,6 +209,8 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
// Temporary variables declaration
code_file << FDIMT_{static_cast<int>(blocks_temporary_terms_idxs.size())};
temporary_terms_t temporary_terms_written;
for (int block {0}; block < static_cast<int>(blocks.size()); block++)
{
const BlockSimulationType simulation_type {blocks[block].simulation_type};
@ -231,7 +233,7 @@ DynamicModel::writeDynamicBlockBytecode(const string &basename) const
u_count,
static_cast<int>(blocks_jacob_cols_endo[block].size())};
writeBlockBytecodeHelper<true>(code_file, block);
writeBlockBytecodeHelper<true>(code_file, block, temporary_terms_written);
}
code_file << FEND_{};
}

View File

@ -333,7 +333,7 @@ protected:
// Helper for writing blocks in bytecode
template<bool dynamic>
void writeBlockBytecodeHelper(BytecodeWriter &code_file, int block) const;
void writeBlockBytecodeHelper(BytecodeWriter &code_file, int block, temporary_terms_t &temporary_terms_union) const;
// Helper for writing sparse derivatives indices in MATLAB/Octave driver file
template<bool dynamic>
@ -1642,7 +1642,7 @@ ModelTree::writeBytecodeHelper(BytecodeWriter &code_file) const
template<bool dynamic>
void
ModelTree::writeBlockBytecodeHelper(BytecodeWriter &code_file, int block) const
ModelTree::writeBlockBytecodeHelper(BytecodeWriter &code_file, int block, temporary_terms_t &temporary_terms_union) const
{
constexpr ExprNodeBytecodeOutputType output_type
{ dynamic ? ExprNodeBytecodeOutputType::dynamicModel : ExprNodeBytecodeOutputType::staticModel };
@ -1654,7 +1654,6 @@ ModelTree::writeBlockBytecodeHelper(BytecodeWriter &code_file, int block) const
const int block_mfs {blocks[block].mfs_size};
const int block_recursive {blocks[block].getRecursiveSize()};
temporary_terms_t temporary_terms_union;
deriv_node_temp_terms_t tef_terms;
auto write_eq_tt = [&](int eq)

View File

@ -143,6 +143,8 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
// Temporary variables declaration
code_file << FDIMST_{static_cast<int>(blocks_temporary_terms_idxs.size())};
temporary_terms_t temporary_terms_written;
for (int block {0}; block < static_cast<int>(blocks.size()); block++)
{
const BlockSimulationType simulation_type {blocks[block].simulation_type};
@ -163,7 +165,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
u_count,
block_size};
writeBlockBytecodeHelper<false>(code_file, block);
writeBlockBytecodeHelper<false>(code_file, block, temporary_terms_written);
}
code_file << FEND_{};
}