1 /* 2 * Copyright © 2007-2017 Dynare Team 3 * 4 * This file is part of Dynare. 5 * 6 * Dynare is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Dynare is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Dynare. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef INTERPRETER_HH_INCLUDED 21 #define INTERPRETER_HH_INCLUDED 22 23 #include <stack> 24 #include <vector> 25 #include <string> 26 #include <cmath> 27 #define BYTE_CODE 28 #include "CodeInterpreter.hh" 29 #include "SparseMatrix.hh" 30 #include "Evaluate.hh" 31 #ifdef LINBCG 32 # include "linbcg.hh" 33 #endif 34 #ifndef DEBUG_EX 35 # include <dynmex.h> 36 #else 37 # include "mex_interface.hh" 38 #endif 39 40 //#define DEBUGC 41 42 using namespace std; 43 44 class Interpreter : public dynSparseMatrix 45 { 46 private: 47 vector<int> previous_block_exogenous; 48 protected: 49 void evaluate_a_block(bool initialization); 50 int simulate_a_block(vector_table_conditional_local_type vector_table_conditional_local); 51 void print_a_block(); 52 string elastic(string str, unsigned int len, bool left); 53 public: 54 ~Interpreter(); 55 Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, double *steady_x_arg, 56 double *direction_arg, size_t y_size_arg, 57 size_t nb_row_x_arg, size_t nb_row_xd_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, 58 int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_arg, double slowc_arg, int y_decal_arg, double markowitz_c_arg, 59 string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg, 60 bool global_temporary_terms_arg, bool print_arg, bool print_error_arg, mxArray *GlobalTemporaryTerms_arg, 61 bool steady_state_arg, bool print_it_arg, int col_x_arg, int col_y_arg 62 #ifdef CUDA 63 , const int CUDA_device, cublasHandle_t cublas_handle_arg, cusparseHandle_t cusparse_handle_arg, cusparseMatDescr_t descr_arg 64 #endif 65 ); 66 bool extended_path(string file_name, string bin_basename, bool evaluate, int block, int &nb_blocks, int nb_periods, vector<s_plan> sextended_path, vector<s_plan> sconstrained_extended_path, vector<string> dates, table_conditional_global_type table_conditional_global); 67 bool compute_blocks(string file_name, string bin_basename, bool evaluate, int block, int &nb_blocks); 68 void check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector<s_plan> sconstrained_extended_path); 69 bool MainLoop(string bin_basename, CodeLoad code, bool evaluate, int block, bool last_call, bool constrained, vector<s_plan> sconstrained_extended_path, vector_table_conditional_local_type vector_table_conditional_local); 70 void ReadCodeFile(string file_name, CodeLoad &code); 71 72 inline mxArray * get_jacob(int block_num)73 get_jacob(int block_num) 74 { 75 return jacobian_block[block_num]; 76 }; 77 inline mxArray * get_jacob_exo(int block_num)78 get_jacob_exo(int block_num) 79 { 80 return jacobian_exo_block[block_num]; 81 }; 82 inline mxArray * get_jacob_exo_det(int block_num)83 get_jacob_exo_det(int block_num) 84 { 85 return jacobian_det_exo_block[block_num]; 86 }; 87 inline mxArray * get_jacob_other_endo(int block_num)88 get_jacob_other_endo(int block_num) 89 { 90 return jacobian_other_endo_block[block_num]; 91 }; 92 inline vector<double> get_residual()93 get_residual() 94 { 95 return residual; 96 }; 97 inline mxArray * get_Temporary_Terms()98 get_Temporary_Terms() 99 { 100 return GlobalTemporaryTerms; 101 }; 102 }; 103 104 #endif 105