Commit cc2a9d90 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Global reindentation of MEX source files

parent f4557cb1
This diff is collapsed.
This diff is collapsed.
......@@ -47,8 +47,8 @@ class Interpreter : public SparseMatrix
private:
unsigned int EQN_dvar1, EQN_dvar2, EQN_dvar3;
int EQN_lag1, EQN_lag2, EQN_lag3;
mxArray* GlobalTemporaryTerms;
protected:
mxArray *GlobalTemporaryTerms;
protected:
double pow1(double a, double b);
double divide(double a, double b);
double log1(double a);
......@@ -57,10 +57,10 @@ private:
void evaluate_a_block(const int size, const int type, string bin_basename, bool steady_state, int block_num,
const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0, int block = -1);
int simulate_a_block(const int size, const int type, string file_name, string bin_basename, bool Gaussian_Elimination, bool steady_state, int block_num,
const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0);
const bool is_linear = false, const int symbol_table_endo_nbr = 0, const int Block_List_Max_Lag = 0, const int Block_List_Max_Lead = 0, const int u_count_int = 0);
void print_a_block(const int size, const int type, string bin_basename, bool steady_state, int block_num,
const bool is_linear, const int symbol_table_endo_nbr, const int Block_List_Max_Lag,
const int Block_List_Max_Lead, const int u_count_int, int block);
const bool is_linear, const int symbol_table_endo_nbr, const int Block_List_Max_Lag,
const int Block_List_Max_Lead, const int u_count_int, int block);
vector<Block_contain_type> Block_Contain;
code_liste_type code_liste;
it_code_type it_code;
......@@ -81,14 +81,38 @@ public:
double *direction_arg, int y_size_arg, int nb_row_x_arg,
int nb_row_xd_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, int maxit_arg_, double solve_tolf_arg, int size_o_direction_arg,
double slowc_arg, int y_decal_arg, double markowitz_c_arg, string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg,
bool global_temporary_terms_arg, bool print_arg, mxArray* GlobalTemporaryTerms_arg);
bool global_temporary_terms_arg, bool print_arg, mxArray *GlobalTemporaryTerms_arg);
bool compute_blocks(string file_name, string bin_basename, bool steady_state, bool evaluate, int block, int &nb_blocks);
inline mxArray* get_jacob(int block_num) {return jacobian_block[block_num];};
inline mxArray* get_jacob_exo(int block_num) {return jacobian_exo_block[block_num];};
inline mxArray* get_jacob_exo_det(int block_num) {return jacobian_det_exo_block[block_num];};
inline mxArray* get_jacob_other_endo(int block_num) {return jacobian_other_endo_block[block_num];};
inline vector<double> get_residual() {return residual;};
inline mxArray* get_Temporary_Terms() {return GlobalTemporaryTerms;};
inline mxArray *
get_jacob(int block_num)
{
return jacobian_block[block_num];
};
inline mxArray *
get_jacob_exo(int block_num)
{
return jacobian_exo_block[block_num];
};
inline mxArray *
get_jacob_exo_det(int block_num)
{
return jacobian_det_exo_block[block_num];
};
inline mxArray *
get_jacob_other_endo(int block_num)
{
return jacobian_other_endo_block[block_num];
};
inline vector<double>
get_residual()
{
return residual;
};
inline mxArray *
get_Temporary_Terms()
{
return GlobalTemporaryTerms;
};
};
#endif
......@@ -85,9 +85,9 @@ Mem_Mngr::mxMalloc_NZE()
mexEvalString("drawnow;");
}
if (NZE_Mem_add)
NZE_Mem_add = (NonZeroElem **) mxRealloc(NZE_Mem_add, CHUNK_SIZE*sizeof(NonZeroElem *)); /*We have to redefine the size of pointer on the memory*/
NZE_Mem_add = (NonZeroElem **) mxRealloc(NZE_Mem_add, CHUNK_SIZE*sizeof(NonZeroElem *)); /*We have to redefine the size of pointer on the memory*/
else
NZE_Mem_add = (NonZeroElem **) mxMalloc(CHUNK_SIZE*sizeof(NonZeroElem *)); /*We have to define the size of pointer on the memory*/
NZE_Mem_add = (NonZeroElem **) mxMalloc(CHUNK_SIZE*sizeof(NonZeroElem *)); /*We have to define the size of pointer on the memory*/
if (!NZE_Mem_add)
{
mexPrintf("Not enough memory available\n");
......@@ -95,7 +95,7 @@ Mem_Mngr::mxMalloc_NZE()
}
for (i = CHUNK_heap_pos; i < CHUNK_SIZE; i++)
{
NZE_Mem_add[i] = (NonZeroElem *)(NZE_Mem+(i-CHUNK_heap_pos));
NZE_Mem_add[i] = (NonZeroElem *) (NZE_Mem+(i-CHUNK_heap_pos));
}
i = CHUNK_heap_pos++;
return (NZE_Mem_add[i]);
......@@ -109,7 +109,7 @@ Mem_Mngr::mxFree_NZE(void *pos)
size_t gap;
for (i = 0; i < Nb_CHUNK; i++)
{
gap = ((size_t)(pos)-(size_t)(NZE_Mem_add[i*CHUNK_BLCK_SIZE]))/sizeof(NonZeroElem);
gap = ((size_t) (pos)-(size_t) (NZE_Mem_add[i*CHUNK_BLCK_SIZE]))/sizeof(NonZeroElem);
if ((gap < CHUNK_BLCK_SIZE) && (gap >= 0))
break;
}
......
This diff is collapsed.
......@@ -27,12 +27,11 @@
#include <ctime>
#ifdef OCTAVE_MEX_FILE
#define CHAR_LENGTH 1
# define CHAR_LENGTH 1
#else
#define CHAR_LENGTH 2
# define CHAR_LENGTH 2
#endif
#include "Mem_Mngr.hh"
#include "ErrorHandling.hh"
#define NEW_ALLOC
......@@ -73,16 +72,16 @@ public:
private:
void Init_GE(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM);
void Init_Matlab_Sparse(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM, mxArray *A_m, mxArray *b_m, mxArray* x0_m);
void Init_Matlab_Sparse_Simple(int Size, map<pair<pair<int, int>, int>, int> &IM, mxArray *A_m, mxArray *b_m, bool &zero_solution, mxArray* x0_m);
void Init_Matlab_Sparse(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM, mxArray *A_m, mxArray *b_m, mxArray *x0_m);
void Init_Matlab_Sparse_Simple(int Size, map<pair<pair<int, int>, int>, int> &IM, mxArray *A_m, mxArray *b_m, bool &zero_solution, mxArray *x0_m);
void Simple_Init(int it_, int y_kmin, int y_kmax, int Size, std::map<std::pair<std::pair<int, int>, int>, int> &IM, bool &zero_solution);
void End_GE(int Size);
void Solve_ByteCode_Symbolic_Sparse_GaussianElimination(int Size, bool symbolic, int Block_number);
void Solve_ByteCode_Sparse_GaussianElimination(int Size, int blck, bool steady_state, int it_);
void Solve_Matlab_Relaxation(mxArray* A_m, mxArray* b_m, unsigned int Size, double slowc_l, bool is_two_boundaries, int it_);
void Solve_Matlab_LU_UMFPack(mxArray* A_m, mxArray* b_m, int Size, double slowc_l, bool is_two_boundaries, int it_);
void Solve_Matlab_GMRES(mxArray* A_m, mxArray* b_m, int Size, double slowc, int block, bool is_two_boundaries, int it_, bool steady_state, mxArray* x0_m);
void Solve_Matlab_BiCGStab(mxArray* A_m, mxArray* b_m, int Size, double slowc, int block, bool is_two_boundaries, int it_, mxArray* x0_m, bool steady_state);
void Solve_Matlab_Relaxation(mxArray *A_m, mxArray *b_m, unsigned int Size, double slowc_l, bool is_two_boundaries, int it_);
void Solve_Matlab_LU_UMFPack(mxArray *A_m, mxArray *b_m, int Size, double slowc_l, bool is_two_boundaries, int it_);
void Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, int Size, double slowc, int block, bool is_two_boundaries, int it_, bool steady_state, mxArray *x0_m);
void Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, int Size, double slowc, int block, bool is_two_boundaries, int it_, mxArray *x0_m, bool steady_state);
bool compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, int periods, long int nop4, int Size
#ifdef PROFILER
, long int *ndiv, long int *nsub
......@@ -111,14 +110,13 @@ private:
#endif
);
double simple_bksub(int it_, int Size, double slowc_l);
mxArray* Sparse_transpose(mxArray* A_m);
mxArray* Sparse_mult_SAT_SB(mxArray* A_m, mxArray* B_m);
mxArray* Sparse_mult_SAT_B(mxArray* A_m, mxArray* B_m);
mxArray* mult_SAT_B(mxArray* A_m, mxArray* B_m);
mxArray* Sparse_substract_SA_SB(mxArray* A_m, mxArray* B_m);
mxArray* Sparse_substract_A_SB(mxArray* A_m, mxArray* B_m);
mxArray* substract_A_B(mxArray* A_m, mxArray* B_m);
mxArray *Sparse_transpose(mxArray *A_m);
mxArray *Sparse_mult_SAT_SB(mxArray *A_m, mxArray *B_m);
mxArray *Sparse_mult_SAT_B(mxArray *A_m, mxArray *B_m);
mxArray *mult_SAT_B(mxArray *A_m, mxArray *B_m);
mxArray *Sparse_substract_SA_SB(mxArray *A_m, mxArray *B_m);
mxArray *Sparse_substract_A_SB(mxArray *A_m, mxArray *B_m);
mxArray *substract_A_B(mxArray *A_m, mxArray *B_m);
stack<double> Stack;
int nb_prologue_table_u, nb_first_table_u, nb_middle_table_u, nb_last_table_u;
......@@ -153,7 +151,7 @@ private:
protected:
vector<double> residual;
int u_count_alloc, u_count_alloc_save;
vector<double*> jac;
vector<double *> jac;
double *jcb;
double res1, res2, max_res;
int max_res_idx;
......
......@@ -19,7 +19,6 @@
#include <cstring>
#include "Interpreter.hh"
#ifdef DEBUG_EX
using namespace std;
......@@ -32,7 +31,6 @@ Get_Argument(const char *argv)
return f;
}
#else
string
......@@ -68,80 +66,80 @@ Get_Arguments_and_global_variables(int nrhs,
bool &steady_state, bool &evaluate, int &block,
mxArray *M_[], mxArray *oo_[], mxArray *options_[], bool &global_temporary_terms,
bool &print,
mxArray* GlobalTemporaryTerms[])
mxArray *GlobalTemporaryTerms[])
{
#ifdef DEBUG_EX
for (int i = 2; i < nrhs; i++)
#else
for (int i = 0; i < nrhs; i++)
for (int i = 0; i < nrhs; i++)
#endif
{
{
#ifndef DEBUG_EX
if (!mxIsChar(prhs[i]))
{
switch (count_array_argument)
{
case 0:
*yd = mxGetPr(prhs[i]);
row_y = mxGetM(prhs[i]);
col_y = mxGetN(prhs[i]);
break;
case 1:
*xd = mxGetPr(prhs[i]);
row_x = mxGetM(prhs[i]);
col_x = mxGetN(prhs[i]);
break;
case 2:
*params = mxGetPr(prhs[i]);
break;
case 3:
periods = mxGetScalar(prhs[i]);
break;
case 4:
*block_structur = mxDuplicateArray(prhs[i]);
break;
case 5:
global_temporary_terms = true;
*GlobalTemporaryTerms = mxDuplicateArray(prhs[i]);
break;
default:
//mexPrintf("Unknown argument count_array_argument=%d\n",count_array_argument);
break;
}
count_array_argument++;
}
else
if (!mxIsChar(prhs[i]))
{
switch (count_array_argument)
{
case 0:
*yd = mxGetPr(prhs[i]);
row_y = mxGetM(prhs[i]);
col_y = mxGetN(prhs[i]);
break;
case 1:
*xd = mxGetPr(prhs[i]);
row_x = mxGetM(prhs[i]);
col_x = mxGetN(prhs[i]);
break;
case 2:
*params = mxGetPr(prhs[i]);
break;
case 3:
periods = mxGetScalar(prhs[i]);
break;
case 4:
*block_structur = mxDuplicateArray(prhs[i]);
break;
case 5:
global_temporary_terms = true;
*GlobalTemporaryTerms = mxDuplicateArray(prhs[i]);
break;
default:
//mexPrintf("Unknown argument count_array_argument=%d\n",count_array_argument);
break;
}
count_array_argument++;
}
else
#endif
if (Get_Argument(prhs[i]) == "static")
steady_state = true;
else if (Get_Argument(prhs[i]) == "dynamic")
steady_state = false;
else if (Get_Argument(prhs[i]) == "evaluate")
evaluate = true;
else if (Get_Argument(prhs[i]) == "global_temporary_terms")
global_temporary_terms = true;
else if (Get_Argument(prhs[i]) == "print")
print = true;
else
{
int pos = Get_Argument(prhs[i]).find("block");
if (pos != (int)string::npos)
{
int pos1 = Get_Argument(prhs[i]).find("=", pos+5);
if (pos1 != (int)string::npos)
pos = pos1 + 1;
else
pos += 5;
block = atoi(Get_Argument(prhs[i]).substr(pos, string::npos).c_str())-1;
}
if (Get_Argument(prhs[i]) == "static")
steady_state = true;
else if (Get_Argument(prhs[i]) == "dynamic")
steady_state = false;
else if (Get_Argument(prhs[i]) == "evaluate")
evaluate = true;
else if (Get_Argument(prhs[i]) == "global_temporary_terms")
global_temporary_terms = true;
else if (Get_Argument(prhs[i]) == "print")
print = true;
else
{
ostringstream tmp;
tmp << " in main, unknown argument : " << Get_Argument(prhs[i]) << "\n";
throw FatalExceptionHandling(tmp.str());
int pos = Get_Argument(prhs[i]).find("block");
if (pos != (int) string::npos)
{
int pos1 = Get_Argument(prhs[i]).find("=", pos+5);
if (pos1 != (int) string::npos)
pos = pos1 + 1;
else
pos += 5;
block = atoi(Get_Argument(prhs[i]).substr(pos, string::npos).c_str())-1;
}
else
{
ostringstream tmp;
tmp << " in main, unknown argument : " << Get_Argument(prhs[i]) << "\n";
throw FatalExceptionHandling(tmp.str());
}
}
}
}
}
if (count_array_argument > 0 && count_array_argument < 4)
{
if (count_array_argument == 3 && steady_state)
......@@ -182,18 +180,18 @@ int
main(int nrhs, const char *prhs[])
#else
/* The gateway routine */
void
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
#endif
{
mxArray *M_, *oo_, *options_;
mxArray* GlobalTemporaryTerms;
mxArray *GlobalTemporaryTerms;
#ifndef DEBUG_EX
mxArray *block_structur = NULL;
#else
int nlhs = 0;
char *plhs[1];
load_global((char*)prhs[1]);
load_global((char *) prhs[1]);
#endif
//ErrorHandlingException error_handling;
unsigned int i, row_y = 0, col_y = 0, row_x = 0, col_x = 0, nb_row_xd = 0;
......@@ -213,22 +211,21 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
try
{
Get_Arguments_and_global_variables(nrhs, prhs, count_array_argument,
&yd, row_y, col_y,
&xd, row_x, col_x,
&params, periods,
&yd, row_y, col_y,
&xd, row_x, col_x,
&params, periods,
#ifndef DEBUG_EX
&block_structur,
&block_structur,
#endif
steady_state, evaluate, block,
&M_, &oo_, &options_, global_temporary_terms,
print, &GlobalTemporaryTerms);
steady_state, evaluate, block,
&M_, &oo_, &options_, global_temporary_terms,
print, &GlobalTemporaryTerms);
}
catch (GeneralExceptionHandling &feh)
{
DYN_MEX_FUNC_ERR_MSG_TXT(feh.GetErrorMsg().c_str());
}
if (!count_array_argument)
params = mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_, "params")));
......@@ -282,10 +279,10 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int solve_algo;
double solve_tolf;
if (steady_state)
{
solve_algo = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "solve_algo")))));
solve_tolf = *(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "solve_tolf"))));
}
{
solve_algo = int (*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "solve_algo")))));
solve_tolf = *(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_, "solve_tolf"))));
}
else
{
......@@ -383,7 +380,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
else
for (i = 0; i < row_y*col_y; i++)
pind[i] = y[i];
pind[i] = y[i];
}
if (nlhs > 2)
{
......@@ -392,11 +389,11 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int jacob_field_number = 0, jacob_exo_field_number = 0, jacob_exo_det_field_number = 0, jacob_other_endo_field_number = 0;
if (!block_structur)
{
const char *field_names[] = {"g1","g1_x","g1_xd","g1_o"};
jacob_field_number=0;
jacob_exo_field_number=1;
jacob_exo_det_field_number=2;
jacob_other_endo_field_number=2;
const char *field_names[] = {"g1", "g1_x", "g1_xd", "g1_o"};
jacob_field_number = 0;
jacob_exo_field_number = 1;
jacob_exo_det_field_number = 2;
jacob_other_endo_field_number = 2;
mwSize dims[1] = {nb_blocks };
plhs[2] = mxCreateStructArray(1, dims, 4, field_names);
}
......@@ -425,15 +422,15 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (!dont_store_a_structure)
{
for (int i = 0; i < nb_blocks; i++)
{
mxSetFieldByNumber(plhs[2],i,jacob_field_number,interprete.get_jacob(i));
mxSetFieldByNumber(plhs[2],i,jacob_exo_field_number,interprete.get_jacob_exo(i));
mxSetFieldByNumber(plhs[2],i,jacob_exo_det_field_number,interprete.get_jacob_exo_det(i));
mxSetFieldByNumber(plhs[2],i,jacob_other_endo_field_number,interprete.get_jacob_other_endo(i));
{
mxSetFieldByNumber(plhs[2], i, jacob_field_number, interprete.get_jacob(i));
mxSetFieldByNumber(plhs[2], i, jacob_exo_field_number, interprete.get_jacob_exo(i));
mxSetFieldByNumber(plhs[2], i, jacob_exo_det_field_number, interprete.get_jacob_exo_det(i));
mxSetFieldByNumber(plhs[2], i, jacob_other_endo_field_number, interprete.get_jacob_other_endo(i));
}
}
}
else
else
{
plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
pind = mxGetPr(plhs[0]);
......@@ -447,7 +444,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
pind[i] = y[i];
if (nlhs > 4)
{
mxArray* GlobalTemporaryTerms = interprete.get_Temporary_Terms();
mxArray *GlobalTemporaryTerms = interprete.get_Temporary_Terms();
unsigned int nb_temp_terms = mxGetM(GlobalTemporaryTerms);
plhs[4] = mxCreateDoubleMatrix(nb_temp_terms, 1, mxREAL);
pind = mxGetPr(plhs[4]);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment