use_dll: refactor MEX compilation so that it happens inside “write” methods
parent
08a86b67cb
commit
d9bda244d4
|
@ -943,8 +943,8 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const
|
||||||
writeToFileIfModified(output, basename + "Dynamic.jl");
|
writeToFileIfModified(output, basename + "Dynamic.jl");
|
||||||
}
|
}
|
||||||
|
|
||||||
filesystem::path
|
void
|
||||||
DynamicModel::writeDynamicCFile(const string &basename) const
|
DynamicModel::writeDynamicCFile(const string &basename, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const
|
||||||
{
|
{
|
||||||
string filename = basename + "/model/src/dynamic.c";
|
string filename = basename + "/model/src/dynamic.c";
|
||||||
|
|
||||||
|
@ -1074,7 +1074,7 @@ DynamicModel::writeDynamicCFile(const string &basename) const
|
||||||
|
|
||||||
output.close();
|
output.close();
|
||||||
|
|
||||||
return filename;
|
compileMEX(basename, "dynamic", mexext, { filename }, matlabroot, dynareroot);
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
|
@ -1144,8 +1144,8 @@ DynamicModel::writeDynamicBlockMFile(const string &basename) const
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
filesystem::path
|
void
|
||||||
DynamicModel::writeDynamicBlockCFile(const string &basename) const
|
DynamicModel::writeDynamicBlockCFile(const string &basename, vector<filesystem::path> per_block_src_files, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const
|
||||||
{
|
{
|
||||||
string filename = basename + "/model/src/dynamic.c";
|
string filename = basename + "/model/src/dynamic.c";
|
||||||
|
|
||||||
|
@ -1228,7 +1228,8 @@ DynamicModel::writeDynamicBlockCFile(const string &basename) const
|
||||||
|
|
||||||
output.close();
|
output.close();
|
||||||
|
|
||||||
return filename;
|
per_block_src_files.push_back(filename);
|
||||||
|
compileMEX(basename, "dynamic", mexext, per_block_src_files, matlabroot, dynareroot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -3606,9 +3607,8 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool use_dll,
|
||||||
|
|
||||||
if (use_dll)
|
if (use_dll)
|
||||||
{
|
{
|
||||||
auto src_files { writeDynamicPerBlockCFiles(basename) };
|
auto per_block_src_files { writeDynamicPerBlockCFiles(basename) };
|
||||||
src_files.emplace_back(writeDynamicBlockCFile(basename));
|
writeDynamicBlockCFile(basename, move(per_block_src_files), mexext, matlabroot, dynareroot);
|
||||||
compileMEX(basename, "dynamic", mexext, src_files, matlabroot, dynareroot);
|
|
||||||
}
|
}
|
||||||
else if (julia)
|
else if (julia)
|
||||||
{
|
{
|
||||||
|
@ -3626,10 +3626,7 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool use_dll,
|
||||||
writeDynamicBytecode(basename);
|
writeDynamicBytecode(basename);
|
||||||
|
|
||||||
if (use_dll)
|
if (use_dll)
|
||||||
{
|
writeDynamicCFile(basename, mexext, matlabroot, dynareroot);
|
||||||
auto src_file { writeDynamicCFile(basename) };
|
|
||||||
compileMEX(basename, "dynamic", mexext, { src_file }, matlabroot, dynareroot);
|
|
||||||
}
|
|
||||||
else if (julia)
|
else if (julia)
|
||||||
writeDynamicJuliaFile(basename);
|
writeDynamicJuliaFile(basename);
|
||||||
else
|
else
|
||||||
|
|
|
@ -121,14 +121,13 @@ private:
|
||||||
void writeDynamicMFile(const string &basename) const;
|
void writeDynamicMFile(const string &basename) const;
|
||||||
//! Writes dynamic model file (Julia version)
|
//! Writes dynamic model file (Julia version)
|
||||||
void writeDynamicJuliaFile(const string &basename) const;
|
void writeDynamicJuliaFile(const string &basename) const;
|
||||||
//! Writes dynamic model file (C version)
|
// Writes and compiles dynamic model file (C version)
|
||||||
// Returns the path to the generated C source file
|
void writeDynamicCFile(const string &basename, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const;
|
||||||
filesystem::path writeDynamicCFile(const string &basename) const;
|
|
||||||
//! Writes the main dynamic function of block decomposed model (MATLAB version)
|
//! Writes the main dynamic function of block decomposed model (MATLAB version)
|
||||||
void writeDynamicBlockMFile(const string &basename) const;
|
void writeDynamicBlockMFile(const string &basename) const;
|
||||||
//! Writes the main dynamic function of block decomposed model (C version)
|
/* Writes the main dynamic functions of block decomposed model (C version),
|
||||||
// Returns the path to the generated C source file
|
then compiles it with the per-block functions into a single MEX */
|
||||||
filesystem::path writeDynamicBlockCFile(const string &basename) const;
|
void writeDynamicBlockCFile(const string &basename, vector<filesystem::path> per_block_src_files, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const;
|
||||||
/* Computes the number of nonzero elements in deterministic Jacobian of
|
/* Computes the number of nonzero elements in deterministic Jacobian of
|
||||||
block-decomposed model */
|
block-decomposed model */
|
||||||
int nzeDeterministicJacobianForBlock(int blk) const;
|
int nzeDeterministicJacobianForBlock(int blk) const;
|
||||||
|
|
|
@ -603,8 +603,8 @@ StaticModel::writeStaticMCompatFile(const string &basename) const
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
filesystem::path
|
void
|
||||||
StaticModel::writeStaticCFile(const string &basename) const
|
StaticModel::writeStaticCFile(const string &basename, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const
|
||||||
{
|
{
|
||||||
// Writing comments and function definition command
|
// Writing comments and function definition command
|
||||||
string filename{basename + "/model/src/static.c"};
|
string filename{basename + "/model/src/static.c"};
|
||||||
|
@ -713,7 +713,7 @@ StaticModel::writeStaticCFile(const string &basename) const
|
||||||
|
|
||||||
output.close();
|
output.close();
|
||||||
|
|
||||||
return filename;
|
compileMEX(basename, "static", mexext, { filename }, matlabroot, dynareroot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -959,9 +959,8 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool use_dll, c
|
||||||
|
|
||||||
if (use_dll)
|
if (use_dll)
|
||||||
{
|
{
|
||||||
auto src_files { writeStaticPerBlockCFiles(basename) };
|
auto per_block_src_files { writeStaticPerBlockCFiles(basename) };
|
||||||
src_files.emplace_back(writeStaticBlockCFile(basename));
|
writeStaticBlockCFile(basename, move(per_block_src_files), mexext, matlabroot, dynareroot);
|
||||||
compileMEX(basename, "static", mexext, src_files, matlabroot, dynareroot);
|
|
||||||
}
|
}
|
||||||
else if (julia)
|
else if (julia)
|
||||||
{
|
{
|
||||||
|
@ -979,10 +978,7 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool use_dll, c
|
||||||
writeStaticBytecode(basename);
|
writeStaticBytecode(basename);
|
||||||
|
|
||||||
if (use_dll)
|
if (use_dll)
|
||||||
{
|
writeStaticCFile(basename, mexext, matlabroot, dynareroot);
|
||||||
auto src_file { writeStaticCFile(basename) };
|
|
||||||
compileMEX(basename, "static", mexext, { src_file }, matlabroot, dynareroot);
|
|
||||||
}
|
|
||||||
else if (julia)
|
else if (julia)
|
||||||
writeStaticJuliaFile(basename);
|
writeStaticJuliaFile(basename);
|
||||||
else // M-files
|
else // M-files
|
||||||
|
@ -1036,8 +1032,8 @@ StaticModel::writeStaticBlockMFile(const string &basename) const
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
filesystem::path
|
void
|
||||||
StaticModel::writeStaticBlockCFile(const string &basename) const
|
StaticModel::writeStaticBlockCFile(const string &basename, vector<filesystem::path> per_block_src_files, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const
|
||||||
{
|
{
|
||||||
string filename = basename + "/model/src/static.c";
|
string filename = basename + "/model/src/static.c";
|
||||||
|
|
||||||
|
@ -1108,7 +1104,8 @@ StaticModel::writeStaticBlockCFile(const string &basename) const
|
||||||
<< "}" << endl;
|
<< "}" << endl;
|
||||||
output.close();
|
output.close();
|
||||||
|
|
||||||
return filename;
|
per_block_src_files.push_back(filename);
|
||||||
|
compileMEX(basename, "static", mexext, per_block_src_files, matlabroot, dynareroot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -37,9 +37,8 @@ private:
|
||||||
//! Writes static model file (standard Matlab version)
|
//! Writes static model file (standard Matlab version)
|
||||||
void writeStaticMFile(const string &basename) const;
|
void writeStaticMFile(const string &basename) const;
|
||||||
|
|
||||||
//! Writes static model file (C version)
|
// Writes and compiles static model file (C version)
|
||||||
// Returns the path to the generated C source file
|
void writeStaticCFile(const string &basename, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const;
|
||||||
filesystem::path writeStaticCFile(const string &basename) const;
|
|
||||||
|
|
||||||
//! Writes static model file (Julia version)
|
//! Writes static model file (Julia version)
|
||||||
void writeStaticJuliaFile(const string &basename) const;
|
void writeStaticJuliaFile(const string &basename) const;
|
||||||
|
@ -47,9 +46,9 @@ private:
|
||||||
//! Writes the main static function of block decomposed model (MATLAB version)
|
//! Writes the main static function of block decomposed model (MATLAB version)
|
||||||
void writeStaticBlockMFile(const string &basename) const;
|
void writeStaticBlockMFile(const string &basename) const;
|
||||||
|
|
||||||
//! Writes the main static function of block decomposed model (C version)
|
/* Writes the main static functions of block decomposed model (C version),
|
||||||
// Returns the path to the generated C source file
|
then compiles it with the per-block functions into a single MEX */
|
||||||
filesystem::path writeStaticBlockCFile(const string &basename) const;
|
void writeStaticBlockCFile(const string &basename, vector<filesystem::path> per_block_src_files, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) const;
|
||||||
|
|
||||||
//! Helper for writing a per-block static file of block decomposed model
|
//! Helper for writing a per-block static file of block decomposed model
|
||||||
template<ExprNodeOutputType output_type>
|
template<ExprNodeOutputType output_type>
|
||||||
|
|
Loading…
Reference in New Issue