Bug correction in error messages and reduction of memory requirement during simulation

time-shift
Ferhat Mihoubi 2010-02-12 14:38:07 +01:00
parent e466748993
commit faa5da07dc
3 changed files with 25 additions and 30 deletions

View File

@ -112,26 +112,32 @@ Interpreter::get_variable(SymbolType variable_type, int variable_num)
C = mxGetN(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "endo_names"))); C = mxGetN(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "endo_names")));
R = mxGetM(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "endo_names"))); R = mxGetM(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "endo_names")));
P = (char*) mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "endo_names"))); P = (char*) mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "endo_names")));
if (EQN_dvar1 < R) if (variable_num < R)
for (unsigned int i = 0; i < C; i++) for (unsigned int i = 0; i < C; i++)
res << P[2*(EQN_dvar1+i*R)]; res << P[2*(variable_num+i*R)];
else
mexPrintf("=> Unknown endogenous variable n° %d",EQN_dvar1);
break; break;
case eExogenous: case eExogenous:
case eExogenousDet: case eExogenousDet:
C = mxGetN(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_names"))); C = mxGetN(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_names")));
R = mxGetM(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_names"))); R = mxGetM(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_names")));
P = (char*) mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_names"))); P = (char*) mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "exo_names")));
if (EQN_dvar1 < R) if (variable_num < R)
for (unsigned int i = 0; i < C; i++) for (unsigned int i = 0; i < C; i++)
res << P[2*(EQN_dvar1+i*R)]; res << P[2*(variable_num+i*R)];
else
mexPrintf("=> Unknown exogenous variable n° %d",EQN_dvar1);
break; break;
case eParameter: case eParameter:
C = mxGetN(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "param_names"))); C = mxGetN(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "param_names")));
R = mxGetM(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "param_names"))); R = mxGetM(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "param_names")));
P = (char*) mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "param_names"))); P = (char*) mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "param_names")));
if (EQN_dvar1 < R) if (variable_num < R)
for (unsigned int i = 0; i < C; i++) for (unsigned int i = 0; i < C; i++)
res << P[2*(EQN_dvar1+i*R)]; res << P[2*(variable_num+i*R)];
else
mexPrintf("=> Unknown parameter n° %d",EQN_dvar1);
break; break;
default: default:
break; break;

View File

@ -1832,7 +1832,7 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (nop+1 >= nopa) if (nop+1 >= nopa)
{ {
nopa = int (1.5*nopa); nopa = long (mem_increasing_factor*(double)nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int)); save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
} }
save_op_s = (t_save_op_s *)(&(save_op[nop])); save_op_s = (t_save_op_s *)(&(save_op[nop]));
@ -1872,7 +1872,7 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (nop+j*2+1 >= nopa) if (nop+j*2+1 >= nopa)
{ {
nopa = int (1.5*nopa); nopa = long (mem_increasing_factor*(double)nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int)); save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
} }
save_op_s = (t_save_op_s *)(&(save_op[nop+j*2])); save_op_s = (t_save_op_s *)(&(save_op[nop+j*2]));
@ -1891,7 +1891,7 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (nop+1 >= nopa) if (nop+1 >= nopa)
{ {
nopa = int (1.5*nopa); nopa = long (mem_increasing_factor*(double)nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int)); save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
} }
save_op_s = (t_save_op_s *)(&(save_op[nop])); save_op_s = (t_save_op_s *)(&(save_op[nop]));
@ -1926,13 +1926,10 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (record) if (record)
{ {
if (nop+2 >= nopa) if (nop+1 >= nopa)
{ {
//#pragma omp critical nopa = long (mem_increasing_factor*(double)nopa);
{ save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
nopa = int (1.5*nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
}
} }
save_op_s_l = (t_save_op_s *)(&(save_op[nop])); save_op_s_l = (t_save_op_s *)(&(save_op[nop]));
save_op_s_l->operat = IFLD; save_op_s_l->operat = IFLD;
@ -1979,11 +1976,8 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (nop+2 >= nopa) if (nop+2 >= nopa)
{ {
//#pragma omp critical nopa = long (mem_increasing_factor*(double)nopa);
{ save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
nopa = int (1.5*nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
}
} }
save_op_s_l = (t_save_op_s *)(&(save_op[nop])); save_op_s_l = (t_save_op_s *)(&(save_op[nop]));
save_op_s_l->operat = IFLESS; save_op_s_l->operat = IFLESS;
@ -2037,11 +2031,8 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (nop+3 >= nopa) if (nop+3 >= nopa)
{ {
//#pragma omp critical nopa = long (mem_increasing_factor*(double)nopa);
{ save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
nopa = int (1.5*nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
}
} }
save_op_s_l = (t_save_op_s *)(&(save_op[nop])); save_op_s_l = (t_save_op_s *)(&(save_op[nop]));
save_op_s_l->operat = IFSUB; save_op_s_l->operat = IFSUB;
@ -2074,11 +2065,8 @@ SparseMatrix::simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax
{ {
if (nop+3 >= nopa) if (nop+3 >= nopa)
{ {
//#pragma omp critical nopa = long (mem_increasing_factor*(double)nopa);
{ save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
nopa = int (1.5*nopa);
save_op = (int *) mxRealloc(save_op, nopa*sizeof(int));
}
} }
save_op_s_l = (t_save_op_s *)(&(save_op[nop])); save_op_s_l = (t_save_op_s *)(&(save_op[nop]));
save_op_s_l->operat = IFSUB; save_op_s_l->operat = IFSUB;

View File

@ -94,6 +94,7 @@ const int IFADD = 7;
const double eps = 1e-10; const double eps = 1e-10;
const double very_big = 1e24; const double very_big = 1e24;
const int alt_symbolic_count_max = 1; const int alt_symbolic_count_max = 1;
const double mem_increasing_factor = 1.1;
class SparseMatrix class SparseMatrix
{ {