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

44
main.h
View File

@@ -10,8 +10,6 @@
#define LOOP(i) for(int i = 0; i < 3; i++)
#define NUM_GROUP_ELEMENTS 50000
#define MAX_TEMP_MATRICES 60000
#define MAX_TEMP_VECTORS 100
typedef struct {
double x[3];
@@ -49,50 +47,8 @@ typedef struct {
// temporary; matrices can only be freed from the top, but that's enough for us
workspace_t *ws;
gsl_matrix **tmp;
int tmp_used;
gsl_vector **tmp_vec;
int tmp_vec_used;
} DrawingContext;
static gsl_matrix **getTempMatrices(DrawingContext *ctx, int n)
{
ERROR(ctx->tmp_used + n > MAX_TEMP_MATRICES, "Ran out of temporary matrices. Consider increasing MAX_TEMP_MATRICES\n");
int index = ctx->tmp_used;
ctx->tmp_used += n;
return ctx->tmp + index;
}
static gsl_matrix *getTempMatrix(DrawingContext *ctx)
{
return *getTempMatrices(ctx, 1);
}
static void releaseTempMatrices(DrawingContext *ctx, int n)
{
ERROR(ctx->tmp_used - n < 0, "Released more matrices then in use\n");
ctx->tmp_used -= n;
}
static gsl_vector **getTempVectors(DrawingContext *ctx, int n)
{
ERROR(ctx->tmp_vec_used + n > MAX_TEMP_VECTORS, "Ran out of temporary vectors. Consider increasing MAX_TEMP_VECTORS\n");
int index = ctx->tmp_vec_used;
ctx->tmp_vec_used += n;
return ctx->tmp_vec + index;
}
static gsl_vector *getTempVector(DrawingContext *ctx)
{
return *getTempVectors(ctx, 1);
}
static void releaseTempVectors(DrawingContext *ctx, int n)
{
ERROR(ctx->tmp_vec_used - n < 0, "Released more vectors then in use\n");
ctx->tmp_vec_used -= n;
}
// implemented in limit_set.c
void cartanMatrix(gsl_matrix *cartan, double a1, double a2, double a3, double s);
void initializeTriangleGenerators(gsl_matrix **gen, gsl_matrix *cartan);