From 50a4d50821122e9ef3f763390477584bc2f44e23 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 23 Feb 2016 13:55:02 +0100 Subject: [PATCH] preprocessor: introduce new option compute_xrefs, #1125 --- DynamicModel.cc | 13 ++++++++----- DynamicModel.hh | 6 +++--- DynareMain.cc | 12 ++++++++---- DynareMain2.cc | 9 +++++---- ModFile.cc | 16 ++++++++-------- ModFile.hh | 8 +++++--- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 2d4943cc..c48ee5e9 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2016 Dynare Team * * This file is part of Dynare. * @@ -2466,7 +2466,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia } void -DynamicModel::writeOutput(ostream &output, const string &basename, bool block_decomposition, bool byte_code, bool use_dll, int order, bool estimation_present, bool julia) const +DynamicModel::writeOutput(ostream &output, const string &basename, bool block_decomposition, bool byte_code, bool use_dll, int order, bool estimation_present, bool compute_xrefs, bool julia) const { /* Writing initialisation for M_.lead_lag_incidence matrix M_.lead_lag_incidence is a matrix with as many columns as there are @@ -3049,7 +3049,8 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de output << modstruct << "params = " << (julia ? "fill(NaN, " : "NaN(") << symbol_table.param_nbr() << ", 1);" << endl; - writeXrefs(output); + if (compute_xrefs) + writeXrefs(output); // Write number of non-zero derivatives // Use -1 if the derivatives have not been computed @@ -3094,7 +3095,8 @@ DynamicModel::runTrendTest(const eval_context_t &eval_context) void DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives, - const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, bool bytecode) + const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, + bool bytecode, bool compute_xrefs) { assert(jacobianExo || !(hessian || thirdDerivatives || paramsDerivatives)); @@ -3203,7 +3205,8 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative computeTemporaryTermsMapping(); } - computeXrefs(); + if (compute_xrefs) + computeXrefs(); } map >, pair >, int> diff --git a/DynamicModel.hh b/DynamicModel.hh index fbb18b22..13f18192 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2016 Dynare Team * * This file is part of Dynare. * @@ -213,9 +213,9 @@ public: \param no_tmp_terms if true, no temporary terms will be computed in the dynamic files */ void computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives, - const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, bool bytecode); + const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll, bool bytecode, bool compute_xrefs); //! Writes model initialization and lead/lag incidence matrix to output - void writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present, bool julia) const; + void writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present, bool compute_xrefs, bool julia) const; //! Adds informations for simulation in a binary file void Write_Inf_To_Bin_File_Block(const string &dynamic_basename, const string &bin_basename, diff --git a/DynareMain.cc b/DynareMain.cc index 56456f81..ead3b74a 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2016 Dynare Team * * This file is part of Dynare. * @@ -40,7 +40,8 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, ConfigFile &config_file, WarningConsolidation &warnings_arg, bool nostrict, bool check_model_changes, - bool minimal_workspace, FileOutputType output_mode, LanguageOutputType lang + bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode, + LanguageOutputType lang #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -55,7 +56,7 @@ usage() { cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]" - << " [-D[=]] [-I/path] [nostrict] [fast] [minimal_workspace] [output=dynamic|first|second|third] [language=C|C++|julia]" + << " [-D[=]] [-I/path] [nostrict] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=C|C++|julia]" #if defined(_WIN32) || defined(__CYGWIN32__) << " [cygwin] [msvc]" #endif @@ -105,6 +106,7 @@ main(int argc, char **argv) bool nostrict = false; bool check_model_changes = false; bool minimal_workspace = false; + bool compute_xrefs = false; map defines; vector path; FileOutputType output_mode = none; @@ -178,6 +180,8 @@ main(int argc, char **argv) check_model_changes = true; else if (!strcmp(argv[arg], "minimal_workspace")) minimal_workspace = true; + else if (!strcmp(argv[arg], "compute_xrefs")) + compute_xrefs = true; else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "parallel", 8)) { parallel = true; @@ -314,7 +318,7 @@ main(int argc, char **argv) main2(macro_output, basename, debug, clear_all, clear_global, no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive, parallel, config_file, warnings, nostrict, check_model_changes, minimal_workspace, - output_mode, language + compute_xrefs, output_mode, language #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc #endif diff --git a/DynareMain2.cc b/DynareMain2.cc index 0b335b11..4bead835 100644 --- a/DynareMain2.cc +++ b/DynareMain2.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2015 Dynare Team + * Copyright (C) 2008-2016 Dynare Team * * This file is part of Dynare. * @@ -29,7 +29,8 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, ConfigFile &config_file, WarningConsolidation &warnings, bool nostrict, bool check_model_changes, - bool minimal_workspace, FileOutputType output_mode, LanguageOutputType language + bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode, + LanguageOutputType language #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -50,14 +51,14 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear mod_file->evalAllExpressions(warn_uninit); // Do computations - mod_file->computingPass(no_tmp_terms, output_mode); + mod_file->computingPass(no_tmp_terms, output_mode, compute_xrefs); // Write outputs if (output_mode != none) mod_file->writeExternalFiles(basename, output_mode, language); else mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, - nointeractive, config_file, check_model_changes, minimal_workspace + nointeractive, config_file, check_model_changes, minimal_workspace, compute_xrefs #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc #endif diff --git a/ModFile.cc b/ModFile.cc index d3748dca..42dbdcbb 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2015 Dynare Team + * Copyright (C) 2006-2016 Dynare Team * * This file is part of Dynare. * @@ -470,7 +470,7 @@ ModFile::transformPass(bool nostrict) } void -ModFile::computingPass(bool no_tmp_terms, FileOutputType output) +ModFile::computingPass(bool no_tmp_terms, FileOutputType output, bool compute_xrefs) { // Mod file may have no equation (for example in a standalone BVAR estimation) if (dynamic_model.equation_number() > 0) @@ -503,7 +503,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) || mod_file_struct.calib_smoother_present) { if (mod_file_struct.perfect_foresight_solver_present) - dynamic_model.computingPass(true, false, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + dynamic_model.computingPass(true, false, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs); else { if (mod_file_struct.stoch_simul_present @@ -525,11 +525,11 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) || mod_file_struct.estimation_analytic_derivation || output == third; bool paramsDerivatives = mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation; - dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs); } } else // No computing task requested, compute derivatives up to 2nd order by default - dynamic_model.computingPass(true, true, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + dynamic_model.computingPass(true, true, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code, compute_xrefs); } for (vector::iterator it = statements.begin(); @@ -540,7 +540,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) void ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, - bool check_model_changes, bool minimal_workspace + bool check_model_changes, bool minimal_workspace, bool compute_xrefs #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -754,7 +754,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo if (dynamic_model.equation_number() > 0) { - dynamic_model.writeOutput(mOutputFile, basename, block, byte_code, use_dll, mod_file_struct.order_option, mod_file_struct.estimation_present, false); + dynamic_model.writeOutput(mOutputFile, basename, block, byte_code, use_dll, mod_file_struct.order_option, mod_file_struct.estimation_present, compute_xrefs, false); if (!no_static) static_model.writeOutput(mOutputFile, block); } @@ -1153,7 +1153,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) { dynamic_model.writeOutput(jlOutputFile, basename, false, false, false, mod_file_struct.order_option, - mod_file_struct.estimation_present, true); + mod_file_struct.estimation_present, false, true); if (!no_static) { static_model.writeStaticFile(basename, false, false, false, true); diff --git a/ModFile.hh b/ModFile.hh index b53cca5e..66c9fb6b 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2015 Dynare Team + * Copyright (C) 2006-2016 Dynare Team * * This file is part of Dynare. * @@ -137,7 +137,8 @@ public: void transformPass(bool nostrict); //! Execute computations /*! \param no_tmp_terms if true, no temporary terms will be computed in the static and dynamic files */ - void computingPass(bool no_tmp_terms, FileOutputType output); + /*! \param compute_xrefs if true, equation cross references will be computed */ + void computingPass(bool no_tmp_terms, FileOutputType output, bool compute_xrefs); //! Writes Matlab/Octave output files /*! \param basename The base name used for writing output files. Should be the name of the mod file without its extension @@ -147,10 +148,11 @@ public: \param nointeractive Should Dynare request user input? \param cygwin Should the MEX command of use_dll be adapted for Cygwin? \param msvc Should the MEX command of use_dll be adapted for MSVC? + \param compute_xrefs if true, equation cross references will be computed */ void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, - bool check_model_changes, bool minimal_workspace + bool check_model_changes, bool minimal_workspace, bool compute_xrefs #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif