Skip to content

Commit

Permalink
- Restructured memory pool (it's now an array of pools)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10318 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 7, 2011
1 parent cbbe21e commit 40420cb
Show file tree
Hide file tree
Showing 16 changed files with 929 additions and 419 deletions.
8 changes: 4 additions & 4 deletions Compiler/runtime/Dynload.cpp
Expand Up @@ -165,9 +165,9 @@ static int execute_function(void *in_arg, void **out_arg,
void *v = NULL;
int retval = 0;
int debugFlag = check_debug_flag("dynload");
state mem_state;

mem_state = get_memory_state();
void *states = push_memory_states(1);
state mem_state = get_memory_state();
// fprintf(stderr, "states-ix: %d\n", mem_state);

if (debugFlag) { fprintf(stderr, "input parameters:\n"); fflush(stderr); }

Expand Down Expand Up @@ -216,7 +216,7 @@ static int execute_function(void *in_arg, void **out_arg,
++arg;
}

restore_memory_state(mem_state);
pop_memory_states(states);

if (retval) {
*out_arg = Values__META_5fFAIL;
Expand Down
7 changes: 6 additions & 1 deletion Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -1038,6 +1038,11 @@ template functionODE(list<list<SimEqSystem>> derivativEquations, Text method)
<%funcNames%>
};

void function_initMemoryState()
{
push_memory_states(<% if RTOpts.debugFlag("openmp") then noProc() else 1 %>);
}

int functionODE()
{
int id,th_id;
Expand Down Expand Up @@ -2955,7 +2960,7 @@ case FUNCTION(__) then
MMC_CATCH_TOP(return 1)
<%if outVars then (outVars |> var hasindex i1 fromindex 1 => writeOutVar(var, i1) ;separator="\n") else "write_noretcall(outVar);"%>
fflush(NULL);
return 0;
}
>>
Expand Down
12 changes: 6 additions & 6 deletions c_runtime/base_array.c
Expand Up @@ -51,7 +51,7 @@ void base_array_create(base_array_t *dest, void *data, int ndims, va_list ap)
dest->data = data;
dest->ndims = ndims;

dest->dim_size = size_alloc(ndims);
dest->dim_size = size_alloc(0,ndims);

for (i = 0; i < ndims; ++i) {
dest->dim_size[i] = va_arg(ap, int);
Expand Down Expand Up @@ -218,15 +218,15 @@ size_t base_array_nr_of_elements(base_array_t *a)
void simple_alloc_1d_base_array(base_array_t *dest, int n, void *data)
{
dest->ndims = 1;
dest->dim_size = size_alloc(1);
dest->dim_size = size_alloc(0,1);
dest->dim_size[0] = n;
dest->data = data;
}

void simple_alloc_2d_base_array(base_array_t *dest, int r, int c, void *data)
{
dest->ndims = 2;
dest->dim_size = size_alloc(2);
dest->dim_size = size_alloc(0,2);
dest->dim_size[0] = r;
dest->dim_size[1] = c;
dest->data = data;
Expand All @@ -237,7 +237,7 @@ size_t alloc_base_array(base_array_t *dest, int ndims, va_list ap)
int i;

dest->ndims = ndims;
dest->dim_size = size_alloc(ndims);
dest->dim_size = size_alloc(0,ndims);

for (i = 0; i < ndims; ++i) {
dest->dim_size[i] = va_arg(ap, _index_t);
Expand All @@ -260,7 +260,7 @@ void clone_base_array_spec(base_array_t *source, base_array_t *dest)
assert(base_array_ok(source));

dest->ndims = source->ndims;
dest->dim_size = size_alloc(dest->ndims);
dest->dim_size = size_alloc(0,dest->ndims);
assert(dest->dim_size);

for (i = 0; i < dest->ndims; ++i) {
Expand Down Expand Up @@ -350,7 +350,7 @@ void clone_reverse_base_array_spec(base_array_t* source, base_array_t* dest)
assert(base_array_ok(source));

dest->ndims = source->ndims;
dest->dim_size = size_alloc(dest->ndims);
dest->dim_size = size_alloc(0,dest->ndims);
assert(dest->dim_size);

for (i = 0; i < dest->ndims; ++i) {
Expand Down
46 changes: 19 additions & 27 deletions c_runtime/boolean_array.c
Expand Up @@ -89,12 +89,12 @@ void boolean_array_create(boolean_array_t *dest, modelica_boolean *data,

void simple_alloc_1d_boolean_array(boolean_array_t* dest, int n)
{
simple_alloc_1d_base_array(dest, n, boolean_alloc(n));
simple_alloc_1d_base_array(dest, n, boolean_alloc(0,n));
}

void simple_alloc_2d_boolean_array(boolean_array_t* dest, int r, int c)
{
simple_alloc_2d_base_array(dest, r, c, boolean_alloc(r * c));
simple_alloc_2d_base_array(dest, r, c, boolean_alloc(0,r * c));
}

void alloc_boolean_array(boolean_array_t *dest, int ndims, ...)
Expand All @@ -104,20 +104,12 @@ void alloc_boolean_array(boolean_array_t *dest, int ndims, ...)
va_start(ap, ndims);
elements = alloc_base_array(dest, ndims, ap);
va_end(ap);
dest->data = boolean_alloc(elements);
dest->data = boolean_alloc(0,elements);
}

void alloc_boolean_array_data(boolean_array_t* a)
{
a->data = boolean_alloc(base_array_nr_of_elements(a));
}

void free_boolean_array_data(boolean_array_t* a)
{
size_t array_size;
assert(base_array_ok(a));
array_size = base_array_nr_of_elements(a);
boolean_free(array_size);
a->data = boolean_alloc(0,base_array_nr_of_elements(a));
}

void copy_boolean_array_data(boolean_array_t *source, boolean_array_t *dest)
Expand Down Expand Up @@ -297,9 +289,9 @@ void indexed_assign_boolean_array(boolean_array_t* source,
assert(j == source->ndims);

mem_state = get_memory_state();
idx_vec1 = size_alloc(dest->ndims);
idx_vec2 = size_alloc(source->ndims);
idx_size = size_alloc(dest_spec->ndims);
idx_vec1 = size_alloc(0,dest->ndims);
idx_vec2 = size_alloc(0,source->ndims);
idx_size = size_alloc(0,dest_spec->ndims);

for (i = 0; i < dest_spec->ndims; ++i) {
idx_vec1[i] = 0;
Expand Down Expand Up @@ -366,9 +358,9 @@ void index_boolean_array(boolean_array_t* source,
assert(j == dest->ndims);

mem_state = get_memory_state();
idx_vec1 = size_alloc(source->ndims); /*indices in the source array*/
idx_vec2 = size_alloc(dest->ndims); /* indices in the destination array*/
idx_size = size_alloc(source_spec->ndims);
idx_vec1 = size_alloc(0,source->ndims); /*indices in the source array*/
idx_vec2 = size_alloc(0,dest->ndims); /* indices in the destination array*/
idx_size = size_alloc(0,source_spec->ndims);

for (i = 0; i < source->ndims; ++i) idx_vec1[i] = 0;
for (i = 0; i < source_spec->ndims; ++i) {
Expand Down Expand Up @@ -433,7 +425,7 @@ void index_alloc_boolean_array(boolean_array_t* source,
}

dest->ndims = source->ndims + ndimsdiff;
dest->dim_size = size_alloc(dest->ndims);
dest->dim_size = size_alloc(0,dest->ndims);

for (i = 0,j = 0; i < dest->ndims; ++i) {
while (source_spec->index_type[i+j] == 'S') ++j; /* Skip scalars */
Expand Down Expand Up @@ -613,8 +605,8 @@ void cat_alloc_boolean_array(int k, boolean_array_t* dest, int n,
if (k == 1) {
int r,c,j;
int dim_size_2 = elts[0]->dim_size[1];
dest->data = boolean_alloc(dim_size_2 * new_k_dim_size);
dest->dim_size = size_alloc(2);
dest->data = boolean_alloc(0,dim_size_2 * new_k_dim_size);
dest->dim_size = size_alloc(0,2);
dest->dim_size[0] = new_k_dim_size;
dest->dim_size[1] = dim_size_2;
dest->ndims = 2;
Expand All @@ -632,8 +624,8 @@ void cat_alloc_boolean_array(int k, boolean_array_t* dest, int n,
else if (k == 2) {
int r,c,j;
int dim_size_1 = elts[0]->dim_size[0];
dest->data = boolean_alloc(dim_size_1 * new_k_dim_size);
dest->dim_size = size_alloc(2);
dest->data = boolean_alloc(0,dim_size_1 * new_k_dim_size);
dest->dim_size = size_alloc(0,2);
dest->dim_size[0] = dim_size_1;
dest->dim_size[1] = new_k_dim_size;
dest->ndims = 2;
Expand Down Expand Up @@ -678,7 +670,7 @@ void promote_boolean_array(boolean_array_t* a, int n,boolean_array_t* dest)
{
int i;

dest->dim_size = size_alloc(n+a->ndims);
dest->dim_size = size_alloc(0,n+a->ndims);
dest->data = a->data;
/* Assert a->ndims>=n */
for (i = 0; i < a->ndims; ++i) {
Expand All @@ -704,10 +696,10 @@ void promote_scalar_boolean_array(modelica_boolean s,int n,
/* Assert that dest is of correct dimension */

/* Alloc size */
dest->dim_size = size_alloc(n);
dest->dim_size = size_alloc(0,n);

/* Alloc data */
dest->data = boolean_alloc(1);
dest->data = boolean_alloc(0,1);

dest->ndims = n;
boolean_set(dest, 0, s);
Expand Down Expand Up @@ -871,7 +863,7 @@ void fill_alloc_boolean_array(boolean_array_t* dest, modelica_boolean value, int
va_start(ap, ndims);
elements = alloc_base_array(dest, ndims, ap);
va_end(ap);
dest->data = boolean_alloc(elements);
dest->data = boolean_alloc(0,elements);

for(i = 0; i < elements; ++i)
{
Expand Down
12 changes: 6 additions & 6 deletions c_runtime/index_spec.c
Expand Up @@ -76,10 +76,10 @@ int index_spec_ok(index_spec_t* s)
void alloc_index_spec(index_spec_t* s)
{
int i;
s->index = index_alloc(s->ndims);
s->index = index_alloc(0,s->ndims);
for (i = 0; i < s->ndims; ++i) {
if (s->dim_size[i] > 0) {
s->index[i] = size_alloc(s->dim_size[i]);
s->index[i] = size_alloc(0,s->dim_size[i]);
} else {
s->index[i] = 0;
}
Expand All @@ -105,9 +105,9 @@ void create_index_spec(index_spec_t* dest, int nridx, ...)
va_start(ap,nridx);

dest->ndims = nridx;
dest->dim_size = size_alloc(nridx);
dest->index = index_alloc(nridx);
dest->index_type = char_alloc(nridx);
dest->dim_size = size_alloc(0,nridx);
dest->index = index_alloc(0,nridx);
dest->index_type = char_alloc(0,nridx);
for (i = 0; i < nridx; ++i) {
dest->dim_size[i] = va_arg(ap, _index_t);
dest->index[i] = va_arg(ap, _index_t*);
Expand All @@ -128,7 +128,7 @@ _index_t* make_index_array(int nridx, ...)
va_list ap;
va_start(ap,nridx);

res = size_alloc(nridx);
res = size_alloc(0,nridx);
for (i = 0; i < nridx; ++i) {
res[i] = va_arg(ap,_index_t);
}
Expand Down
47 changes: 19 additions & 28 deletions c_runtime/integer_array.c
Expand Up @@ -92,12 +92,12 @@ void integer_array_create(integer_array_t *dest, modelica_integer *data,

void simple_alloc_1d_integer_array(integer_array_t* dest, int n)
{
simple_alloc_1d_base_array(dest, n, integer_alloc(n));
simple_alloc_1d_base_array(dest, n, integer_alloc(0,n));
}

void simple_alloc_2d_integer_array(integer_array_t* dest, int r, int c)
{
simple_alloc_2d_base_array(dest, r, c, integer_alloc(r * c));
simple_alloc_2d_base_array(dest, r, c, integer_alloc(0,r * c));
}

void alloc_integer_array(integer_array_t* dest,int ndims,...)
Expand All @@ -107,20 +107,12 @@ void alloc_integer_array(integer_array_t* dest,int ndims,...)
va_start(ap, ndims);
elements = alloc_base_array(dest, ndims, ap);
va_end(ap);
dest->data = integer_alloc(elements);
dest->data = integer_alloc(0,elements);
}

void alloc_integer_array_data(integer_array_t* a)
{
a->data = integer_alloc(base_array_nr_of_elements(a));
}

void free_integer_array_data(integer_array_t* a)
{
size_t array_size;
assert(base_array_ok(a));
array_size = integer_array_nr_of_elements(a);
integer_free(array_size);
a->data = integer_alloc(0,base_array_nr_of_elements(a));
}

void copy_integer_array_data(integer_array_t* source, integer_array_t* dest)
Expand Down Expand Up @@ -327,9 +319,9 @@ void indexed_assign_integer_array(integer_array_t* source,
assert(j == source->ndims);

mem_state = get_memory_state();
idx_vec1 = size_alloc(dest->ndims);
idx_vec2 = size_alloc(source->ndims);
idx_size = size_alloc(dest_spec->ndims);
idx_vec1 = size_alloc(0,dest->ndims);
idx_vec2 = size_alloc(0,source->ndims);
idx_size = size_alloc(0,dest_spec->ndims);

for (i = 0; i < dest_spec->ndims; ++i) {
idx_vec1[i] = 0;
Expand Down Expand Up @@ -397,9 +389,9 @@ void index_integer_array(integer_array_t* source,
assert(j == dest->ndims);

mem_state = get_memory_state();
idx_vec1 = size_alloc(source->ndims); /*indices in the source array*/
idx_vec2 = size_alloc(dest->ndims); /* indices in the destination array*/
idx_size = size_alloc(source_spec->ndims);
idx_vec1 = size_alloc(0,source->ndims); /*indices in the source array*/
idx_vec2 = size_alloc(0,dest->ndims); /* indices in the destination array*/
idx_size = size_alloc(0,source_spec->ndims);

for (i = 0; i < source->ndims; ++i) idx_vec1[i] = 0;
for (i = 0; i < source_spec->ndims; ++i) {
Expand Down Expand Up @@ -464,7 +456,7 @@ void index_alloc_integer_array(integer_array_t* source,
}

dest->ndims = source->ndims + ndimsdiff;
dest->dim_size = size_alloc(dest->ndims);
dest->dim_size = size_alloc(0,dest->ndims);

for (i = 0,j = 0; i < dest->ndims; ++i) {
while (source_spec->index_type[i+j] == 'S') ++j; /* Skip scalars */
Expand Down Expand Up @@ -644,8 +636,8 @@ void cat_alloc_integer_array(int k, integer_array_t* dest, int n,
if (k == 1) {
int r,c,j;
int dim_size_2 = elts[0]->dim_size[1];
dest->data = integer_alloc(dim_size_2*new_k_dim_size);
dest->dim_size = size_alloc(2);
dest->data = integer_alloc(0,dim_size_2*new_k_dim_size);
dest->dim_size = size_alloc(0,2);
dest->dim_size[0] = new_k_dim_size;
dest->dim_size[1] = dim_size_2;
dest->ndims = 2;
Expand All @@ -663,8 +655,8 @@ void cat_alloc_integer_array(int k, integer_array_t* dest, int n,
else if (k == 2) {
int r,c,j;
int dim_size_1 = elts[0]->dim_size[0];
dest->data = integer_alloc(dim_size_1 * new_k_dim_size);
dest->dim_size = size_alloc(2);
dest->data = integer_alloc(0,dim_size_1 * new_k_dim_size);
dest->dim_size = size_alloc(0,2);
dest->dim_size[0] = dim_size_1;
dest->dim_size[1] = new_k_dim_size;
dest->ndims = 2;
Expand Down Expand Up @@ -959,7 +951,6 @@ void exp_integer_array(integer_array_t* a, modelica_integer n, integer_array_t*
mul_integer_matrix_product(a,tmp,dest);
copy_integer_array_data(dest,tmp);
}
free_integer_array_data(tmp);
}
}
}
Expand Down Expand Up @@ -995,7 +986,7 @@ void promote_integer_array(integer_array_t* a, int n,integer_array_t* dest)
{
int i;

dest->dim_size = size_alloc(n+a->ndims);
dest->dim_size = size_alloc(0,n+a->ndims);
dest->data = a->data;
/* Assert a->ndims>=n */
for (i = 0; i < a->ndims; ++i) {
Expand All @@ -1018,10 +1009,10 @@ void promote_scalar_integer_array(modelica_integer s,int n,integer_array_t* dest
/* Assert that dest is of correct dimension */

/* Alloc size */
dest->dim_size = size_alloc(n);
dest->dim_size = size_alloc(0,n);

/* Alloc data */
dest->data = integer_alloc(1);
dest->data = integer_alloc(0,1);

dest->ndims = n;
integer_set(dest, 0, s);
Expand Down Expand Up @@ -1170,7 +1161,7 @@ void fill_alloc_integer_array(integer_array_t* dest, modelica_integer value, int
va_start(ap, ndims);
elements = alloc_base_array(dest, ndims, ap);
va_end(ap);
dest->data = integer_alloc(elements);
dest->data = integer_alloc(0,elements);

for(i = 0; i < elements; ++i)
{
Expand Down

0 comments on commit 40420cb

Please sign in to comment.