Functions that write C files now return the paths to the generated files
This avoids computing those paths two times (the second time when compiling them).master
parent
895a866bb3
commit
36fcbf6cfe
|
@ -345,10 +345,11 @@ DynamicModel::writeBlockBytecodeAdditionalDerivatives(BytecodeWriter &code_file,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
vector<filesystem::path>
|
||||
DynamicModel::writeDynamicPerBlockCFiles(const string &basename) const
|
||||
{
|
||||
temporary_terms_t temporary_terms; // Temp terms written so far
|
||||
vector<filesystem::path> written_src_files;
|
||||
|
||||
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
||||
{
|
||||
|
@ -364,6 +365,7 @@ DynamicModel::writeDynamicPerBlockCFiles(const string &basename) const
|
|||
int nze_exo_det = blocks_derivatives_exo_det[blk].size();
|
||||
|
||||
string filename = basename + "/model/src/dynamic_" + to_string(blk+1) + ".c";
|
||||
written_src_files.emplace_back(filename);
|
||||
ofstream output{filename, ios::out | ios::binary};
|
||||
if (!output.is_open())
|
||||
{
|
||||
|
@ -539,6 +541,7 @@ DynamicModel::writeDynamicPerBlockCFiles(const string &basename) const
|
|||
header_output << header.str() << ';' << endl;
|
||||
header_output.close();
|
||||
}
|
||||
return written_src_files;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -939,7 +942,7 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const
|
|||
writeToFileIfModified(output, basename + "Dynamic.jl");
|
||||
}
|
||||
|
||||
void
|
||||
filesystem::path
|
||||
DynamicModel::writeDynamicCFile(const string &basename) const
|
||||
{
|
||||
string filename = basename + "/model/src/dynamic.c";
|
||||
|
@ -1069,6 +1072,8 @@ DynamicModel::writeDynamicCFile(const string &basename) const
|
|||
<< "}" << endl;
|
||||
|
||||
output.close();
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
string
|
||||
|
@ -1138,7 +1143,7 @@ DynamicModel::writeDynamicBlockMFile(const string &basename) const
|
|||
output.close();
|
||||
}
|
||||
|
||||
void
|
||||
filesystem::path
|
||||
DynamicModel::writeDynamicBlockCFile(const string &basename) const
|
||||
{
|
||||
string filename = basename + "/model/src/dynamic.c";
|
||||
|
@ -1221,6 +1226,8 @@ DynamicModel::writeDynamicBlockCFile(const string &basename) const
|
|||
<< "}" << endl;
|
||||
|
||||
output.close();
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3593,12 +3600,8 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool use_dll,
|
|||
|
||||
if (use_dll)
|
||||
{
|
||||
writeDynamicPerBlockCFiles(basename);
|
||||
writeDynamicBlockCFile(basename);
|
||||
vector<filesystem::path> src_files(blocks.size() + 1);
|
||||
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
||||
src_files[blk] = model_dir / "src" / ("dynamic_" + to_string(blk+1) + ".c");
|
||||
src_files[blocks.size()] = model_dir / "src" / "dynamic.c";
|
||||
auto src_files { writeDynamicPerBlockCFiles(basename) };
|
||||
src_files.emplace_back(writeDynamicBlockCFile(basename));
|
||||
compileMEX(basename, "dynamic", mexext, src_files, matlabroot, dynareroot);
|
||||
}
|
||||
else if (julia)
|
||||
|
@ -3618,9 +3621,8 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool use_dll,
|
|||
|
||||
if (use_dll)
|
||||
{
|
||||
writeDynamicCFile(basename);
|
||||
compileMEX(basename, "dynamic", mexext, { model_dir / "src" / "dynamic.c" },
|
||||
matlabroot, dynareroot);
|
||||
auto src_file { writeDynamicCFile(basename) };
|
||||
compileMEX(basename, "dynamic", mexext, { src_file }, matlabroot, dynareroot);
|
||||
}
|
||||
else if (julia)
|
||||
writeDynamicJuliaFile(basename);
|
||||
|
|
|
@ -122,12 +122,13 @@ private:
|
|||
//! Writes dynamic model file (Julia version)
|
||||
void writeDynamicJuliaFile(const string &basename) const;
|
||||
//! Writes dynamic model file (C version)
|
||||
/*! \todo add third derivatives handling */
|
||||
void writeDynamicCFile(const string &basename) const;
|
||||
// Returns the path to the generated C source file
|
||||
filesystem::path writeDynamicCFile(const string &basename) const;
|
||||
//! Writes the main dynamic function of block decomposed model (MATLAB version)
|
||||
void writeDynamicBlockMFile(const string &basename) const;
|
||||
//! Writes the main dynamic function of block decomposed model (C version)
|
||||
void writeDynamicBlockCFile(const string &basename) const;
|
||||
// Returns the path to the generated C source file
|
||||
filesystem::path writeDynamicBlockCFile(const string &basename) const;
|
||||
/* Computes the number of nonzero elements in deterministic Jacobian of
|
||||
block-decomposed model */
|
||||
int nzeDeterministicJacobianForBlock(int blk) const;
|
||||
|
@ -136,8 +137,9 @@ private:
|
|||
void writeDynamicPerBlockHelper(int blk, ostream &output, temporary_terms_t &temporary_terms, int nze_stochastic, int nze_deterministic, int nze_exo, int nze_exo_det, int nze_other_endo) const;
|
||||
//! Writes the per-block dynamic files of block decomposed model (MATLAB version)
|
||||
void writeDynamicPerBlockMFiles(const string &basename) const;
|
||||
//! Writes the per-block dynamic files of block decomposed model (C version)
|
||||
void writeDynamicPerBlockCFiles(const string &basename) const;
|
||||
/* Writes the per-block dynamic files of block decomposed model (C version).
|
||||
Returns the list of paths to the generated C source files (not the headers) */
|
||||
vector<filesystem::path> writeDynamicPerBlockCFiles(const string &basename) const;
|
||||
//! Writes the code of the block-decomposed model in virtual machine bytecode
|
||||
void writeDynamicBlockBytecode(const string &basename) const;
|
||||
// Writes derivatives w.r.t. exo, exo det and other endogenous
|
||||
|
|
|
@ -150,16 +150,18 @@ StaticModel::writeStaticPerBlockMFiles(const string &basename) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
vector<filesystem::path>
|
||||
StaticModel::writeStaticPerBlockCFiles(const string &basename) const
|
||||
{
|
||||
temporary_terms_t temporary_terms; // Temp terms written so far
|
||||
vector<filesystem::path> written_src_files;
|
||||
|
||||
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
||||
{
|
||||
BlockSimulationType simulation_type = blocks[blk].simulation_type;
|
||||
|
||||
string filename = basename + "/model/src/static_" + to_string(blk+1) + ".c";
|
||||
written_src_files.emplace_back(filename);
|
||||
ofstream output{filename, ios::out | ios::binary};
|
||||
if (!output.is_open())
|
||||
{
|
||||
|
@ -237,6 +239,7 @@ StaticModel::writeStaticPerBlockCFiles(const string &basename) const
|
|||
header_output << header.str() << ';' << endl;
|
||||
header_output.close();
|
||||
}
|
||||
return written_src_files;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -619,7 +622,7 @@ StaticModel::writeStaticMCompatFile(const string &basename) const
|
|||
output.close();
|
||||
}
|
||||
|
||||
void
|
||||
filesystem::path
|
||||
StaticModel::writeStaticCFile(const string &basename) const
|
||||
{
|
||||
// Writing comments and function definition command
|
||||
|
@ -728,6 +731,8 @@ StaticModel::writeStaticCFile(const string &basename) const
|
|||
<< "}" << endl;
|
||||
|
||||
output.close();
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -973,12 +978,8 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool use_dll, c
|
|||
|
||||
if (use_dll)
|
||||
{
|
||||
writeStaticPerBlockCFiles(basename);
|
||||
writeStaticBlockCFile(basename);
|
||||
vector<filesystem::path> src_files(blocks.size() + 1);
|
||||
for (int blk = 0; blk < static_cast<int>(blocks.size()); blk++)
|
||||
src_files[blk] = model_dir / "src" / ("static_" + to_string(blk+1) + ".c");
|
||||
src_files[blocks.size()] = model_dir / "src" / "static.c";
|
||||
auto src_files { writeStaticPerBlockCFiles(basename) };
|
||||
src_files.emplace_back(writeStaticBlockCFile(basename));
|
||||
compileMEX(basename, "static", mexext, src_files, matlabroot, dynareroot);
|
||||
}
|
||||
else if (julia)
|
||||
|
@ -998,9 +999,8 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool use_dll, c
|
|||
|
||||
if (use_dll)
|
||||
{
|
||||
writeStaticCFile(basename);
|
||||
compileMEX(basename, "static", mexext, { model_dir / "src" / "static.c" },
|
||||
matlabroot, dynareroot);
|
||||
auto src_file { writeStaticCFile(basename) };
|
||||
compileMEX(basename, "static", mexext, { src_file }, matlabroot, dynareroot);
|
||||
}
|
||||
else if (julia)
|
||||
writeStaticJuliaFile(basename);
|
||||
|
@ -1055,7 +1055,7 @@ StaticModel::writeStaticBlockMFile(const string &basename) const
|
|||
output.close();
|
||||
}
|
||||
|
||||
void
|
||||
filesystem::path
|
||||
StaticModel::writeStaticBlockCFile(const string &basename) const
|
||||
{
|
||||
string filename = basename + "/model/src/static.c";
|
||||
|
@ -1126,6 +1126,8 @@ StaticModel::writeStaticBlockCFile(const string &basename) const
|
|||
<< " mxDestroyArray(g1);" << endl
|
||||
<< "}" << endl;
|
||||
output.close();
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -38,7 +38,8 @@ private:
|
|||
void writeStaticMFile(const string &basename) const;
|
||||
|
||||
//! Writes static model file (C version)
|
||||
void writeStaticCFile(const string &basename) const;
|
||||
// Returns the path to the generated C source file
|
||||
filesystem::path writeStaticCFile(const string &basename) const;
|
||||
|
||||
//! Writes static model file (Julia version)
|
||||
void writeStaticJuliaFile(const string &basename) const;
|
||||
|
@ -47,7 +48,8 @@ private:
|
|||
void writeStaticBlockMFile(const string &basename) const;
|
||||
|
||||
//! Writes the main static function of block decomposed model (C version)
|
||||
void writeStaticBlockCFile(const string &basename) const;
|
||||
// Returns the path to the generated C source file
|
||||
filesystem::path writeStaticBlockCFile(const string &basename) const;
|
||||
|
||||
//! Helper for writing a per-block static file of block decomposed model
|
||||
template<ExprNodeOutputType output_type>
|
||||
|
@ -56,8 +58,9 @@ private:
|
|||
//! Writes the per-block static files of block decomposed model (MATLAB version)
|
||||
void writeStaticPerBlockMFiles(const string &basename) const;
|
||||
|
||||
//! Writes the per-block static files of block decomposed model (C version)
|
||||
void writeStaticPerBlockCFiles(const string &basename) const;
|
||||
/* Writes the per-block static files of block decomposed model (C version).
|
||||
Returns the list of paths to the generated C source files (not the headers) */
|
||||
vector<filesystem::path> writeStaticPerBlockCFiles(const string &basename) const;
|
||||
|
||||
//! Writes the code of the block-decomposed model in virtual machine bytecode
|
||||
void writeStaticBlockBytecode(const string &basename) const;
|
||||
|
|
Loading…
Reference in New Issue