new matrix allocation mechanism

This commit is contained in:
Florian Stecker
2019-02-08 13:35:02 +01:00
parent 3d8378aa16
commit 870ae7d2d2
6 changed files with 152 additions and 154 deletions

View File

@@ -13,6 +13,9 @@
#define ERROR(condition, msg, ...) if(condition){fprintf(stderr, msg, ##__VA_ARGS__); exit(1);}
#define FCMP(x, y) gsl_fcmp(x, y, 1e-10)
#define MAX_TEMP_MATRICES 60000
#define MAX_TEMP_VECTORS 100
typedef struct _workspace {
int n;
gsl_eigen_nonsymmv_workspace *work_nonsymmv;
@@ -22,9 +25,12 @@ typedef struct _workspace {
gsl_matrix_complex *evec_complex;
gsl_vector *eval_real;
gsl_matrix *evec_real;
gsl_matrix *tmp;
gsl_permutation *permutation;
gsl_matrix *stack[20];
gsl_matrix **tmp_mat;
int tmp_mat_used;
gsl_vector **tmp_vec;
int tmp_vec_used;
} workspace_t;
workspace_t *workspace_alloc(int n);
@@ -46,4 +52,45 @@ int real_eigenvectors(gsl_matrix *g, gsl_matrix *evec, workspace_t *ws);
void eigenvectors_symm(gsl_matrix *g, gsl_vector *eval, gsl_matrix *evec, workspace_t *ws);
int diagonalize_symmetric_form(gsl_matrix *A, gsl_matrix *cob, workspace_t *ws);
// matrix allocation stuff
static gsl_matrix **getTempMatrices(workspace_t *ws, int n)
{
ERROR(ws->tmp_mat_used + n > MAX_TEMP_MATRICES, "Ran out of temporary matrices. Consider increasing MAX_TEMP_MATRICES\n");
int index = ws->tmp_mat_used;
ws->tmp_mat_used += n;
return ws->tmp_mat + index;
}
static gsl_matrix *getTempMatrix(workspace_t *ws)
{
return *getTempMatrices(ws, 1);
}
static void releaseTempMatrices(workspace_t *ws, int n)
{
ERROR(ws->tmp_mat_used - n < 0, "Released more matrices then in use\n");
ws->tmp_mat_used -= n;
}
static gsl_vector **getTempVectors(workspace_t *ws, int n)
{
ERROR(ws->tmp_vec_used + n > MAX_TEMP_VECTORS, "Ran out of temporary vectors. Consider increasing MAX_TEMP_VECTORS\n");
int index = ws->tmp_vec_used;
ws->tmp_vec_used += n;
return ws->tmp_vec + index;
}
static gsl_vector *getTempVector(workspace_t *ws)
{
return *getTempVectors(ws, 1);
}
static void releaseTempVectors(workspace_t *ws, int n)
{
ERROR(ws->tmp_vec_used - n < 0, "Released more vectors then in use\n");
ws->tmp_vec_used -= n;
}
#endif