New options for block decomposition and bytecode (see http://www.dynare.org/DynareWiki/ByteCode):
- the options "sparse_dll" and "sparse" are no more available. They are replaced by combinations of block (for block decomposition) and bytecode (for model stored in a binary file) - markowitz is now an option of simul and steady commands git-svn-id: https://www.dynare.org/svn/dynare/trunk@2873 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
a693b8310d
commit
0a816a4e74
|
@ -129,7 +129,10 @@ BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prolog
|
|||
for (int i = 0; i < n; i++)
|
||||
for (int j = 0; j < n; j++)
|
||||
if (IM0[(i+prologue) * equation_number+j+prologue])
|
||||
add_edge(i + n, j, g);
|
||||
{
|
||||
//printf("equation=%3d variable=%3d\n",i,j);
|
||||
add_edge(i + n, j, g);
|
||||
}
|
||||
|
||||
// Compute maximum cardinality matching
|
||||
typedef vector<graph_traits<BipartiteGraph>::vertex_descriptor> mate_map_t;
|
||||
|
@ -931,10 +934,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
int count_Block, count_Equ;
|
||||
bool *SIM0, *SIM00;
|
||||
|
||||
SIM0 = (bool *) malloc(n * n * sizeof(bool));
|
||||
memcpy(SIM0, IM_0, n*n*sizeof(bool));
|
||||
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM, SIM0);
|
||||
free(SIM0);
|
||||
|
||||
|
||||
int counted = 0;
|
||||
if (prologue+epilogue < n)
|
||||
|
@ -963,8 +963,10 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
memset(SIM0, 0, n*n*sizeof(bool));
|
||||
SIM00 = (bool *) malloc(n * n * sizeof(bool));
|
||||
memset(SIM00, 0, n*n*sizeof(bool));
|
||||
//cout << "---------------------------------\n";
|
||||
for (map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++)
|
||||
{
|
||||
//printf("iter->second=% 1.10f iter->first.first=%3d iter->first.second=%3d bi=%f\n", iter->second, iter->first.first, iter->first.second, bi);
|
||||
if (fabs(iter->second) > max(bi, cutoff))
|
||||
{
|
||||
SIM0[iter->first.first*n+iter->first.second] = 1;
|
||||
|
@ -999,6 +1001,11 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
}
|
||||
}
|
||||
|
||||
SIM0 = (bool *) malloc(n * n * sizeof(bool));
|
||||
memcpy(SIM0, IM_0, n*n*sizeof(bool));
|
||||
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM, SIM0);
|
||||
free(SIM0);
|
||||
|
||||
V_Equation_Type = Equation_Type_determination(equations, first_order_endo_derivatives, Index_Var_IM, Index_Equ_IM, mfs);
|
||||
|
||||
cout << "Finding the optimal block decomposition of the model ...\n";
|
||||
|
|
|
@ -35,10 +35,6 @@ SteadyStatement::SteadyStatement(const OptionsList &options_list_arg, StaticDllM
|
|||
void
|
||||
SteadyStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
if (options_list.num_options.find("block_mfs") != options_list.num_options.end())
|
||||
mod_file_struct.steady_block_mfs_option = true;
|
||||
else if (options_list.num_options.find("block_mfs_dll") != options_list.num_options.end())
|
||||
mod_file_struct.steady_block_mfs_dll_option = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -86,8 +82,8 @@ void ModelInfoStatement::writeOutput(ostream &output, const string &basename) co
|
|||
}
|
||||
|
||||
|
||||
SimulStatement::SimulStatement(const OptionsList &options_list_arg, DynamicModel::mode_t mode_arg) :
|
||||
options_list(options_list_arg), mode(mode_arg)
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -101,7 +97,7 @@ void
|
|||
SimulStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
options_list.writeOutput(output);
|
||||
if (mode == DynamicModel::eStandardMode || mode == DynamicModel::eDLLMode)
|
||||
if ((mode == DynamicModel::eStandardMode || mode == DynamicModel::eDLLMode) && !block)
|
||||
output << "simul(oo_.dr);\n";
|
||||
else
|
||||
{
|
||||
|
@ -113,7 +109,7 @@ SimulStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< " read_data_;" << endl
|
||||
<< " end" << endl
|
||||
<< "end" << endl;
|
||||
if (mode == DynamicModel::eSparseDLLMode)
|
||||
if (byte_code)
|
||||
output << "oo_.endo_simul=simulate;" << endl;
|
||||
else
|
||||
output << basename << "_dynamic;" << endl;
|
||||
|
@ -922,7 +918,7 @@ PlannerObjectiveStatement::computingPass()
|
|||
void
|
||||
PlannerObjectiveStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
model_tree->writeStaticFile(basename + "_objective");
|
||||
model_tree->writeStaticFile(basename + "_objective", false);
|
||||
}
|
||||
|
||||
BVARDensityStatement::BVARDensityStatement(int maxnlags_arg, const OptionsList &options_list_arg) :
|
||||
|
|
|
@ -54,8 +54,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);
|
||||
SimulStatement(const OptionsList &options_list_arg, DynamicModel::mode_t mode_arg, bool block_arg, bool byte_code_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
|
|
@ -337,6 +337,7 @@ DynamicModel::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const strin
|
|||
<< " % // Simulation type "
|
||||
<< BlockTriangular::BlockSim(ModelBlock->Block_List[j].Simulation_Type) << " //" << endl
|
||||
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
|
||||
output << " global options_;" << endl;
|
||||
//The Temporary terms
|
||||
//output << " relax = 1;\n";
|
||||
if (ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD
|
||||
|
@ -359,9 +360,9 @@ DynamicModel::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const strin
|
|||
output << " else\n";
|
||||
if (ModelBlock->Block_List[j].Simulation_Type==SOLVE_TWO_BOUNDARIES_COMPLETE || ModelBlock->Block_List[j].Simulation_Type==SOLVE_TWO_BOUNDARIES_SIMPLE)
|
||||
{
|
||||
output << " g1 = spalloc(" << (ModelBlock->Block_List[j].Size-ModelBlock->Block_List[j].Nb_Recursives)*ModelBlock->Periods
|
||||
<< ", " << (ModelBlock->Block_List[j].Size-ModelBlock->Block_List[j].Nb_Recursives)*(ModelBlock->Periods+ModelBlock->Block_List[j].Max_Lag+ModelBlock->Block_List[j].Max_Lead+1)
|
||||
<< ", " << nze*ModelBlock->Periods << ");\n";
|
||||
output << " g1 = spalloc(" << (ModelBlock->Block_List[j].Size-ModelBlock->Block_List[j].Nb_Recursives) << "*options_.periods, "
|
||||
<< (ModelBlock->Block_List[j].Size-ModelBlock->Block_List[j].Nb_Recursives) << "*(options_.periods+" << ModelBlock->Block_List[j].Max_Lag+ModelBlock->Block_List[j].Max_Lead+1 << ")"
|
||||
<< ", " << nze << "*options_.periods);\n";
|
||||
/*output << " g1_tmp_r = spalloc(" << (ModelBlock->Block_List[j].Nb_Recursives)
|
||||
<< ", " << (ModelBlock->Block_List[j].Size)*(ModelBlock->Block_List[j].Max_Lag+ModelBlock->Block_List[j].Max_Lead+1)
|
||||
<< ", " << nze << ");\n";
|
||||
|
@ -1278,7 +1279,6 @@ DynamicModel::Write_Inf_To_Bin_File(const string &dynamic_basename, const string
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*for (int m=0;m<=block_triangular.ModelBlock->Block_List[num].Max_Lead+block_triangular.ModelBlock->Block_List[num].Max_Lag;m++)
|
||||
{
|
||||
int k1=m-block_triangular.ModelBlock->Block_List[num].Max_Lag;
|
||||
|
@ -1296,10 +1296,10 @@ DynamicModel::Write_Inf_To_Bin_File(const string &dynamic_basename, const string
|
|||
}*/
|
||||
if (is_two_boundaries)
|
||||
{
|
||||
for (j=0;j<Size;j++)
|
||||
/*for (j=0;j<Size;j++)
|
||||
{
|
||||
int eqr1=j;
|
||||
int varr=/*block_triangular.ModelBlock->Block_List[num].Size*/Size*(block_triangular.periods
|
||||
int varr=Size*(block_triangular.periods
|
||||
+block_triangular.incidencematrix.Model_Max_Lead_Endo);
|
||||
int k1=0;
|
||||
SaveCode.write(reinterpret_cast<char *>(&eqr1), sizeof(eqr1));
|
||||
|
@ -1307,7 +1307,8 @@ DynamicModel::Write_Inf_To_Bin_File(const string &dynamic_basename, const string
|
|||
SaveCode.write(reinterpret_cast<char *>(&k1), sizeof(k1));
|
||||
SaveCode.write(reinterpret_cast<char *>(&eqr1), sizeof(eqr1));
|
||||
u_count_int++;
|
||||
}
|
||||
}*/
|
||||
u_count_int+=Size;
|
||||
}
|
||||
//cout << "u_count_int=" << u_count_int << "\n";
|
||||
for (j=block_triangular.ModelBlock->Block_List[num].Nb_Recursives;j<block_triangular.ModelBlock->Block_List[num].Size;j++)
|
||||
|
@ -1687,7 +1688,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const
|
|||
ostringstream hessian_output; // Used for storing Hessian equations
|
||||
ostringstream third_derivatives_output;
|
||||
|
||||
ExprNodeOutputType output_type = (mode == eStandardMode || mode==eSparseMode ? oMatlabDynamicModel : oCDynamicModel);
|
||||
ExprNodeOutputType output_type = (mode != eDLLMode ? oMatlabDynamicModel : oCDynamicModel);
|
||||
|
||||
writeModelLocalVariables(model_output, output_type);
|
||||
|
||||
|
@ -1889,12 +1890,12 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeOutput(ostream &output, const string &basename) const
|
||||
DynamicModel::writeOutput(ostream &output, const string &basename, bool block) const
|
||||
{
|
||||
output << "options_.model_mode = " << mode << ";" << endl;
|
||||
|
||||
// Erase possible remnants of previous runs
|
||||
if (mode != eStandardMode)
|
||||
if (mode != eStandardMode || block)
|
||||
output << "delete('" << basename << "_dynamic.m');" << endl;
|
||||
if (mode != eDLLMode)
|
||||
output << "erase_compiled_function('" + basename + "_dynamic');" << endl;
|
||||
|
@ -1902,7 +1903,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename) const
|
|||
// Special setup for DLL or Sparse modes
|
||||
if (mode == eDLLMode)
|
||||
output << "mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_dynamic.c" << endl;
|
||||
if (mode == eSparseMode || mode == eSparseDLLMode)
|
||||
if (block)
|
||||
output << "addpath " << basename << ";" << endl;
|
||||
|
||||
/* Writing initialisation for M_.lead_lag_incidence matrix
|
||||
|
@ -1938,7 +1939,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename) const
|
|||
output << "]';" << endl;
|
||||
//In case of sparse model, writes the block structure of the model
|
||||
|
||||
if (mode==eSparseMode || mode==eSparseDLLMode)
|
||||
if (block)
|
||||
{
|
||||
//int prev_Simulation_Type=-1;
|
||||
//bool skip_the_head;
|
||||
|
@ -2137,9 +2138,9 @@ DynamicModel::writeOutput(ostream &output, const string &basename) const
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeOutputPostComputing(ostream &output, const string &basename) const
|
||||
DynamicModel::writeOutputPostComputing(ostream &output, const string &basename, bool block) const
|
||||
{
|
||||
if (mode == eSparseMode || mode == eSparseDLLMode)
|
||||
if (block)
|
||||
output << "rmpath " << basename << ";" << endl;
|
||||
}
|
||||
|
||||
|
@ -2300,7 +2301,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)
|
||||
const eval_context_type &eval_context, bool no_tmp_terms, bool block)
|
||||
{
|
||||
assert(jacobianExo || !(hessian || thirdDerivatives || paramsDerivatives));
|
||||
|
||||
|
@ -2343,7 +2344,7 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative
|
|||
computeThirdDerivatives(vars);
|
||||
}
|
||||
|
||||
if (mode == eSparseDLLMode || mode == eSparseMode)
|
||||
if (block)
|
||||
{
|
||||
BuildIncidenceMatrix();
|
||||
|
||||
|
@ -2375,10 +2376,48 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeDynamicFile(const string &basename) const
|
||||
DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode) const
|
||||
{
|
||||
int r;
|
||||
switch (mode)
|
||||
if(block && bytecode)
|
||||
{
|
||||
#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);
|
||||
}
|
||||
else if(block && !bytecode)
|
||||
{
|
||||
#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);
|
||||
}
|
||||
else if (mode == eDLLMode)
|
||||
writeDynamicCFile(basename + "_dynamic");
|
||||
else if (mode == eStandardMode)
|
||||
writeDynamicMFile(basename + "_dynamic");
|
||||
/*switch (mode)
|
||||
{
|
||||
case eStandardMode:
|
||||
writeDynamicMFile(basename + "_dynamic");
|
||||
|
@ -2419,7 +2458,7 @@ DynamicModel::writeDynamicFile(const string &basename) const
|
|||
block_triangular.incidencematrix.Free_IM();
|
||||
//block_triangular.Free_IM_X(block_triangular.First_IM_X);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -36,9 +36,9 @@ public:
|
|||
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)
|
||||
//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;
|
||||
|
@ -174,18 +174,18 @@ 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);
|
||||
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) const;
|
||||
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) const;
|
||||
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
|
||||
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) const;
|
||||
void writeDynamicFile(const string &basename, bool block, bool bytecode) const;
|
||||
//! Writes file containing parameters derivatives
|
||||
void writeParamsDerivativesFile(const string &basename) const;
|
||||
//! Converts to static model (only the equations)
|
||||
|
|
242
DynareBison.yy
242
DynareBison.yy
|
@ -87,11 +87,11 @@ class ParsingDriver;
|
|||
%}
|
||||
|
||||
%token AR AUTOCORR
|
||||
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK_MFS BLOCK_MFS_DLL
|
||||
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK
|
||||
%token BVAR_DENSITY BVAR_FORECAST
|
||||
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
|
||||
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
|
||||
%token BVAR_REPLIC
|
||||
%token BVAR_REPLIC BYTECODE
|
||||
%token CALIB CALIB_VAR CHANGE_TYPE CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF
|
||||
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE
|
||||
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
|
||||
|
@ -119,7 +119,7 @@ class ParsingDriver;
|
|||
%token QZ_CRITERIUM
|
||||
%token RELATIVE_IRF REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE
|
||||
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO
|
||||
%token SPARSE SPARSE_DLL STDERR STEADY STOCH_SIMUL
|
||||
%token STDERR STEADY STOCH_SIMUL
|
||||
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT
|
||||
%token <string_val> TEX_NAME
|
||||
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL SHOCK_DECOMPOSITION LABELS
|
||||
|
@ -143,8 +143,8 @@ class ParsingDriver;
|
|||
%token FREQ INITIAL_YEAR INITIAL_SUBPERIOD FINAL_YEAR FINAL_SUBPERIOD DATA VLIST VARLIST VLISTLOG VLISTPER
|
||||
%token RESTRICTION_FNAME NLAGS CROSS_RESTRICTIONS CONTEMP_REDUCED_FORM REAL_PSEUDO_FORECAST BAYESIAN_PRIOR
|
||||
%token DUMMY_OBS NSTATES INDXSCALESSTATES ALPHA BETA GSIG2_LMD GSIG2_LMDM Q_DIAG FLAT_PRIOR NCSK NSTD NINV
|
||||
%token INDXPARR INDXOVR ABAND INDXAP APBAND INDXIMF IMFBAND INDXFORE FOREBAND INDXGFOREHAT INDXGIMFHAT
|
||||
%token INDXESTIMA INDXGDLS EQ_MS CMS NCMS EQ_CMS TLINDX TLNUMBER CNUM BANACT
|
||||
%token INDXPARR INDXOVR ABAND INDXAP APBAND INDXIMF IMFBAND INDXFORE FOREBAND INDXGFOREHAT INDXGIMFHAT
|
||||
%token INDXESTIMA INDXGDLS EQ_MS CMS NCMS EQ_CMS TLINDX TLNUMBER CNUM BANACT
|
||||
%token SBVAR MS_SBVAR
|
||||
|
||||
%type <node_val> expression expression_or_empty
|
||||
|
@ -155,7 +155,7 @@ class ParsingDriver;
|
|||
%type <string_val> vec_value_1 vec_value
|
||||
%type <string_val> calib_arg2 range number
|
||||
%type <symbol_type_val> change_type_arg
|
||||
%type <vector_string_val> change_type_var_list
|
||||
%type <vector_string_val> change_type_var_list
|
||||
|
||||
%%
|
||||
|
||||
|
@ -443,14 +443,24 @@ histval_list : histval_list histval_elem
|
|||
|
||||
histval_elem : symbol '(' signed_integer ')' EQUAL expression ';' { driver.hist_val($1, $3, $6); };
|
||||
|
||||
model_sparse_options_list : model_sparse_options_list COMMA model_sparse_options
|
||||
| model_sparse_options
|
||||
/*model_block_options_list : model_block_options_list COMMA model_block_options
|
||||
| model_block_options
|
||||
;
|
||||
|
||||
model_sparse_options : o_cutoff
|
||||
| o_markowitz
|
||||
| o_mfs
|
||||
model_block_options : o_cutoff
|
||||
| o_mfs
|
||||
;
|
||||
*/
|
||||
|
||||
model_options : BLOCK {driver.block(); }
|
||||
| o_cutoff
|
||||
| o_mfs
|
||||
| BYTECODE {driver.byte_code();}
|
||||
;
|
||||
|
||||
model_options_list : model_options_list COMMA model_options
|
||||
| model_options
|
||||
;
|
||||
|
||||
model : MODEL ';' { driver.begin_model(); }
|
||||
equation_list END { driver.reset_data_tree(); }
|
||||
|
@ -458,15 +468,7 @@ model : MODEL ';' { 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 '(' SPARSE_DLL COMMA model_sparse_options_list ')'
|
||||
{ driver.begin_model(); driver.sparse_dll(); } ';'
|
||||
equation_list END { driver.reset_data_tree(); }
|
||||
| MODEL '(' SPARSE_DLL ')' { driver.begin_model(); driver.sparse_dll(); } ';'
|
||||
equation_list END { driver.reset_data_tree(); }
|
||||
| MODEL '(' SPARSE COMMA model_sparse_options_list ')'
|
||||
{ driver.begin_model(); driver.sparse(); } ';'
|
||||
equation_list END { driver.reset_data_tree(); }
|
||||
| MODEL '(' SPARSE ')' { driver.begin_model(); driver.sparse(); } ';'
|
||||
| MODEL '(' model_options_list ')' ';' { driver.begin_model(); }
|
||||
equation_list END { driver.reset_data_tree(); }
|
||||
;
|
||||
|
||||
|
@ -641,11 +643,7 @@ steady_options_list : steady_options_list COMMA steady_options
|
|||
steady_options : o_solve_algo
|
||||
| o_homotopy_mode
|
||||
| o_homotopy_steps
|
||||
| o_block_mfs
|
||||
| o_block_mfs_dll
|
||||
| o_cutoff
|
||||
| o_markowitz
|
||||
| o_mfs
|
||||
;
|
||||
|
||||
check : CHECK ';'
|
||||
|
@ -677,6 +675,7 @@ simul_options_list : simul_options_list COMMA simul_options
|
|||
simul_options : o_periods
|
||||
| o_datafile
|
||||
| o_method
|
||||
| o_markowitz
|
||||
;
|
||||
|
||||
stoch_simul : STOCH_SIMUL ';'
|
||||
|
@ -733,7 +732,7 @@ symbol_list_ext : symbol_list
|
|||
driver.add_in_symbol_list(colon);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
list_of_symbol_lists : symbol_list ';' symbol
|
||||
{
|
||||
string *semicolon = new string(";");
|
||||
|
@ -1259,53 +1258,53 @@ bvar_forecast : BVAR_FORECAST INT_NUMBER ';'
|
|||
;
|
||||
|
||||
sbvar_option : o_datafile
|
||||
| o_freq
|
||||
| o_initial_year
|
||||
| o_initial_subperiod
|
||||
| o_final_year
|
||||
| o_final_subperiod
|
||||
| o_data
|
||||
| o_vlist
|
||||
| o_vlistlog
|
||||
| o_vlistper
|
||||
| o_varlist
|
||||
| o_restriction_fname
|
||||
| o_nlags
|
||||
| o_cross_restrictions
|
||||
| o_contemp_reduced_form
|
||||
| o_real_pseudo_forecast
|
||||
| o_bayesian_prior
|
||||
| o_dummy_obs
|
||||
| o_nstates
|
||||
| o_indxscalesstates
|
||||
| o_alpha
|
||||
| o_beta
|
||||
| o_gsig2_lmd
|
||||
| o_gsig2_lmdm
|
||||
| o_q_diag
|
||||
| o_flat_prior
|
||||
| o_ncsk
|
||||
| o_nstd
|
||||
| o_ninv
|
||||
| o_indxparr
|
||||
| o_indxovr
|
||||
| o_aband
|
||||
| o_indxap
|
||||
| o_apband
|
||||
| o_indximf
|
||||
| o_indxfore
|
||||
| o_foreband
|
||||
| o_indxgforhat
|
||||
| o_indxgimfhat
|
||||
| o_indxestima
|
||||
| o_indxgdls
|
||||
| o_eq_ms
|
||||
| o_cms
|
||||
| o_ncms
|
||||
| o_eq_cms
|
||||
| o_tlindx
|
||||
| o_tlnumber
|
||||
| o_cnum
|
||||
| o_freq
|
||||
| o_initial_year
|
||||
| o_initial_subperiod
|
||||
| o_final_year
|
||||
| o_final_subperiod
|
||||
| o_data
|
||||
| o_vlist
|
||||
| o_vlistlog
|
||||
| o_vlistper
|
||||
| o_varlist
|
||||
| o_restriction_fname
|
||||
| o_nlags
|
||||
| o_cross_restrictions
|
||||
| o_contemp_reduced_form
|
||||
| o_real_pseudo_forecast
|
||||
| o_bayesian_prior
|
||||
| o_dummy_obs
|
||||
| o_nstates
|
||||
| o_indxscalesstates
|
||||
| o_alpha
|
||||
| o_beta
|
||||
| o_gsig2_lmd
|
||||
| o_gsig2_lmdm
|
||||
| o_q_diag
|
||||
| o_flat_prior
|
||||
| o_ncsk
|
||||
| o_nstd
|
||||
| o_ninv
|
||||
| o_indxparr
|
||||
| o_indxovr
|
||||
| o_aband
|
||||
| o_indxap
|
||||
| o_apband
|
||||
| o_indximf
|
||||
| o_indxfore
|
||||
| o_foreband
|
||||
| o_indxgforhat
|
||||
| o_indxgimfhat
|
||||
| o_indxestima
|
||||
| o_indxgdls
|
||||
| o_eq_ms
|
||||
| o_cms
|
||||
| o_ncms
|
||||
| o_eq_cms
|
||||
| o_tlindx
|
||||
| o_tlnumber
|
||||
| o_cnum
|
||||
;
|
||||
|
||||
sbvar_options_list : sbvar_option COMMA sbvar_options_list
|
||||
|
@ -1319,53 +1318,53 @@ sbvar : SBVAR ';'
|
|||
;
|
||||
|
||||
ms_sbvar_option : o_datafile
|
||||
| o_freq
|
||||
| o_initial_year
|
||||
| o_initial_subperiod
|
||||
| o_final_year
|
||||
| o_final_subperiod
|
||||
| o_data
|
||||
| o_vlist
|
||||
| o_vlistlog
|
||||
| o_vlistper
|
||||
| o_varlist
|
||||
| o_restriction_fname
|
||||
| o_nlags
|
||||
| o_cross_restrictions
|
||||
| o_contemp_reduced_form
|
||||
| o_real_pseudo_forecast
|
||||
| o_bayesian_prior
|
||||
| o_dummy_obs
|
||||
| o_nstates
|
||||
| o_indxscalesstates
|
||||
| o_alpha
|
||||
| o_beta
|
||||
| o_gsig2_lmd
|
||||
| o_gsig2_lmdm
|
||||
| o_q_diag
|
||||
| o_flat_prior
|
||||
| o_ncsk
|
||||
| o_nstd
|
||||
| o_ninv
|
||||
| o_indxparr
|
||||
| o_indxovr
|
||||
| o_aband
|
||||
| o_indxap
|
||||
| o_apband
|
||||
| o_indximf
|
||||
| o_indxfore
|
||||
| o_foreband
|
||||
| o_indxgforhat
|
||||
| o_indxgimfhat
|
||||
| o_indxestima
|
||||
| o_indxgdls
|
||||
| o_eq_ms
|
||||
| o_cms
|
||||
| o_ncms
|
||||
| o_eq_cms
|
||||
| o_tlindx
|
||||
| o_tlnumber
|
||||
| o_cnum
|
||||
| o_freq
|
||||
| o_initial_year
|
||||
| o_initial_subperiod
|
||||
| o_final_year
|
||||
| o_final_subperiod
|
||||
| o_data
|
||||
| o_vlist
|
||||
| o_vlistlog
|
||||
| o_vlistper
|
||||
| o_varlist
|
||||
| o_restriction_fname
|
||||
| o_nlags
|
||||
| o_cross_restrictions
|
||||
| o_contemp_reduced_form
|
||||
| o_real_pseudo_forecast
|
||||
| o_bayesian_prior
|
||||
| o_dummy_obs
|
||||
| o_nstates
|
||||
| o_indxscalesstates
|
||||
| o_alpha
|
||||
| o_beta
|
||||
| o_gsig2_lmd
|
||||
| o_gsig2_lmdm
|
||||
| o_q_diag
|
||||
| o_flat_prior
|
||||
| o_ncsk
|
||||
| o_nstd
|
||||
| o_ninv
|
||||
| o_indxparr
|
||||
| o_indxovr
|
||||
| o_aband
|
||||
| o_indxap
|
||||
| o_apband
|
||||
| o_indximf
|
||||
| o_indxfore
|
||||
| o_foreband
|
||||
| o_indxgforhat
|
||||
| o_indxgimfhat
|
||||
| o_indxestima
|
||||
| o_indxgdls
|
||||
| o_eq_ms
|
||||
| o_cms
|
||||
| o_ncms
|
||||
| o_eq_cms
|
||||
| o_tlindx
|
||||
| o_tlnumber
|
||||
| o_cnum
|
||||
;
|
||||
|
||||
ms_sbvar_options_list : ms_sbvar_option COMMA ms_sbvar_options_list
|
||||
|
@ -1607,8 +1606,7 @@ o_gsa_trans_ident : TRANS_IDENT EQUAL INT_NUMBER { driver.option_num("trans_iden
|
|||
|
||||
o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); };
|
||||
o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); };
|
||||
o_block_mfs : BLOCK_MFS { driver.option_num("block_mfs", "1"); }
|
||||
o_block_mfs_dll : BLOCK_MFS_DLL { driver.option_num("block_mfs_dll", "1"); }
|
||||
|
||||
|
||||
o_parameters : PARAMETERS EQUAL symbol {driver.option_str("parameters",$3);};
|
||||
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
|
||||
|
@ -1624,7 +1622,7 @@ o_vlist : VLIST EQUAL INT_NUMBER {driver.option_num("ms.vlist",$3); };
|
|||
o_vlistlog : VLISTLOG EQUAL INT_NUMBER {driver.option_num("ms.vlistlog",$3); };
|
||||
o_vlistper : VLISTPER EQUAL INT_NUMBER {driver.option_num("ms.vlistper",$3); };
|
||||
o_varlist : VARLIST EQUAL '(' symbol_list ')' {driver.option_symbol_list("ms.varlist"); };
|
||||
o_restriction_fname : RESTRICTION_FNAME EQUAL symbol {driver.option_str("ms.restriction_fname",$3); };
|
||||
o_restriction_fname : RESTRICTION_FNAME EQUAL '(' symbol_list ')' {driver.option_symbol_list("ms.restriction_fname"); };
|
||||
o_nlags : NLAGS EQUAL INT_NUMBER {driver.option_num("ms.nlags",$3); };
|
||||
o_cross_restrictions : CROSS_RESTRICTIONS EQUAL INT_NUMBER {driver.option_num("ms.cross_restrictions",$3); };
|
||||
o_contemp_reduced_form : CONTEMP_REDUCED_FORM EQUAL INT_NUMBER {driver.option_num("ms.contemp_reduced_form",$3); };
|
||||
|
|
|
@ -220,8 +220,6 @@ int sigma_e = 0;
|
|||
<DYNARE_STATEMENT>filename {return token::FILENAME;}
|
||||
<DYNARE_STATEMENT>diffuse_filter {return token::DIFFUSE_FILTER;}
|
||||
<DYNARE_STATEMENT>plot_priors {return token::PLOT_PRIORS;}
|
||||
<DYNARE_STATEMENT>block_mfs {return token::BLOCK_MFS;}
|
||||
<DYNARE_STATEMENT>block_mfs_dll {return token::BLOCK_MFS_DLL;}
|
||||
|
||||
<DYNARE_STATEMENT>freq {return token::FREQ;}
|
||||
<DYNARE_STATEMENT>initial_year {return token::INITIAL_YEAR;}
|
||||
|
@ -349,8 +347,8 @@ int sigma_e = 0;
|
|||
<DYNARE_STATEMENT,DYNARE_BLOCK>gaussian_elimination {return token::GAUSSIAN_ELIMINATION;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>gmres {return token::GMRES;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>bicgstab {return token::BICGSTAB;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>sparse {return token::SPARSE;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>sparse_dll {return token::SPARSE_DLL;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>block {return token::BLOCK;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>bytecode {return token::BYTECODE;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>linear {return token::LINEAR;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>[,] {return token::COMMA;}
|
||||
<DYNARE_STATEMENT,DYNARE_BLOCK>[:] {return Dynare::parser::token_type (yytext[0]);}
|
||||
|
|
44
ModFile.cc
44
ModFile.cc
|
@ -29,6 +29,8 @@ ModFile::ModFile() : expressions_tree(symbol_table, num_constants),
|
|||
dynamic_model(symbol_table, num_constants),
|
||||
linear(false)
|
||||
{
|
||||
block = false;
|
||||
byte_code = false;
|
||||
}
|
||||
|
||||
ModFile::~ModFile()
|
||||
|
@ -144,20 +146,23 @@ ModFile::computingPass(bool no_tmp_terms)
|
|||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
// Compute static model and its derivatives
|
||||
if(mod_file_struct.steady_block_mfs_dll_option)
|
||||
cout << "byte_code=" << byte_code << endl;
|
||||
cout << "block=" << block << endl;
|
||||
if(byte_code)
|
||||
{
|
||||
cout << "go in DLL\n";
|
||||
dynamic_model.toStaticDll(static_dll_model);
|
||||
static_dll_model.computingPass(global_eval_context, no_tmp_terms);
|
||||
static_dll_model.computingPass(global_eval_context, no_tmp_terms, block);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_model.toStatic(static_model);
|
||||
static_model.computingPass(mod_file_struct.steady_block_mfs_option, false, no_tmp_terms);
|
||||
static_model.computingPass(block, false, 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);
|
||||
dynamic_model.computingPass(false, false, false, false, global_eval_context, no_tmp_terms, block);
|
||||
else
|
||||
{
|
||||
if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3)
|
||||
|
@ -168,7 +173,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);
|
||||
dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,11 +240,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
|||
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
dynamic_model.writeOutput(mOutputFile, basename);
|
||||
if(mod_file_struct.steady_block_mfs_dll_option)
|
||||
static_dll_model.writeOutput(mOutputFile, basename);
|
||||
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
|
||||
static_model.writeOutput(mOutputFile);
|
||||
static_model.writeOutput(mOutputFile, block);
|
||||
}
|
||||
|
||||
// Print statements
|
||||
|
@ -248,7 +256,12 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
|||
(*it)->writeOutput(mOutputFile, basename);
|
||||
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
dynamic_model.writeOutputPostComputing(mOutputFile, basename);
|
||||
{
|
||||
if (mod_file_struct.simul_present)
|
||||
dynamic_model.writeOutputPostComputing(mOutputFile, basename, block);
|
||||
else
|
||||
dynamic_model.writeOutputPostComputing(mOutputFile, basename, false);
|
||||
}
|
||||
|
||||
mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl
|
||||
<< "diary off" << endl
|
||||
|
@ -259,11 +272,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
|||
// Create static and dynamic files
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
if(mod_file_struct.steady_block_mfs_dll_option)
|
||||
static_dll_model.writeStaticFile(basename);
|
||||
if(byte_code)
|
||||
static_dll_model.writeStaticFile(basename, block);
|
||||
else
|
||||
static_model.writeStaticFile(basename);
|
||||
dynamic_model.writeDynamicFile(basename);
|
||||
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.writeParamsDerivativesFile(basename);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,14 @@ public:
|
|||
DynamicModel dynamic_model;
|
||||
//! Option linear
|
||||
bool linear;
|
||||
|
||||
//! Is the model block decomposed?
|
||||
bool block;
|
||||
|
||||
//! Is the model stored in baytecode format (byte_code=true) or in a M-file (byte_code=false)
|
||||
bool byte_code;
|
||||
|
||||
|
||||
//! Global evaluation context
|
||||
/*! Filled using initval blocks and parameters initializations */
|
||||
eval_context_type global_eval_context;
|
||||
|
|
|
@ -183,7 +183,7 @@ ParsingDriver::add_model_variable(string *name, string *olag)
|
|||
if (type == eUnknownFunction)
|
||||
error("Symbol " + *name + " is a function name unknown to Dynare. It cannot be used inside model.");
|
||||
|
||||
if (type == eExogenous && lag != 0 && (dynamic_model->mode != DynamicModel::eSparseDLLMode && dynamic_model->mode != DynamicModel::eSparseMode))
|
||||
if (type == eExogenous && lag != 0 && !mod_file->block)
|
||||
warning("Exogenous variable " + *name + " has lead/lag " + *olag);
|
||||
|
||||
if (type == eModelLocalVariable && lag != 0)
|
||||
|
@ -351,15 +351,15 @@ ParsingDriver::use_dll()
|
|||
}
|
||||
|
||||
void
|
||||
ParsingDriver::sparse_dll()
|
||||
ParsingDriver::block()
|
||||
{
|
||||
dynamic_model->mode = DynamicModel::eSparseDLLMode;
|
||||
mod_file->block = true;
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::sparse()
|
||||
ParsingDriver::byte_code()
|
||||
{
|
||||
dynamic_model->mode = DynamicModel::eSparseMode;
|
||||
mod_file->byte_code = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -617,7 +617,7 @@ ParsingDriver::option_num(const string &name_option, const string &opt)
|
|||
&& (options_list.num_options.find(name_option) != options_list.num_options.end()))
|
||||
error("option " + name_option + " declared twice");
|
||||
|
||||
if ((name_option == "periods") && (mod_file->dynamic_model.mode == DynamicModel::eSparseDLLMode || mod_file->dynamic_model.mode == DynamicModel::eSparseMode))
|
||||
if ((name_option == "periods") && mod_file->block)
|
||||
mod_file->dynamic_model.block_triangular.periods = atoi(opt.c_str());
|
||||
else if (name_option == "cutoff")
|
||||
{
|
||||
|
@ -629,8 +629,6 @@ ParsingDriver::option_num(const string &name_option, const string &opt)
|
|||
mod_file->dynamic_model.mfs = atoi(opt.c_str());
|
||||
mod_file->static_dll_model.mfs = atoi(opt.c_str());
|
||||
}
|
||||
else if (name_option == "block_mfs_dll")
|
||||
mod_file->static_dll_model.mode = (StaticDllModel::mode_t)DynamicModel::eSparseDLLMode;
|
||||
|
||||
options_list.num_options[name_option] = opt;
|
||||
}
|
||||
|
@ -695,7 +693,7 @@ void ParsingDriver::stoch_simul()
|
|||
void
|
||||
ParsingDriver::simul()
|
||||
{
|
||||
mod_file->addStatement(new SimulStatement(options_list, mod_file->dynamic_model.mode));
|
||||
mod_file->addStatement(new SimulStatement(options_list, mod_file->dynamic_model.mode, mod_file->block, mod_file->byte_code));
|
||||
options_list.clear();
|
||||
}
|
||||
|
||||
|
@ -1095,14 +1093,14 @@ ParsingDriver::ms_sbvar()
|
|||
options_list.clear();
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
ParsingDriver::shock_decomposition()
|
||||
{
|
||||
mod_file->addStatement(new ShockDecompositionStatement(symbol_list, options_list));
|
||||
symbol_list.clear();
|
||||
options_list.clear();
|
||||
}
|
||||
|
||||
|
||||
NodeID
|
||||
ParsingDriver::add_model_equal(NodeID arg1, NodeID arg2)
|
||||
{
|
||||
|
|
|
@ -175,10 +175,10 @@ public:
|
|||
bool symbol_exists_and_is_not_modfile_local_or_unknown_function(const char *s);
|
||||
//! Sets mode of ModelTree class to use C output
|
||||
void use_dll();
|
||||
//! Sets mode of ModelTree class to block decompose the model and triggers the creation of the incidence matrix in a C context
|
||||
void sparse_dll();
|
||||
//! Sets mode of ModelTree class to block decompose the model and triggers the creation of the incidence matrix in Matlab context
|
||||
void sparse();
|
||||
//! the modelis block decomposed
|
||||
void block();
|
||||
//! the model is stored in a binary file
|
||||
void byte_code();
|
||||
//! Sets the FILENAME for the initial value in initval
|
||||
void initval_file(string *filename);
|
||||
//! Declares an endogenous variable
|
||||
|
|
|
@ -824,8 +824,10 @@ StaticDllModel::writeSparseStaticMFile(const string &static_basename, const stri
|
|||
|
||||
|
||||
void
|
||||
StaticDllModel::writeOutput(ostream &output, const string &basename) const
|
||||
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
|
||||
|
@ -837,14 +839,14 @@ StaticDllModel::writeOutput(ostream &output, const string &basename) const
|
|||
// Special setup for DLL or Sparse modes
|
||||
if (mode == eDLLMode)
|
||||
output << "mex -O LDFLAGS='-pthread -shared -Wl,--no-undefined' " << basename << "_static.c" << endl;
|
||||
if (mode == eSparseMode || mode == eSparseDLLMode)
|
||||
if (block)
|
||||
output << "addpath " << basename << ";" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
StaticDllModel::writeOutputPostComputing(ostream &output, const string &basename) const
|
||||
StaticDllModel::writeOutputPostComputing(ostream &output, const string &basename, bool block) const
|
||||
{
|
||||
if (mode == eSparseMode || mode == eSparseDLLMode)
|
||||
if (block)
|
||||
output << "rmpath " << basename << ";" << endl;
|
||||
}
|
||||
|
||||
|
@ -1004,7 +1006,7 @@ StaticDllModel::collect_first_order_derivatives_endogenous()
|
|||
|
||||
|
||||
void
|
||||
StaticDllModel::computingPass(const eval_context_type &eval_context, bool no_tmp_terms)
|
||||
StaticDllModel::computingPass(const eval_context_type &eval_context, bool no_tmp_terms, bool block)
|
||||
{
|
||||
|
||||
// Computes static jacobian columns
|
||||
|
@ -1025,7 +1027,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 (mode == eSparseDLLMode || mode == eSparseMode)
|
||||
if (block)
|
||||
{
|
||||
BuildIncidenceMatrix();
|
||||
|
||||
|
@ -1067,10 +1069,29 @@ StaticDllModel::computingPass(const eval_context_type &eval_context, bool no_tmp
|
|||
}
|
||||
|
||||
void
|
||||
StaticDllModel::writeStaticFile(const string &basename) const
|
||||
StaticDllModel::writeStaticFile(const string &basename, bool block) const
|
||||
{
|
||||
int r;
|
||||
switch (mode)
|
||||
if(block)
|
||||
{
|
||||
#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();
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
/*switch (mode)
|
||||
{
|
||||
case eStandardMode:
|
||||
break;
|
||||
|
@ -1109,7 +1130,7 @@ StaticDllModel::writeStaticFile(const string &basename) const
|
|||
block_triangular.incidencematrix.Free_IM();
|
||||
//block_triangular.Free_IM_X(block_triangular.First_IM_X);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ public:
|
|||
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)
|
||||
//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;
|
||||
|
@ -167,18 +167,18 @@ public:
|
|||
\param eval_context evaluation context for normalization
|
||||
\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);
|
||||
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) const;
|
||||
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) const;
|
||||
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
|
||||
void Write_Inf_To_Bin_File(const string &static_basename, const string &bin_basename,
|
||||
const int &num, int &u_count_int, bool &file_open) const;
|
||||
//! Writes static model file
|
||||
void writeStaticFile(const string &basename) const;
|
||||
void writeStaticFile(const string &basename, bool block) const;
|
||||
//! Writes file containing parameters derivatives
|
||||
void writeParamsDerivativesFile(const string &basename) const;
|
||||
|
||||
|
|
|
@ -45,8 +45,7 @@ using namespace boost;
|
|||
|
||||
StaticModel::StaticModel(SymbolTable &symbol_table_arg,
|
||||
NumericalConstants &num_constants_arg) :
|
||||
ModelTree(symbol_table_arg, num_constants_arg),
|
||||
block_mfs(false)
|
||||
ModelTree(symbol_table_arg, num_constants_arg)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -158,7 +157,7 @@ StaticModel::writeStaticMFile(ostream &output, const string &func_name) const
|
|||
}
|
||||
|
||||
void
|
||||
StaticModel::writeStaticFile(const string &basename) const
|
||||
StaticModel::writeStaticFile(const string &basename, bool block) const
|
||||
{
|
||||
string filename = basename + "_static.m";
|
||||
|
||||
|
@ -170,7 +169,7 @@ StaticModel::writeStaticFile(const string &basename) const
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (block_mfs)
|
||||
if (block)
|
||||
writeStaticBlockMFSFile(output, basename + "_static");
|
||||
else
|
||||
writeStaticMFile(output, basename + "_static");
|
||||
|
@ -179,9 +178,9 @@ StaticModel::writeStaticFile(const string &basename) const
|
|||
}
|
||||
|
||||
void
|
||||
StaticModel::computingPass(bool block_mfs_arg, bool hessian, bool no_tmp_terms)
|
||||
StaticModel::computingPass(bool block, bool hessian, bool no_tmp_terms)
|
||||
{
|
||||
block_mfs = block_mfs_arg;
|
||||
|
||||
|
||||
// Compute derivatives w.r. to all endogenous
|
||||
set<int> vars;
|
||||
|
@ -199,7 +198,7 @@ StaticModel::computingPass(bool block_mfs_arg, bool hessian, bool no_tmp_terms)
|
|||
computeHessian(vars);
|
||||
}
|
||||
|
||||
if (block_mfs)
|
||||
if (block)
|
||||
{
|
||||
computeNormalization();
|
||||
computeSortedBlockDecomposition();
|
||||
|
@ -555,9 +554,9 @@ StaticModel::computeBlockMFSJacobian()
|
|||
}
|
||||
|
||||
void
|
||||
StaticModel::writeOutput(ostream &output) const
|
||||
StaticModel::writeOutput(ostream &output, bool block) const
|
||||
{
|
||||
if (!block_mfs)
|
||||
if (!block)
|
||||
return;
|
||||
|
||||
output << "M_.blocksMFS = cell(" << blocksMFS.size() << ", 1);" << endl;
|
||||
|
@ -574,7 +573,6 @@ StaticModel::writeLocalVars(ostream &output, NodeID expr, set<int> &local_var_wr
|
|||
{
|
||||
set<int> expr_local_var;
|
||||
expr->collectModelLocalVariables(expr_local_var);
|
||||
|
||||
vector<int> new_local_var;
|
||||
set_difference(expr_local_var.begin(), expr_local_var.end(),
|
||||
local_var_written.begin(), local_var_written.end(),
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
class StaticModel : public ModelTree
|
||||
{
|
||||
private:
|
||||
//! Are we in block decomposition + min. feedback set mode ?
|
||||
bool block_mfs;
|
||||
|
||||
//! Normalization of equations
|
||||
/*! Maps endogenous type specific IDs to equation numbers */
|
||||
vector<int> endo2eq;
|
||||
|
@ -95,13 +92,13 @@ public:
|
|||
\param block_mfs 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_mfs_arg, bool hessian, bool no_tmp_terms);
|
||||
void computingPass(bool block, bool hessian, bool no_tmp_terms);
|
||||
|
||||
//! Writes information on block decomposition when relevant
|
||||
void writeOutput(ostream &output) const;
|
||||
void writeOutput(ostream &output, bool block) const;
|
||||
|
||||
//! Writes static model file
|
||||
void writeStaticFile(const string &basename) const;
|
||||
void writeStaticFile(const string &basename, bool block) const;
|
||||
|
||||
//! Writes LaTeX file with the equations of the static model
|
||||
void writeLatexFile(const string &basename) const;
|
||||
|
|
Loading…
Reference in New Issue