Commit 946d105c authored by Sébastien Villemot's avatar Sébastien Villemot

Remove C and C++ preprocessor output types

This code is broken since the temporary terms array changes. It is probably not
worth maintaining it.
parent b8a5dfdc
This diff is collapsed.
......@@ -627,21 +627,6 @@ public:
//! Returns true if a parameter was used in the model block with a lead or lag
bool ParamUsedWithLeadLag() const;
//! Writes model initialization and lead/lag incidence matrix to C output
void writeCOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present) const;
//! Writes model initialization and lead/lag incidence matrix to Cpp output
void writeCCOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present) const;
//! Writes C file containing residuals
void writeResidualsC(const string &basename, bool cuda) const;
//! Writes C file containing first order derivatives of model evaluated at steady state
void writeFirstDerivativesC(const string &basename, bool cuda) const;
//! Writes C file containing first order derivatives of model evaluated at steady state (conpressed sparse column)
void writeFirstDerivativesC_csr(const string &basename, bool cuda) const;
//! Writes C file containing second order derivatives of model evaluated at steady state (compressed sparse column)
void writeSecondDerivativesC_csr(const string &basename, bool cuda) const;
//! Writes C file containing third order derivatives of model evaluated at steady state (compressed sparse column)
void writeThirdDerivativesC_csr(const string &basename, bool cuda) const;
bool isChecksumMatching(const string &basename) const;
};
......
......@@ -57,7 +57,7 @@ usage()
{
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [noemptylinemacro] [notmpterms] [nolog] [warn_uninit]"
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=C|C++|julia]"
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=julia]"
<< " [params_derivs_order=0|1|2] [transform_unary_ops]"
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
<< " [cygwin] [msvc] [mingw]"
......@@ -292,11 +292,7 @@ main(int argc, char **argv)
{
// we don't want temp terms in external functions (except Julia)
no_tmp_terms = true;
if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 9, "C", 1))
language = c;
else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 9, "C++", 3))
language = cpp;
else if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 9, "cuda", 4))
if (strlen(argv[arg]) == 13 && !strncmp(argv[arg] + 9, "cuda", 4))
language = cuda;
else if (strlen(argv[arg]) == 15 && !strncmp(argv[arg] + 9, "python", 6))
language = python;
......
......@@ -864,10 +864,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
i = datatree.getDynJacobianCol(datatree.getDerivID(symb_id, lag)) + ARRAY_SUBSCRIPT_OFFSET(output_type);
output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCDynamic2Model:
i = tsid + (lag+1)*datatree.symbol_table.endo_nbr() + ARRAY_SUBSCRIPT_OFFSET(output_type);
output << "y" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCStaticModel:
case oJuliaStaticModel:
case oMatlabStaticModel:
......@@ -899,9 +895,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
case oSteadyStateFile:
output << "ys_" << LEFT_ARRAY_SUBSCRIPT(output_type) << tsid + 1 << RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCSteadyStateFile:
output << "ys_[" << tsid << "]";
break;
case oMatlabDseries:
output << "ds." << datatree.symbol_table.getName(symb_id);
if (lag != 0)
......@@ -931,7 +924,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCDynamicModel:
case oCDynamic2Model:
if (lag == 0)
output << "x[it_+" << i << "*nb_row_x]";
else if (lag > 0)
......@@ -956,9 +948,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
case oSteadyStateFile:
output << "exo_" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCSteadyStateFile:
output << "exo_[" << i - 1 << "]";
break;
case oMatlabDseries:
output << "ds." << datatree.symbol_table.getName(symb_id);
if (lag != 0)
......@@ -988,7 +977,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
<< RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCDynamicModel:
case oCDynamic2Model:
if (lag == 0)
output << "x[it_+" << i << "*nb_row_x]";
else if (lag > 0)
......@@ -1013,9 +1001,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
case oSteadyStateFile:
output << "exo_" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
break;
case oCSteadyStateFile:
output << "exo_[" << i - 1 << "]";
break;
case oMatlabDseries:
output << "ds." << datatree.symbol_table.getName(symb_id);
if (lag != 0)
......@@ -6686,7 +6671,7 @@ ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_typ
const deriv_node_temp_terms_t &tef_terms) const
{
if (output_type == oMatlabOutsideModel || output_type == oSteadyStateFile
|| output_type == oCSteadyStateFile || output_type == oJuliaSteadyStateFile
|| output_type == oJuliaSteadyStateFile
|| IS_LATEX(output_type))
{
string name = IS_LATEX(output_type) ? datatree.symbol_table.getTeXName(symb_id)
......
......@@ -74,7 +74,6 @@ enum ExprNodeOutputType
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed model
oMatlabDynamicModelSparse, //!< Matlab code, dynamic block decomposed model
oCDynamicModel, //!< C code, dynamic model
oCDynamic2Model, //!< C code, dynamic model, alternative numbering of endogenous variables
oCStaticModel, //!< C code, static model
oJuliaStaticModel, //!< Julia code, static model
oJuliaDynamicModel, //!< Julia code, dynamic model
......@@ -87,7 +86,6 @@ enum ExprNodeOutputType
oCDynamicSteadyStateOperator, //!< C code, dynamic model, inside a steady state operator
oJuliaDynamicSteadyStateOperator, //!< Julia code, dynamic model, inside a steady state operator
oSteadyStateFile, //!< Matlab code, in the generated steady state file
oCSteadyStateFile, //!< C code, in the generated steady state file
oJuliaSteadyStateFile, //!< Julia code, in the generated steady state file
oMatlabDseries //!< Matlab code for dseries
};
......@@ -108,10 +106,8 @@ enum ExprNodeOutputType
|| (output_type) == oJuliaSteadyStateFile)
#define IS_C(output_type) ((output_type) == oCDynamicModel \
|| (output_type) == oCDynamic2Model \
|| (output_type) == oCStaticModel \
|| (output_type) == oCDynamicSteadyStateOperator \
|| (output_type) == oCSteadyStateFile)
|| (output_type) == oCDynamicSteadyStateOperator)
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|| (output_type) == oLatexDynamicModel \
......
......@@ -32,8 +32,6 @@ enum FileOutputType
enum LanguageOutputType
{
matlab, // outputs files for Matlab/Octave processing
c, // outputs files for C
cpp, // outputs files for C++
cuda, // outputs files for CUDA (not yet implemented)
julia, // outputs files for Julia
python, // outputs files for Python (not yet implemented) (not yet implemented)
......
......@@ -1061,12 +1061,6 @@ ModFile::writeExternalFiles(const string &basename, FileOutputType output, Langu
{
switch (language)
{
case c:
writeExternalFilesC(basename, output);
break;
case cpp:
writeExternalFilesCC(basename, output);
break;
case julia:
writeExternalFilesJulia(basename, output, nopreprocessoroutput);
break;
......@@ -1076,213 +1070,6 @@ ModFile::writeExternalFiles(const string &basename, FileOutputType output, Langu
}
}
void
ModFile::writeExternalFilesC(const string &basename, FileOutputType output) const
{
writeModelC(basename);
steady_state_model.writeSteadyStateFileC(basename, mod_file_struct.ramsey_model_present);
dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option, false);
if (!no_static)
static_model.writeStaticFile(basename, false, false, true, false);
// static_model.writeStaticCFile(basename, block, byte_code, use_dll);
// static_model.writeParamsDerivativesFileC(basename, cuda);
// static_model.writeAuxVarInitvalC(mOutputFile, oMatlabOutsideModel, cuda);
dynamic_model.writeResidualsC(basename, cuda);
// dynamic_model.writeParamsDerivativesFileC(basename, cuda);
dynamic_model.writeFirstDerivativesC(basename, cuda);
if (output == second)
dynamic_model.writeSecondDerivativesC_csr(basename, cuda);
else if (output == third)
{
dynamic_model.writeSecondDerivativesC_csr(basename, cuda);
dynamic_model.writeThirdDerivativesC_csr(basename, cuda);
}
}
void
ModFile::writeModelC(const string &basename) const
{
string filename = basename + ".c";
ofstream mDriverCFile;
mDriverCFile.open(filename, ios::out | ios::binary);
if (!mDriverCFile.is_open())
{
cerr << "Error: Can't open file " << filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
mDriverCFile << "/*" << endl
<< " * " << filename << " : Driver file for Dynare C code" << endl
<< " *" << endl
<< " * Warning : this file is generated automatically by Dynare" << endl
<< " * from model file (.mod)" << endl
<< " */" << endl
<< endl
<< "#include \"dynare_driver.h\"" << endl
<< endl
<< "struct" << endl
<< "{" << endl;
// Write basic info
symbol_table.writeCOutput(mDriverCFile);
mDriverCFile << endl << "params.resize(param_nbr);" << endl;
if (dynamic_model.equation_number() > 0)
{
dynamic_model.writeCOutput(mDriverCFile, basename, block, byte_code, use_dll, mod_file_struct.order_option, mod_file_struct.estimation_present);
// if (!no_static)
// static_model.writeCOutput(mOutputFile, block);
}
// Print statements
for (auto statement : statements)
statement->writeCOutput(mDriverCFile, basename);
mDriverCFile << "} DynareInfo;" << endl;
mDriverCFile.close();
// Write informational m file
ofstream mOutputFile;
if (basename.size())
{
string fname(basename);
fname += ".m";
mOutputFile.open(fname, ios::out | ios::binary);
if (!mOutputFile.is_open())
{
cerr << "ERROR: Can't open file " << fname
<< " for writing" << endl;
exit(EXIT_FAILURE);
}
}
else
{
cerr << "ERROR: Missing file name" << endl;
exit(EXIT_FAILURE);
}
mOutputFile << "%" << endl
<< "% Status : informational m file" << endl
<< "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl
<< "disp('The following C file was successfully created:');" << endl
<< "ls preprocessorOutput.c" << endl << endl;
mOutputFile.close();
}
void
ModFile::writeExternalFilesCC(const string &basename, FileOutputType output) const
{
writeModelCC(basename);
steady_state_model.writeSteadyStateFileC(basename, mod_file_struct.ramsey_model_present);
dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option, false);
if (!no_static)
static_model.writeStaticFile(basename, false, false, true, false);
// static_model.writeStaticCFile(basename, block, byte_code, use_dll);
// static_model.writeParamsDerivativesFileC(basename, cuda);
// static_model.writeAuxVarInitvalC(mOutputFile, oMatlabOutsideModel, cuda);
// dynamic_model.writeResidualsC(basename, cuda);
// dynamic_model.writeParamsDerivativesFileC(basename, cuda);
dynamic_model.writeResidualsC(basename, cuda);
dynamic_model.writeFirstDerivativesC_csr(basename, cuda);
if (output == second)
dynamic_model.writeSecondDerivativesC_csr(basename, cuda);
else if (output == third)
{
dynamic_model.writeSecondDerivativesC_csr(basename, cuda);
dynamic_model.writeThirdDerivativesC_csr(basename, cuda);
}
}
void
ModFile::writeModelCC(const string &basename) const
{
string filename = basename + ".cc";
ofstream mDriverCFile;
mDriverCFile.open(filename, ios::out | ios::binary);
if (!mDriverCFile.is_open())
{
cerr << "Error: Can't open file " << filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
mDriverCFile << "/*" << endl
<< " * " << filename << " : Driver file for Dynare C++ code" << endl
<< " *" << endl
<< " * Warning : this file is generated automatically by Dynare" << endl
<< " * from model file (.mod)" << endl
<< " */" << endl
<< endl
<< "#include \"dynare_cpp_driver.hh\"" << endl
<< endl
<< "DynareInfo::DynareInfo(void)" << endl
<< "{" << endl;
// Write basic info
symbol_table.writeCCOutput(mDriverCFile);
mDriverCFile << endl << "params.resize(param_nbr);" << endl;
if (dynamic_model.equation_number() > 0)
{
dynamic_model.writeCCOutput(mDriverCFile, basename, block, byte_code, use_dll, mod_file_struct.order_option, mod_file_struct.estimation_present);
// if (!no_static)
// static_model.writeCOutput(mOutputFile, block);
}
// Print statements
for (auto statement : statements)
statement->writeCOutput(mDriverCFile, basename);
mDriverCFile << "};" << endl;
mDriverCFile.close();
// Write informational m file
ofstream mOutputFile;
if (basename.size())
{
string fname(basename);
fname += ".m";
mOutputFile.open(fname, ios::out | ios::binary);
if (!mOutputFile.is_open())
{
cerr << "ERROR: Can't open file " << fname
<< " for writing" << endl;
exit(EXIT_FAILURE);
}
}
else
{
cerr << "ERROR: Missing file name" << endl;
exit(EXIT_FAILURE);
}
mOutputFile << "%" << endl
<< "% Status : informational m file" << endl
<< "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl
<< "disp('The following C++ file was successfully created:');" << endl
<< "ls preprocessorOutput.cc" << endl << endl;
mOutputFile.close();
}
void
ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output, const bool nopreprocessoroutput) const
{
......
......@@ -157,15 +157,7 @@ public:
, const bool nopreprocessoroutput
) const;
void writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language, const bool nopreprocessoroutput) const;
void writeExternalFilesC(const string &basename, FileOutputType output) const;
void writeExternalFilesCC(const string &basename, FileOutputType output) const;
void writeExternalFilesJulia(const string &basename, FileOutputType output, const bool nopreprocessoroutput) const;
//! Writes C output files only => No further Matlab processing
void writeCOutputFiles(const string &basename) const;
void writeModelC(const string &basename) const;
//! Writes Cpp output files only => No further Matlab processing
void writeCCOutputFiles(const string &basename) const;
void writeModelCC(const string &basename) const;
void computeChecksum();
//! Write JSON representation of ModFile object
......
......@@ -220,54 +220,6 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
output << "end" << endl;
}
void
SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_model) const
{
string filename = basename + "_steadystate.c";
ofstream output;
output.open(filename, ios::out | ios::binary);
if (!output.is_open())
{
cerr << "ERROR: Can't open file " << filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
output << "#include <math.h>" << endl;
output << "void steadystate("
<< "const double *exo_, const double *params, double *ys_, int *info)" << endl
<< "// Steady state file generated by Dynare preprocessor" << endl
<< "{" << endl
<< " *info = 0;" << endl;
if (def_table.size() == 0)
{
output << " return;" << endl
<< "}" << endl;
return;
}
for (const auto & i : def_table)
{
const vector<int> &symb_ids = i.first;
output << " ";
if (symb_ids.size() > 1)
std::cout << "Error: in C, multiple returns are not permitted in steady_state_model" << std::endl;
auto it = variable_node_map.find({ symb_ids[0], 0 });
assert(it != variable_node_map.end());
if (it->second->get_type() == eModFileLocalVariable)
output << "double ";
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, oCSteadyStateFile);
output << "=";
i.second->writeOutput(output, oCSteadyStateFile);
output << ";" << endl;
}
output << " // Auxiliary equations" << endl;
static_model.writeAuxVarInitval(output, oCSteadyStateFile);
output << "}" << endl;
}
void
SteadyStateModel::writeJsonSteadyStateFile(ostream &output, bool transformComputingPass) const
{
......
......@@ -50,7 +50,6 @@ public:
\param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then use the "ys" in argument of the steady state file as initial values
*/
void writeSteadyStateFile(const string &basename, bool ramsey_model, bool julia) const;
void writeSteadyStateFileC(const string &basename, bool ramsey_model) const;
//! Writes LaTeX file with the equations of the dynamic model (for the steady state model)
void writeLatexSteadyStateFile(const string &basename) const;
//! Writes JSON output
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment