Commit 6479edf5 authored by ferhat's avatar ferhat
Browse files

- Correction of several bugs

- normalize an equation linear in its endogenous variable
- Chained rule derivatives (necessary to reduce a block to the feedback equations and variables)

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2726 ac1d8469-bf42-47a9-8791-bf33cf982152
parent d67f1ecd
......@@ -90,15 +90,16 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
g1=spalloc( Blck_size, Blck_size, nze);
while ~(cvg==1 | iter>maxit_),
if(is_dynamic)
[r, g1, g2, g3] = feval(fname, y, x, params, it_, 0);
[r, y, g1, g2, g3] = feval(fname, y, x, params, it_, 0);
else
[r, g1, g2, g3] = feval(fname, y, x, params, 0);
[r, y, g1, g2, g3] = feval(fname, y, x, params, 0);
end;
if(~isreal(r))
max_res=(-(max(max(abs(r))))^2)^0.5;
else
max_res=max(max(abs(r)));
end;
%['max_res=' num2str(max_res) ' Block_Num=' int2str(Block_Num) ' it_=' int2str(it_)]
if(verbose==1)
disp(['iteration : ' int2str(iter) ' => ' num2str(max_res) ' time = ' int2str(it_)]);
if(is_dynamic)
......@@ -315,7 +316,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
function [err, G]=local_fname(yl, x, params, y, y_index_eq, fname, is_csolve)
y(y_index_eq) = yl;
[err, G] = feval(fname, y, x, params, 0);
[err, y, G] = feval(fname, y, x, params, 0);
if(is_csolve)
G = full(G);
end;
......@@ -58,7 +58,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global oo_;
global oo_ M_;
cvg=0;
iter=0;
Per_u_=0;
......@@ -72,17 +72,18 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
g1=spalloc( Blck_size*periods, Jacobian_Size, nze*periods);
reduced = 0;
while ~(cvg==1 | iter>maxit_),
[r, g1, g2, g3, b]=feval(fname, y, x, params, periods, 0, y_kmin, Blck_size);
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, periods, 0, y_kmin, Blck_size);
g1a=g1(:, y_kmin*Blck_size+1:(periods+y_kmin)*Blck_size);
%disp(['size(g1)=' int2str(size(g1))]);
%disp(['g1(:,' int2str(1:y_kmin_l*Blck_size) ')']);
%disp(['g1(:,' int2str((periods+y_kmin_l)*Blck_size+1:(periods+y_kmin_l+y_kmax_l)*Blck_size) ')']);
b = b' -g1(:, 1:y_kmin_l*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)'-g1(:, (periods+y_kmin_l)*Blck_size+1:(periods+y_kmin_l+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
b = b -g1(:, 1:y_kmin_l*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)'-g1(:, (periods+y_kmin_l)*Blck_size+1:(periods+y_kmin_l+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
[max_res, max_indx]=max(max(abs(r')));
if(~isreal(r))
max_res=(-(max(max(abs(r))))^2)^0.5;
else
max_res=max(max(abs(r)));
max_res = (-max_res^2)^0.5;
end;
% if(~isreal(r))
% max_res=(-(max(max(abs(r))))^2)^0.5;
% else
% max_res=max(max(abs(r)));
% end;
if(~isreal(max_res) | isnan(max_res))
cvg = 0;
elseif(is_linear & iter>0)
......@@ -93,6 +94,9 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
if(~cvg)
if(iter>0)
if(~isreal(max_res) | isnan(max_res) | (max_resa<max_res && iter>1))
if(~isreal(max_res))
disp(['Variable ' M_.endo_names(max_indx,:) ' (' int2str(max_indx) ') returns an undefined value']);
end;
if(isnan(max_res))
detJ=det(g1aa);
if(abs(detJ)<1e-7)
......
......@@ -16,9 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
//#define DEBUGC
#include <cstring>
#include "Interpreter.hh"
Interpreter::Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *direction_arg, int y_size_arg,
......@@ -77,16 +76,22 @@ Interpreter::compute_block_time(int Per_u_) /*throw(EvalException)*/
case FLDV :
//load a variable in the processor
#ifdef DEBUGC
mexPrintf("FLDV");
mexEvalString("drawnow;");
if(Block_Count==2)
{
mexPrintf("FLDV\n");
mexEvalString("drawnow;");
}
#endif
switch (get_code_char)
{
case eParameter :
var=get_code_int
#ifdef DEBUGC
mexPrintf(" params[%d]=%f\n",var,params[var]);
mexEvalString("drawnow;");
if(Block_Count==2)
{
mexPrintf(" params[%d]=%f\n",var,params[var]);
mexEvalString("drawnow;");
}
#endif
Stack.push(params[var]);
break;
......@@ -94,27 +99,32 @@ Interpreter::compute_block_time(int Per_u_) /*throw(EvalException)*/
var=get_code_int
lag=get_code_int
#ifdef DEBUGC
if(var==153)
if(Block_Count==2)
{
mexPrintf(" FLD y[var=%d,time=%d,lag=%d,%d]=%f\n",var,it_,lag,(it_+lag)*y_size+var,y[(it_+lag)*y_size+var]);
mexEvalString("drawnow;");
mexPrintf("y[%d, %d]=%f\n",it_+lag, var+1, y[(it_+lag)*y_size+var]);
}
#endif
Stack.push(y[(it_+lag)*y_size+var]);
break;
case eExogenous :
#ifdef DEBUGC
mexPrintf("Exogenous\n");
#endif
var=get_code_int
lag=get_code_int
#ifdef DEBUGC
if(var==650 or var==643 or var==628)
if(Block_Count==2)
{
mexPrintf(" FLD x[%d, time=%d, var=%d, lag=%d]=%f\n",it_+lag+var*nb_row_x,it_,var,lag,x[it_+lag+var*nb_row_x]);
mexEvalString("drawnow;");
mexPrintf("x[%d, %d]\n",it_+lag, var+1);
}
#endif
Stack.push(x[it_+lag+var*nb_row_x]);
break;
case eExogenousDet :
#ifdef DEBUGC
mexPrintf("ExogenousDet\n");
#endif
var=get_code_int
lag=get_code_int
#ifdef DEBUGC
......@@ -123,6 +133,8 @@ Interpreter::compute_block_time(int Per_u_) /*throw(EvalException)*/
#endif
Stack.push(x[it_+lag+var*nb_row_xd]);
break;
default:
mexPrintf("Unknown vraibale type\n");
}
break;
case FLDT :
......@@ -183,39 +195,53 @@ Interpreter::compute_block_time(int Per_u_) /*throw(EvalException)*/
case eParameter :
var=get_code_int
params[var] = Stack.top();
#ifdef DEBUGC
mexPrintf("FSTP params[%d]=%f\n", var, params[var]);
mexEvalString("drawnow;");
#endif
Stack.pop();
break;
case eEndogenous :
#ifdef DEBUGC
mexPrintf("FSTP Endogenous\n");
#endif
var=get_code_int
lag=get_code_int
#ifdef DEBUGC
mexPrintf("y[%d(it_=%d, lag=%d, y_size=%d, var=%d)](%d)=",(it_+lag)*y_size+var,it_, lag, y_size, var, Stack.size());
//mexPrintf("y[%d(it_=%d, lag=%d, y_size=%d, var=%d)](%d)=",(it_+lag)*y_size+var,it_, lag, y_size, var, Stack.size());
mexPrintf("y[it_=%d, lag=%d, y_size=%d, var=%d, block=%d)]=",it_, lag, y_size, var+1, Block_Count+1);
mexEvalString("drawnow;");
#endif
y[(it_+lag)*y_size+var] = Stack.top();
#ifdef DEBUGC
if(var==557 || var==558)
{
mexPrintf(" FSTP y[var=%d,time=%d,lag=%d,%d]=%f\n",var,it_,lag,(it_+lag)*y_size+var,y[(it_+lag)*y_size+var]);
mexEvalString("drawnow;");
}
/*mexPrintf("%f\n",y[(it_+lag)*y_size+var]);
mexEvalString("drawnow;");*/
mexPrintf("%f\n",y[(it_+lag)*y_size+var]);
mexEvalString("drawnow;");
#endif
Stack.pop();
break;
case eExogenous :
#ifdef DEBUGC
mexPrintf("Exogenous\n");
#endif
var=get_code_int
var=get_code_int
lag=get_code_int
x[it_+lag+var*nb_row_x] = Stack.top();
Stack.pop();
break;
case eExogenousDet :
#ifdef DEBUGC
mexPrintf("ExogenousDet\n");
#endif
var=get_code_int
var=get_code_int
lag=get_code_int
x[it_+lag+var*nb_row_xd] = Stack.top();
Stack.pop();
break;
default:
mexPrintf("Unknown vraibale type\n");
}
break;
case FSTPT :
......@@ -584,7 +610,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
Mat_DP a;
Vec_INT indx;
#endif
//SparseMatrix sparse_matrix;
//SparseMatrix sparse_matrix;
//int nb_endo, u_count_init;
......@@ -599,19 +625,22 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
switch (type)
{
case EVALUATE_FORWARD :
case EVALUATE_FORWARD_R :
//case EVALUATE_FORWARD_R :
#ifdef DEBUGC
mexPrintf("EVALUATE_FORWARD\n");
#endif
begining=get_code_pointer;
for (it_=y_kmin;it_<periods+y_kmin;it_++)
{
//mexPrintf("begining=%x\n",begining);
set_code_pointer(begining);
Per_y_=it_*y_size;
//mexPrintf("bef compute_block_time()\n");
compute_block_time(0);
#ifdef PRINT_OUT
for (j = 0; j<size; j++)
mexPrintf("y[%d, %d] = %f\n", Block_Contain[j].Variable, it_, y[Per_y_ + Block_Contain[j].Variable]);
for (int j = 34; j</*size*/37; j++)
mexPrintf("y[%d, %d] = %f\n",j+1, it_, y[j+it_*y_size]);
//mexPrintf("y[%d, %d] = %f\n", Block_Contain[j].Variable, it_, y[Per_y_ + Block_Contain[j].Variable]);
#endif
}
/*mexPrintf("Evaluate Forward\n");
......@@ -624,12 +653,12 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
}*/
break;
case EVALUATE_BACKWARD :
case EVALUATE_BACKWARD_R :
//case EVALUATE_BACKWARD_R :
#ifdef DEBUGC
mexPrintf("EVALUATE_BACKWARD\n");
#endif
begining=get_code_pointer;
for (it_=periods+y_kmin;it_>y_kmin;it_--)
for (it_=periods+y_kmin-1;it_>=y_kmin;it_--)
{
set_code_pointer(begining);
Per_y_=it_*y_size;
......@@ -824,6 +853,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
if (!is_linear)
{
max_res_idx=0;
for (it_=y_kmin;it_<periods+y_kmin;it_++)
{
cvg=false;
......@@ -845,7 +875,10 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
double rr;
rr=r[i]/(1+y[Per_y_+Block_Contain[i].Variable]);
if (max_res<fabs(rr))
max_res=fabs(rr);
{
max_res=fabs(rr);
max_res_idx=i;
}
res2+=rr*rr;
res1+=fabs(rr);
}
......@@ -867,7 +900,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
set_code_pointer(begining);
Per_y_=it_*y_size;
iter = 0;
res1=res2=max_res=0;
res1=res2=max_res=0;max_res_idx=0;
/*mexPrintf("Compute_block_time=> in SOLVE_FORWARD_COMPLETE before compute_block_time OK\n");
mexEvalString("drawnow;");*/
compute_block_time(0);
......@@ -916,6 +949,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
begining=get_code_pointer;
if (!is_linear)
{
max_res_idx=0;
for (it_=periods+y_kmin;it_>y_kmin;it_--)
{
cvg=false;
......@@ -937,7 +971,10 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
double rr;
rr=r[i]/(1+y[Per_y_+Block_Contain[i].Variable]);
if (max_res<fabs(rr))
max_res=fabs(rr);
{
max_res=fabs(rr);
max_res_idx=i;
}
res2+=rr*rr;
res1+=fabs(rr);
}
......@@ -1056,6 +1093,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
res2=0;
res1=0;
max_res=0;
max_res_idx=0;
memcpy(y_save, y, y_size*sizeof(double)*(periods+y_kmax+y_kmin));
for (it_=y_kmin;it_<periods+y_kmin;it_++)
{
......@@ -1063,14 +1101,15 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
//mexPrintf("Per_u_=%d\n",Per_u_);
Per_y_=it_*y_size;
//mexPrintf("ok\n");
//mexPrintf("compute_block_time\n");
/*mexPrintf("compute_block_time it_=%d periods=%d y_kmin=%d\n",it_, periods, y_kmin);
mexEvalString("drawnow;");*/
set_code_pointer(begining);
compute_block_time(Per_u_);
//mexPrintf("end of compute_block_time\n");
/*mexPrintf("end of compute_block_time it_=%d\n",it_);*/
/*if(Gaussian_Elimination)
initialize(periods, nb_endo, y_kmin, y_kmax, y_size, u_count, u_count_init, u, y, ya, slowc, y_decal, markowitz_c, res1, res2, max_res);*/
//mexPrintf("ok1\n");
//mexEvalString("drawnow;");
/*mexEvalString("drawnow;");*/
if (isnan(res1)||isinf(res1))
{
memcpy(y, y_save, y_size*sizeof(double)*(periods+y_kmax+y_kmin));
......@@ -1089,7 +1128,10 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
/*else
rr=r[i];*/
if (max_res<fabs(rr))
max_res=fabs(rr);
{
max_res=fabs(rr);
max_res_idx=i;
}
res2+=rr*rr;
res1+=fabs(rr);
/*if (GaussSeidel && giter)
......@@ -1150,7 +1192,7 @@ Interpreter::simulate_a_block(int size,int type, string file_name, string bin_ba
mexPrintf(" %f",y[i]);
mexPrintf("\n");*/
}
res1=res2=max_res=0;
res1=res2=max_res=0;max_res_idx=0;
cvg = false;
if(Gaussian_Elimination)
simulate_NG1(Block_Count, symbol_table_endo_nbr, it_, y_kmin, y_kmax, size, periods, true, cvg, iter);
......@@ -1248,7 +1290,7 @@ Interpreter::compute_blocks(string file_name, string bin_basename)
#endif
lBlock.begin=get_code_pos-(long int)(Init_Code);
#ifdef DEBUGC
mexPrintf("Block[Block_Count].begin=%d\n",lBlock.begin);
mexPrintf("Block[%d].begin=%d\n",Block_Count, lBlock.begin);
mexEvalString("drawnow;");
#endif
lBlock.size=get_code_int
......@@ -1278,8 +1320,10 @@ Interpreter::compute_blocks(string file_name, string bin_basename)
//mexPrintf("Block_Contain[%d].Own_Derivative=%d\n",i,lBlock_Contain.Own_Derivative);
Block_Contain.push_back(lBlock_Contain);
}
/*mexPrintf("Block Completed\n");
mexEvalString("drawnow;");*/
#ifdef DEBUGC
mexPrintf("Block Completed\n");
mexEvalString("drawnow;");
#endif
simulate_a_block(lBlock.size,lBlock.type, file_name, bin_basename,true);
//simulate_a_block(lBlock.size,lBlock.type, file_name, bin_basename,false);
break;
......
......@@ -453,7 +453,7 @@ void SparseMatrix::Simple_Init(int it_, int y_kmin, int y_kmax, int Size, std::m
it4=IM.begin();
eq=-1;
double tmp_b[Size];
#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
///#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
for(i=0; i< Size;i++)
{
tmp_b[i]=0;//u[i];
......@@ -509,7 +509,7 @@ void SparseMatrix::Simple_Init(int it_, int y_kmin, int y_kmax, int Size, std::m
}
it4++;
}
#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
///#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
for(i=0;i<Size;i++)
{
b[i]=u_count1+i;
......@@ -600,13 +600,13 @@ void SparseMatrix::Init(int periods, int y_kmin, int y_kmax, int Size, std::map<
//i=periods*Size*sizeof(*b);
//memset(b,0,i);
#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
///#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
for(i=0; i< periods*Size;i++)
{
b[i]=0;
line_done[i]=0;
}
#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
///#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
for(i=0; i< (periods+y_kmax+1)*Size;i++)
{
FNZE_C[i]=0;
......@@ -621,7 +621,7 @@ void SparseMatrix::Init(int periods, int y_kmin, int y_kmax, int Size, std::map<
mexPrintf("Now looping\n");
mexEvalString("drawnow;");
#endif
#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS"))) ordered private(it4, ti_y_kmin, ti_y_kmax, eq, var, lag) schedule(dynamic)
///#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS"))) ordered private(it4, ti_y_kmin, ti_y_kmax, eq, var, lag) schedule(dynamic)
for (t=0;t<periods;t++)
{
#ifdef PRINT_OUT
......@@ -631,7 +631,7 @@ void SparseMatrix::Init(int periods, int y_kmin, int y_kmax, int Size, std::map<
ti_y_kmax= min( periods-(t+1), y_kmax);
it4=IM.begin();
eq=-1;
#pragma omp ordered
///#pragma omp ordered
while (it4!=IM.end())
{
var=it4->first.first.second;
......@@ -948,18 +948,17 @@ SparseMatrix::compare( int *save_op, int *save_opa, int *save_opaa, int beg_t, i
#endif
// the same pivot for all remaining periods
if (OK)
#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS"))) ordered private(j) schedule(dynamic)
///#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS"))) ordered private(j) schedule(dynamic)
for (i=beg_t;i<periods;i++)
{
for (j=0;j<Size;j++)
{
#pragma omp ordered
///#pragma omp ordered
pivot[i*Size+j]=pivot[(i-1)*Size+j]+Size;
}
}
if (OK)
{
#ifdef WRITE_u
long int i_toto=0;
fstream toto;
......@@ -972,9 +971,6 @@ SparseMatrix::compare( int *save_op, int *save_opa, int *save_opaa, int beg_t, i
mexPrintf("u=(double*)mxRealloc(u,u_count_alloc*sizeof(double))=%d, t=%d, omp_get_thread_num()=%d\n",u_count_alloc,t,omp_get_thread_num());
#endif
u=(double*)mxRealloc(u,u_count_alloc*sizeof(double));
#ifdef MEM_ALLOC_CHK
mexPrintf("ok\n");
#endif
if (!u)
{
mexPrintf("Error in Get_u: memory exhausted (realloc(%d))\n",u_count_alloc*sizeof(double));
......@@ -1028,30 +1024,27 @@ SparseMatrix::compare( int *save_op, int *save_opa, int *save_opaa, int beg_t, i
break;
}
j++;
}
}
int t1=periods-beg_t-max(y_kmax,y_kmin);
//mexPrintf("=>t=%d\n",t);
/*if (index_d+(periods-beg_t-t1)*s_nop4>=u_count_alloc)
{
u_count_alloc+=5*u_count_alloc_save;
//#ifdef MEM_ALLOC_CHK
mexPrintf("u=(double*)mxRealloc(u,u_count_alloc*sizeof(double))=%d, t=%d, omp_get_thread_num()=%d\n",u_count_alloc,t,omp_get_thread_num());
//#endif
u=(double*)mxRealloc(u,u_count_alloc*sizeof(double));
if (index_d+3>=u_count_alloc)
{
u_count_alloc+=2*u_count_alloc_save;
#ifdef MEM_ALLOC_CHK
mexPrintf("ok\n");
mexPrintf("u=(double*)mxRealloc(u,u_count_alloc*sizeof(double))=%d, t=%d, omp_get_thread_num()=%d\n",u_count_alloc,t,omp_get_thread_num());
#endif
if (!u)
{
mexPrintf("Error in Get_u: memory exhausted (realloc(%d))\n",u_count_alloc*sizeof(double));
mexEvalString("st=fclose('all');clear all;");
mexErrMsgTxt("Exit from Dynare");
u=(double*)mxRealloc(u,u_count_alloc*sizeof(double));
#ifdef MEM_ALLOC_CHK
mexPrintf("ok\n");
#endif
if (!u)
{
mexPrintf("Error in Get_u: memory exhausted (realloc(%d))\n",u_count_alloc*sizeof(double));
mexEvalString("st=fclose('all');clear all;");
mexErrMsgTxt("Exit from Dynare");
}
}
}
}*/
//mexPrintf("beg_t=%d, starting at t1=%d\n",beg_t,t1);
}
int t1=periods-beg_t-max(y_kmax,y_kmin);
//#pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS"))) ordered private(t, i,j, save_op_s, index_d, r) schedule(dynamic)
for (t=t1;t<periods-beg_t;t++)
{
//mexPrintf("omp_in_parallel=%hd, omp_get_thread_num=%d, t=%d\n",omp_in_parallel(), omp_get_thread_num(), t);
......@@ -1094,6 +1087,23 @@ SparseMatrix::compare( int *save_op, int *save_opa, int *save_opaa, int beg_t, i
i+=3;
break;
}
if (index_d+3>=u_count_alloc)
{
u_count_alloc+=2*u_count_alloc_save;
#ifdef MEM_ALLOC_CHK
mexPrintf("u=(double*)mxRealloc(u,u_count_alloc*sizeof(double))=%d, t=%d, omp_get_thread_num()=%d\n",u_count_alloc,t,omp_get_thread_num());
#endif
u=(double*)mxRealloc(u,u_count_alloc*sizeof(double));
#ifdef MEM_ALLOC_CHK
mexPrintf("ok\n");
#endif
if (!u)
{
mexPrintf("Error in Get_u: memory exhausted (realloc(%d))\n",u_count_alloc*sizeof(double));
mexEvalString("st=fclose('all');clear all;");
mexErrMsgTxt("Exit from Dynare");
}
}
}
else
{
......@@ -2131,7 +2141,8 @@ SparseMatrix::simulate_NG(int blck, int y_size, int it_, int y_kmin, int y_kmax,
{
if (slowc_save<1e-8)
{
mexPrintf("Dynare cannot improve the simulation\n");
mexPrintf("slowc_save=%g\n", slowc_save);
mexPrintf("Dynare cannot improve the simulation in block %d at time %d\n", blck, it_);
mexEvalString("drawnow;");
mexEvalString("st=fclose('all');clear all;");
filename+=" stopped";
......@@ -2415,9 +2426,12 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{
if (slowc_save<1e-8)
{
mexPrintf("Dynare cannot improve the simulation\n");
mexPrintf("slowc_save=%g\n", slowc_save);
for(j=0;j<y_size; j++)
mexPrintf("variable %d at time %d = %f\n",j+1, it_, y[j+it_*y_size]);
mexPrintf("Dynare cannot improve the simulation in block %d at time %d (variable %d)\n", blck+1, it_+1, max_res_idx);
mexEvalString("drawnow;");
mexEvalString("st=fclose('all');clear all;");
//mexEvalString("st=fclose('all');clear all;");
filename+=" stopped";
mexErrMsgTxt(filename.c_str());
}
......@@ -2791,10 +2805,6 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
mexErrMsgTxt(filename.c_str());
}
/*divide all the non zeros elements of the line pivj by the max_pivot*/
#ifdef PRINT_OUT
mexPrintf("ok2\n");
mexEvalString("drawnow;");
#endif
int nb_var=At_Row(pivj,&first);
NonZeroElem* bb[nb_var];
for(j=0;j<nb_var;j++)
......@@ -2883,10 +2893,6 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
i_toto++;
}
#endif
#ifdef PRINT_OUT
mexPrintf("ok3\n");
mexEvalString("drawnow;");
#endif
#ifdef PRINT_u
mexPrintf("FDIV u[%d](%f)/=piv(%f)=(%f) |",b[pivj],u[b[pivj]],piv,u[b[pivj]]);
Print_u();mexPrintf("\n");
......@@ -3110,11 +3116,6 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
#endif
firsta=first;
first_suba=first_sub->NZE_R_N;
/*if(iter>0)
{
mexPrintf("just after\n");
mexEvalString("drawnow;");
}*/
#ifdef PROFILER
clock_t td0=clock();
#endif
......@@ -3240,11 +3241,6 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
mexPrintf("FSUB u[%d]-=u[%d](%f)*r(%f)=(%f) |",b[row],b[pivj],u[b[pivj]],first_elem,u[b[row]]);
Print_u();mexPrintf("\n");
#endif
/*if(iter>0)
{
mexPrintf("ok4f j=%d\n",j);
mexEvalString("drawnow;");
}*/
if (symbolic)
{
......@@ -3325,6 +3321,7 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
))
{