diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 63a59f89c248dae492b6fa32f89bb1211fe51b77..85521e2047b9847eff6f8fc6979728be4db8d61a 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -221,12 +221,11 @@ function global_initialization() options_.prior_mc = 20000; options_.prior_analysis_endo_var_list = []; - % block decomposition + minimum feedback set for steady state computation + % did model undergo block decomposition + minimum feedback set computation ? options_.block = 0; % model evaluated using simulate.dll options_.bytecode = 0; - % SWZ SBVAR options_.ms.freq = 1; diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index f753360047552fb4f82a5b7da47d50352b393dd1..b5c841e61b03d53eaf5eecec52a3c5db94a9337c 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -27,8 +27,8 @@ using namespace std; #include "ComputingTasks.hh" #include "Statement.hh" -SteadyStatement::SteadyStatement(const OptionsList &options_list_arg, StaticDllModel::mode_t mode_arg) : - options_list(options_list_arg), mode(mode_arg) +SteadyStatement::SteadyStatement(const OptionsList &options_list_arg) : + options_list(options_list_arg) { } @@ -41,9 +41,6 @@ void SteadyStatement::writeOutput(ostream &output, const string &basename) const { options_list.writeOutput(output); - /*if (mode == StaticDllModel::eSparseDLLMode) - output << "oo_.steady_state=simulate('steady');" << endl; - else*/ output << "steady;\n"; } @@ -82,8 +79,8 @@ void ModelInfoStatement::writeOutput(ostream &output, const string &basename) co } -SimulStatement::SimulStatement(const OptionsList &options_list_arg, DynamicModel::mode_t mode_arg, bool block_arg, bool byte_code_arg) : - options_list(options_list_arg), mode(mode_arg), byte_code(byte_code_arg), block(block_arg) +SimulStatement::SimulStatement(const OptionsList &options_list_arg, bool block_arg, bool byte_code_arg) : + options_list(options_list_arg), byte_code(byte_code_arg), block(block_arg) { } @@ -97,7 +94,7 @@ void SimulStatement::writeOutput(ostream &output, const string &basename) const { options_list.writeOutput(output); - if ((mode == DynamicModel::eStandardMode || mode == DynamicModel::eDLLMode) && !block) + if (!block) output << "simul(oo_.dr);\n"; else { @@ -119,10 +116,10 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg, - DynamicModel::mode_t mode_arg) : + bool block_arg) : symbol_list(symbol_list_arg), options_list(options_list_arg), - mode(mode_arg) + block(block_arg) { } @@ -150,7 +147,7 @@ StochSimulStatement::writeOutput(ostream &output, const string &basename) const { options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); - if (mode == DynamicModel::eStandardMode || mode == DynamicModel::eDLLMode) + if (!block) output << "info = stoch_simul(var_list_);" << endl; else output << "info = stoch_simul_sparse(var_list_);" << endl; diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index 4f06b07ab5972487393016e28fb50dfa7f595771..0ffe3c6f8ddaa656784fa198909cecdfc1170276 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -32,9 +32,8 @@ class SteadyStatement : public Statement { private: const OptionsList options_list; - const StaticDllModel::mode_t mode; public: - SteadyStatement(const OptionsList &options_list_arg, StaticDllModel::mode_t mode_arg); + SteadyStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct); virtual void writeOutput(ostream &output, const string &basename) const; }; @@ -53,11 +52,10 @@ class SimulStatement : public Statement { private: const OptionsList options_list; - const DynamicModel::mode_t mode; const bool byte_code; const bool block; public: - SimulStatement(const OptionsList &options_list_arg, DynamicModel::mode_t mode_arg, bool block_arg, bool byte_code_arg); + SimulStatement(const OptionsList &options_list_arg, bool block_arg, bool byte_code_arg); virtual void checkPass(ModFileStructure &mod_file_struct); virtual void writeOutput(ostream &output, const string &basename) const; }; @@ -77,11 +75,11 @@ class StochSimulStatement : public Statement private: const SymbolList symbol_list; const OptionsList options_list; - const DynamicModel::mode_t mode; + bool block; public: StochSimulStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg, - DynamicModel::mode_t mode_arg); + bool block_arg); virtual void checkPass(ModFileStructure &mod_file_struct); virtual void writeOutput(ostream &output, const string &basename) const; }; diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 160d4098ab3dbe47f111470e987ce03c9f4be587..49e8e82f95ef1b9172b9dc16693b605b8909279d 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -42,7 +42,6 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg, max_exo_lag(0), max_exo_lead(0), max_exo_det_lag(0), max_exo_det_lead(0), dynJacobianColsNbr(0), - mode(eStandardMode), cutoff(1e-15), markowitz(0.7), mfs(0), @@ -1131,7 +1130,7 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const << "% Warning : this file is generated automatically by Dynare" << endl << "% from model file (.mod)" << endl << endl; - writeDynamicModel(mDynamicModelFile); + writeDynamicModel(mDynamicModelFile, false); mDynamicModelFile.close(); } @@ -1159,7 +1158,7 @@ DynamicModel::writeDynamicCFile(const string &dynamic_basename) const << "#include \"mex.h\"" << endl; // Writing the function body - writeDynamicModel(mDynamicModelFile); + writeDynamicModel(mDynamicModelFile, true); // Writing the gateway routine mDynamicModelFile << "/* The gateway routine */" << endl @@ -1325,7 +1324,7 @@ DynamicModel::Write_Inf_To_Bin_File(const string &dynamic_basename, const string } void -DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const string &basename, const int mode) const +DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const string &basename) const { string sp; ofstream mDynamicModelFile; @@ -1681,14 +1680,14 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri } void -DynamicModel::writeDynamicModel(ostream &DynamicOutput) const +DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll) const { ostringstream model_output; // Used for storing model equations ostringstream jacobian_output; // Used for storing jacobian equations ostringstream hessian_output; // Used for storing Hessian equations ostringstream third_derivatives_output; - ExprNodeOutputType output_type = (mode != eDLLMode ? oMatlabDynamicModel : oCDynamicModel); + ExprNodeOutputType output_type = (use_dll ? oCDynamicModel : oMatlabDynamicModel); writeModelLocalVariables(model_output, output_type); @@ -1810,7 +1809,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const k += k2; } - if (mode == eStandardMode) + if (!use_dll) { DynamicOutput << "%" << endl << "% Model equations" << endl @@ -1890,22 +1889,8 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const } void -DynamicModel::writeOutput(ostream &output, const string &basename, bool block) const +DynamicModel::writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll) const { - output << "options_.model_mode = " << mode << ";" << endl; - - // Erase possible remnants of previous runs - if (mode != eStandardMode || block) - output << "delete('" << basename << "_dynamic.m');" << endl; - if (mode != eDLLMode) - output << "erase_compiled_function('" + basename + "_dynamic');" << endl; - - // Special setup for DLL or Sparse modes - if (mode == eDLLMode) - output << "mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_dynamic.c" << endl; - if (block) - output << "addpath " << basename << ";" << endl; - /* Writing initialisation for M_.lead_lag_incidence matrix M_.lead_lag_incidence is a matrix with as many columns as there are endogenous variables and as many rows as there are periods in the @@ -1937,8 +1922,8 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block) c output << ";"; } output << "]';" << endl; - //In case of sparse model, writes the block structure of the model + //In case of sparse model, writes the block structure of the model if (block) { //int prev_Simulation_Type=-1; @@ -2137,13 +2122,6 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block) c << "M_.NNZDerivatives(3) = " << NNZDerivatives[2] << ";" << endl; } -void -DynamicModel::writeOutputPostComputing(ostream &output, const string &basename, bool block) const -{ - if (block) - output << "rmpath " << basename << ";" << endl; -} - void DynamicModel::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m, bool dynamic) { @@ -2301,7 +2279,7 @@ DynamicModel::collect_first_order_derivatives_endogenous() void DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivatives, bool paramsDerivatives, - const eval_context_type &eval_context, bool no_tmp_terms, bool block) + const eval_context_type &eval_context, bool no_tmp_terms, bool block, bool use_dll) { assert(jacobianExo || !(hessian || thirdDerivatives || paramsDerivatives)); @@ -2372,11 +2350,11 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative } else if (!no_tmp_terms) - computeTemporaryTerms(mode == eStandardMode); + computeTemporaryTerms(!use_dll); } void -DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode) const +DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode, bool use_dll) const { int r; if(block && bytecode) @@ -2408,57 +2386,15 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode perror("ERROR"); exit(EXIT_FAILURE); } - writeSparseDynamicMFile(basename + "_dynamic", basename, mode); + writeSparseDynamicMFile(basename + "_dynamic", basename); block_triangular.Free_Block(block_triangular.ModelBlock); block_triangular.incidencematrix.Free_IM(); //block_triangular.Free_IM_X(block_triangular.First_IM_X); } - else if (mode == eDLLMode) + else if (use_dll) writeDynamicCFile(basename + "_dynamic"); - else if (mode == eStandardMode) + else writeDynamicMFile(basename + "_dynamic"); - /*switch (mode) - { - case eStandardMode: - writeDynamicMFile(basename + "_dynamic"); - break; - case eSparseMode: -#ifdef _WIN32 - r = mkdir(basename.c_str()); -#else - r = mkdir(basename.c_str(), 0777); -#endif - if (r < 0 && errno != EEXIST) - { - perror("ERROR"); - exit(EXIT_FAILURE); - } - writeSparseDynamicMFile(basename + "_dynamic", basename, mode); - block_triangular.Free_Block(block_triangular.ModelBlock); - block_triangular.incidencematrix.Free_IM(); - //block_triangular.Free_IM_X(block_triangular.First_IM_X); - break; - case eDLLMode: - writeDynamicCFile(basename + "_dynamic"); - break; - case eSparseDLLMode: - // create a directory to store all the files -#ifdef _WIN32 - r = mkdir(basename.c_str()); -#else - r = mkdir(basename.c_str(), 0777); -#endif - if (r < 0 && errno != EEXIST) - { - perror("ERROR"); - exit(EXIT_FAILURE); - } - writeModelEquationsCodeOrdered(basename + "_dynamic", block_triangular.ModelBlock, basename, map_idx); - block_triangular.Free_Block(block_triangular.ModelBlock); - block_triangular.incidencematrix.Free_IM(); - //block_triangular.Free_IM_X(block_triangular.First_IM_X); - break; - }*/ } void diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh index 21c935b8f929605b3737d4a819427e4ab6ef8dd6..92bd8171263d89058619718926f3d8b659726d64 100644 --- a/preprocessor/DynamicModel.hh +++ b/preprocessor/DynamicModel.hh @@ -32,14 +32,6 @@ using namespace std; class DynamicModel : public ModelTree { public: - //! The modes in which DynamicModel can work - enum mode_t - { - eStandardMode, //!< Standard mode (dynamic file in Matlab) - //eSparseMode, //!< Sparse mode (dynamic file in Matlab with block decomposition) - eDLLMode //!< DLL mode (dynamic file in C) - //eSparseDLLMode //!< Sparse DLL mode (dynamic file in C with block decomposition plus a binary file) - }; private: typedef map<pair<int, int>, int> deriv_id_table_t; //! Maps a pair (symbol_id, lag) to a deriv ID @@ -88,10 +80,10 @@ private: /*! \todo add third derivatives handling */ void writeDynamicCFile(const string &dynamic_basename) const; //! Writes dynamic model file when SparseDLL option is on - void writeSparseDynamicMFile(const string &dynamic_basename, const string &basename, const int mode) const; + void writeSparseDynamicMFile(const string &dynamic_basename, const string &basename) const; //! Writes the dynamic model equations and its derivatives /*! \todo add third derivatives handling in C output */ - void writeDynamicModel(ostream &DynamicOutput) const; + void writeDynamicModel(ostream &DynamicOutput, bool use_dll) const; //! Writes the Block reordred structure of the model in M output void writeModelEquationsOrdered_M(Model_Block *ModelBlock, const string &dynamic_basename) const; //! Writes the code of the Block reordred structure of the model in virtual machine bytecode @@ -146,8 +138,6 @@ private: public: DynamicModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants); - //! Mode in which the ModelTree is supposed to work (Matlab, DLL or SparseDLL) - mode_t mode; //! Adds a variable node /*! This implementation allows for non-zero lag */ virtual NodeID AddVariable(const string &name, int lag = 0); @@ -174,18 +164,17 @@ 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_type &eval_context, bool no_tmp_terms, bool block); + const eval_context_type &eval_context, bool no_tmp_terms, bool block, bool use_dll); //! Writes model initialization and lead/lag incidence matrix to output - void writeOutput(ostream &output, const string &basename, bool block) const; - //! Write statements to be added to the main M-file, after computational tasks - void writeOutputPostComputing(ostream &output, const string &basename, bool block) const; + void writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll) const; + //! Complete set to block decompose the model BlockTriangular block_triangular; //! Adds informations for simulation in a binary file void Write_Inf_To_Bin_File(const string &dynamic_basename, const string &bin_basename, const int &num, int &u_count_int, bool &file_open, bool is_two_boundaries) const; //! Writes dynamic model file - void writeDynamicFile(const string &basename, bool block, bool bytecode) const; + void writeDynamicFile(const string &basename, bool block, bool bytecode, bool use_dll) const; //! Writes file containing parameters derivatives void writeParamsDerivativesFile(const string &basename) const; //! Converts to static model (only the equations) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index f5877ed8c069d454289b67c552df95f45e02934a..827d961b5f8f265aeebdd4c8cc8175b5a43cbb48 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -446,19 +446,12 @@ histval_list : histval_list histval_elem histval_elem : symbol '(' signed_integer ')' EQUAL expression ';' { driver.hist_val($1, $3, $6); }; -/*model_block_options_list : model_block_options_list COMMA model_block_options - | model_block_options - ; - -model_block_options : o_cutoff - | o_mfs - ; -*/ - -model_options : BLOCK {driver.block(); } - | o_cutoff +model_options : BLOCK { driver.block(); } + | o_cutoff | o_mfs - | BYTECODE {driver.byte_code();} + | BYTECODE { driver.byte_code(); } + | USE_DLL { driver.use_dll(); } + | o_linear ; model_options_list : model_options_list COMMA model_options @@ -467,10 +460,6 @@ model_options_list : model_options_list COMMA model_options model : MODEL ';' { driver.begin_model(); } equation_list END { driver.reset_data_tree(); } - | MODEL '(' o_linear ')' ';' { driver.begin_model(); } - equation_list END { driver.reset_data_tree(); } - | MODEL '(' USE_DLL ')' ';' { driver.begin_model(); driver.use_dll(); } - equation_list END { driver.reset_data_tree(); } | MODEL '(' model_options_list ')' ';' { driver.begin_model(); } equation_list END { driver.reset_data_tree(); } ; diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index ce4094f9197254a5b84dafffdd339a117049a56b..e9e87af61a84ddef19d010dbed6dc8b2a8b11f52 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -27,10 +27,9 @@ ModFile::ModFile() : expressions_tree(symbol_table, num_constants), static_model(symbol_table, num_constants), static_dll_model(symbol_table, num_constants), dynamic_model(symbol_table, num_constants), - linear(false) + linear(false), block(false), byte_code(false), + use_dll(false) { - block = false; - byte_code = false; } ModFile::~ModFile() @@ -119,6 +118,18 @@ ModFile::checkPass() exit(EXIT_FAILURE); } + if (use_dll && (block || byte_code)) + { + cerr << "ERROR: In 'model' block, 'use_dll' option is not compatible with 'block' or 'bytecode'" << endl; + exit(EXIT_FAILURE); + } + + if (byte_code && !block) + { + cerr << "ERROR: In 'model' block, can't use option 'bytecode' without option 'block'" << endl; + exit(EXIT_FAILURE); + } + // Freeze the symbol table symbol_table.freeze(); @@ -159,7 +170,7 @@ ModFile::computingPass(bool no_tmp_terms) // Set things to compute for dynamic model if (mod_file_struct.simul_present) - dynamic_model.computingPass(false, false, false, false, global_eval_context, no_tmp_terms, block); + dynamic_model.computingPass(false, false, false, false, global_eval_context, no_tmp_terms, block, use_dll); else { if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) @@ -170,7 +181,7 @@ ModFile::computingPass(bool no_tmp_terms) bool hessian = mod_file_struct.order_option >= 2; bool thirdDerivatives = mod_file_struct.order_option == 3; bool paramsDerivatives = mod_file_struct.identification_present; - dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, false); + dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, false, use_dll); } } @@ -235,15 +246,31 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const if (linear == 1) mOutputFile << "options_.linear = 1;" << endl; + mOutputFile << "options_.block=" << block << ";" << endl + << "options_.bytecode=" << byte_code << ";" << endl; + + // Erase possible remnants of previous runs + if (block || byte_code) + mOutputFile << "delete('" << basename << "_dynamic.m');" << endl; + + if (byte_code) + mOutputFile << "delete('" << basename << "_static.m');" << endl; + + if (!use_dll) + mOutputFile << "erase_compiled_function('" + basename + "_dynamic');" << endl; + + // Compile the dynamic MEX file for use_dll option + if (use_dll) + mOutputFile << "mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_dynamic.c" << endl; + + // Add path for block option with M-files + if (block && !byte_code) + mOutputFile << "addpath " << basename << ";" << endl; + if (dynamic_model.equation_number() > 0) { - if (mod_file_struct.simul_present) - dynamic_model.writeOutput(mOutputFile, basename, block); - else - dynamic_model.writeOutput(mOutputFile, basename, false); - if(byte_code) - static_dll_model.writeOutput(mOutputFile, basename, block); - else + dynamic_model.writeOutput(mOutputFile, basename, block, byte_code, use_dll); + if (!byte_code) static_model.writeOutput(mOutputFile, block); } @@ -252,13 +279,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const it != statements.end(); it++) (*it)->writeOutput(mOutputFile, basename); - if (dynamic_model.equation_number() > 0) - { - if (mod_file_struct.simul_present) - dynamic_model.writeOutputPostComputing(mOutputFile, basename, block); - else - dynamic_model.writeOutputPostComputing(mOutputFile, basename, false); - } + // Remove path for block option with M-files + if (block && !byte_code) + mOutputFile << "rmpath " << basename << ";" << endl; mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl << "diary off" << endl @@ -273,10 +296,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const static_dll_model.writeStaticFile(basename, block); else static_model.writeStaticFile(basename, block); - if (mod_file_struct.simul_present) - dynamic_model.writeDynamicFile(basename, block, byte_code); - else - dynamic_model.writeDynamicFile(basename, false, false); + dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll); dynamic_model.writeParamsDerivativesFile(basename); } diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh index 80d31c25d61946c51600e4052fa32b97c3f0a212..f9e69a25a765b5aef3be93f8b4dd755b518f9d21 100644 --- a/preprocessor/ModFile.hh +++ b/preprocessor/ModFile.hh @@ -60,6 +60,8 @@ public: //! Is the model stored in baytecode format (byte_code=true) or in a M-file (byte_code=false) bool byte_code; + //! Deprecated option use_dll + bool use_dll; //! Global evaluation context /*! Filled using initval blocks and parameters initializations */ diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 4216f66fe12000aea6c8ec94aef9c74ff55bbc35..4fcce2916237cd9184df5ab2153518cd3f3014a4 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -347,7 +347,7 @@ ParsingDriver::forecast() void ParsingDriver::use_dll() { - dynamic_model->mode = DynamicModel::eDLLMode; + mod_file->use_dll = true; } void @@ -586,7 +586,7 @@ ParsingDriver::add_to_row(NodeID v) void ParsingDriver::steady() { - mod_file->addStatement(new SteadyStatement(options_list, mod_file->static_dll_model.mode)); + mod_file->addStatement(new SteadyStatement(options_list)); options_list.clear(); } @@ -685,7 +685,7 @@ void ParsingDriver::rplot() void ParsingDriver::stoch_simul() { - mod_file->addStatement(new StochSimulStatement(symbol_list, options_list, mod_file->dynamic_model.mode)); + mod_file->addStatement(new StochSimulStatement(symbol_list, options_list, mod_file->block)); symbol_list.clear(); options_list.clear(); } @@ -693,7 +693,7 @@ void ParsingDriver::stoch_simul() void ParsingDriver::simul() { - mod_file->addStatement(new SimulStatement(options_list, mod_file->dynamic_model.mode, mod_file->block, mod_file->byte_code)); + mod_file->addStatement(new SimulStatement(options_list, mod_file->block, mod_file->byte_code)); options_list.clear(); } diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc index 527b9af3f502009f4779d3743653155973949ed0..35df9360dbb48ba868e38b9cd9c2ecd8283e6884 100644 --- a/preprocessor/Statement.cc +++ b/preprocessor/Statement.cc @@ -30,9 +30,7 @@ ModFileStructure::ModFileStructure() : order_option(0), bvar_density_present(false), bvar_forecast_present(false), - identification_present(false), - steady_block_mfs_option(false), - steady_block_mfs_dll_option(false) + identification_present(false) { } diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh index fd519c52cf125e5d343fb4a6c8cf9ca8e97b538f..d51d55a47f1cbba279488f2b077059bc17068712 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -60,10 +60,6 @@ public: bool ms_sbvar_present; //! Whether an identification statement is present bool identification_present; - //! Whether the option "block_mfs" is used on steady statement - bool steady_block_mfs_option; - //! Whether the option "block_mfs_dll" is used on steady statement - bool steady_block_mfs_dll_option; }; class Statement diff --git a/preprocessor/StaticDllModel.cc b/preprocessor/StaticDllModel.cc index e186e2b025ca787cfde62ede6a19ba7e5f6750cb..f2c0e5bdffee85fdf709586d17a1ec792f55b5e9 100644 --- a/preprocessor/StaticDllModel.cc +++ b/preprocessor/StaticDllModel.cc @@ -42,7 +42,6 @@ StaticDllModel::StaticDllModel(SymbolTable &symbol_table_arg, max_exo_lag(0), max_exo_lead(0), max_exo_det_lag(0), max_exo_det_lead(0), dynJacobianColsNbr(0), - mode(eStandardMode), cutoff(1e-15), markowitz(0.7), mfs(0), @@ -822,34 +821,6 @@ StaticDllModel::writeSparseStaticMFile(const string &static_basename, const stri chdir(".."); } - -void -StaticDllModel::writeOutput(ostream &output, const string &basename, bool block) const -{ - output << "options_.block=" << block << ";" << endl; - output << "options_.bytecode=1;" << endl; - output << "options_.model_mode = " << mode << ";" << endl; - - // Erase possible remnants of previous runs - if (mode != eStandardMode) - output << "delete('" << basename << "_static.m');" << endl; - if (mode != eDLLMode) - output << "erase_compiled_function('" + basename + "_static');" << endl; - - // Special setup for DLL or Sparse modes - if (mode == eDLLMode) - output << "mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_static.c" << endl; - if (block) - output << "addpath " << basename << ";" << endl; -} - -void -StaticDllModel::writeOutputPostComputing(ostream &output, const string &basename, bool block) const -{ - if (block) - output << "rmpath " << basename << ";" << endl; -} - void StaticDllModel::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m, bool dynamic) { @@ -1008,6 +979,7 @@ StaticDllModel::collect_first_order_derivatives_endogenous() void StaticDllModel::computingPass(const eval_context_type &eval_context, bool no_tmp_terms, bool block) { + assert(block); // Computes static jacobian columns computeStatJacobianCols(); @@ -1027,8 +999,7 @@ StaticDllModel::computingPass(const eval_context_type &eval_context, bool no_tmp << " - order 1" << endl; computeJacobian(vars); //cout << "mode=" << mode << " eSparseDLLMode=" << eSparseDLLMode << " eSparseMode=" << eSparseMode << "\n"; - if (block) - { + BuildIncidenceMatrix(); jacob_map j_m; @@ -1062,78 +1033,30 @@ StaticDllModel::computingPass(const eval_context_type &eval_context, bool no_tmp if (!no_tmp_terms) computeTemporaryTermsOrdered(block_triangular.ModelBlock); - } - else - if (!no_tmp_terms) - computeTemporaryTerms(mode == eStandardMode); } void StaticDllModel::writeStaticFile(const string &basename, bool block) const { int r; - if(block) - { + + assert(block); + #ifdef _WIN32 - r = mkdir(basename.c_str()); + r = mkdir(basename.c_str()); #else - r = mkdir(basename.c_str(), 0777); + r = mkdir(basename.c_str(), 0777); #endif - if (r < 0 && errno != EEXIST) - { - perror("ERROR"); - exit(EXIT_FAILURE); - } - writeModelEquationsCodeOrdered(basename + "_static", block_triangular.ModelBlock, basename, map_idx); - block_triangular.Free_Block(block_triangular.ModelBlock); - block_triangular.incidencematrix.Free_IM(); - } - else - { - } - /*switch (mode) + if (r < 0 && errno != EEXIST) { - case eStandardMode: - break; - case eSparseMode: -#ifdef _WIN32 - r = mkdir(basename.c_str()); -#else - r = mkdir(basename.c_str(), 0777); -#endif - if (r < 0 && errno != EEXIST) - { - perror("ERROR"); - exit(EXIT_FAILURE); - } - writeSparseStaticMFile(basename + "_static", basename, mode); - block_triangular.Free_Block(block_triangular.ModelBlock); - block_triangular.incidencematrix.Free_IM(); - //block_triangular.Free_IM_X(block_triangular.First_IM_X); - break; - case eDLLMode: - break; - case eSparseDLLMode: - // create a directory to store all the files -#ifdef _WIN32 - r = mkdir(basename.c_str()); -#else - r = mkdir(basename.c_str(), 0777); -#endif - if (r < 0 && errno != EEXIST) - { - perror("ERROR"); - exit(EXIT_FAILURE); - } - writeModelEquationsCodeOrdered(basename + "_static", block_triangular.ModelBlock, basename, map_idx); - block_triangular.Free_Block(block_triangular.ModelBlock); - block_triangular.incidencematrix.Free_IM(); - //block_triangular.Free_IM_X(block_triangular.First_IM_X); - break; - }*/ + perror("ERROR"); + exit(EXIT_FAILURE); + } + writeModelEquationsCodeOrdered(basename + "_static", block_triangular.ModelBlock, basename, map_idx); + block_triangular.Free_Block(block_triangular.ModelBlock); + block_triangular.incidencematrix.Free_IM(); } - int StaticDllModel::computeDerivID(int symb_id, int lag) { diff --git a/preprocessor/StaticDllModel.hh b/preprocessor/StaticDllModel.hh index 8812a1d6c5cc4b0b39137258dd6a5d250d9e0a3d..1254e4fa1066444bf474d14621ca7808777d4d68 100644 --- a/preprocessor/StaticDllModel.hh +++ b/preprocessor/StaticDllModel.hh @@ -30,15 +30,6 @@ using namespace std; //! Stores a static model class StaticDllModel : public ModelTree { -public: - //! The modes in which StaticDllModel can work - enum mode_t - { - eStandardMode, //!< Standard mode (static file in Matlab) - //eSparseMode, //!< Sparse mode (static file in Matlab with block decomposition) - eDLLMode //!< DLL mode (static file in C) - //eSparseDLLMode //!< Sparse DLL mode (static file in C with block decomposition plus a binary file) - }; private: typedef map<pair<int, int>, int> deriv_id_table_t; //! Maps a pair (symbol_id, lag) to a deriv ID @@ -141,8 +132,6 @@ private: public: StaticDllModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants); - //! Mode in which the ModelTree is supposed to work (Matlab, DLL or SparseDLL) - mode_t mode; //! Adds a variable node /*! This implementation allows for non-zero lag */ virtual NodeID AddVariable(const string &name, int lag = 0); @@ -168,10 +157,6 @@ public: \param no_tmp_terms if true, no temporary terms will be computed in the static files */ void computingPass(const eval_context_type &eval_context, bool no_tmp_terms, bool block); - //! Writes model initialization and lead/lag incidence matrix to output - void writeOutput(ostream &output, const string &basename, bool block) const; - //! Write statements to be added to the main M-file, after computational tasks - void writeOutputPostComputing(ostream &output, const string &basename, bool block) const; //! Complete set to block decompose the model BlockTriangular block_triangular; //! Adds informations for simulation in a binary file diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc index dc380bb295cd697f1796eb5784c09a628effc929..bda4f1ec5d1926989f45de493cd9ecb5b3353384 100644 --- a/preprocessor/StaticModel.cc +++ b/preprocessor/StaticModel.cc @@ -558,7 +558,7 @@ StaticModel::writeOutput(ostream &output, bool block) const { if (!block) return; - output << "options_.block=" << block << ";" << endl; + output << "M_.blocksMFS = cell(" << blocksMFS.size() << ", 1);" << endl; for(int b = 0; b < (int) blocks.size(); b++) { diff --git a/preprocessor/StaticModel.hh b/preprocessor/StaticModel.hh index ac4dda213ce3bde9360083af03b4e42a737dd226..ddc5f0eae304c881049d2f8e2315d1afdcd0d404 100644 --- a/preprocessor/StaticModel.hh +++ b/preprocessor/StaticModel.hh @@ -89,7 +89,7 @@ public: StaticModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants); //! Execute computations (derivation) /*! - \param block_mfs whether block decomposition and minimum feedback set should be computed + \param block whether block decomposition and minimum feedback set should be computed \param hessian whether Hessian (w.r. to endogenous only) should be computed \param no_tmp_terms if true, no temporary terms will be computed in the static and dynamic files */ void computingPass(bool block, bool hessian, bool no_tmp_terms);