src/frontend/outif.c, plotAddRealValue() etc, rallocate more coarsely
reallocate in chunks, instead of once per time step.
This commit is contained in:
parent
9d32a0a5a9
commit
03b47b3e34
|
|
@ -16,6 +16,7 @@ dvec_alloc(char *name, int type, short flags, int length, void *storage)
|
|||
rv->v_type = type;
|
||||
rv->v_flags = flags;
|
||||
rv->v_length = length;
|
||||
rv->v_alloc_length = length;
|
||||
|
||||
if (!length) {
|
||||
rv->v_realdata = NULL;
|
||||
|
|
@ -60,6 +61,19 @@ dvec_realloc(struct dvec *v, int length, void *storage)
|
|||
}
|
||||
|
||||
v->v_length = length;
|
||||
v->v_alloc_length = length;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dvec_extend(struct dvec *v, int length)
|
||||
{
|
||||
if (isreal(v))
|
||||
v->v_realdata = TREALLOC(double, v->v_realdata, length);
|
||||
else
|
||||
v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, length);
|
||||
|
||||
v->v_alloc_length = length;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**********
|
||||
Copyright 1990 Regents of the University of California. All rights reserved.
|
||||
Author: 1988 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||
Modified: 2000 AlansFixes
|
||||
Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski
|
||||
**********/
|
||||
|
||||
/*
|
||||
|
|
@ -1057,17 +1057,35 @@ plotInit(runDesc *run)
|
|||
}
|
||||
|
||||
|
||||
static inline int
|
||||
vlength2delta(int l)
|
||||
{
|
||||
if (l < 50000)
|
||||
return 512;
|
||||
if (l < 200000)
|
||||
return 256;
|
||||
if (l < 500000)
|
||||
return 128;
|
||||
/* larger memory allocations may exhaust memory easily
|
||||
* this function may use better estimation depending on
|
||||
* available memory and number of vectors (run->numData)
|
||||
*/
|
||||
return 64;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
plotAddRealValue(dataDesc *desc, double value)
|
||||
{
|
||||
struct dvec *v = desc->vec;
|
||||
|
||||
if (v->v_length >= v->v_alloc_length)
|
||||
dvec_extend(v, v->v_length + vlength2delta(v->v_length));
|
||||
|
||||
if (isreal(v)) {
|
||||
v->v_realdata = TREALLOC(double, v->v_realdata, v->v_length + 1);
|
||||
v->v_realdata[v->v_length] = value;
|
||||
} else {
|
||||
/* a real parading as a VF_COMPLEX */
|
||||
v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, v->v_length + 1);
|
||||
v->v_compdata[v->v_length].cx_real = value;
|
||||
v->v_compdata[v->v_length].cx_imag = 0.0;
|
||||
}
|
||||
|
|
@ -1082,7 +1100,9 @@ plotAddComplexValue(dataDesc *desc, IFcomplex value)
|
|||
{
|
||||
struct dvec *v = desc->vec;
|
||||
|
||||
v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, v->v_length + 1);
|
||||
if (v->v_length >= v->v_alloc_length)
|
||||
dvec_extend(v, v->v_length + vlength2delta(v->v_length));
|
||||
|
||||
v->v_compdata[v->v_length].cx_real = value.real;
|
||||
v->v_compdata[v->v_length].cx_imag = value.imag;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ struct dvec {
|
|||
GRIDTYPE v_gridtype; /* One of GRID_*. */
|
||||
PLOTTYPE v_plottype; /* One of PLOT_*. */
|
||||
int v_length; /* Length of the vector. */
|
||||
int v_alloc_length; /* How much has been actually allocated. */
|
||||
int v_rlength; /* How much space we really have. Used as binary flag */
|
||||
int v_outindex; /* Index if writedata is building the
|
||||
vector. */
|
||||
|
|
@ -70,6 +71,7 @@ struct dveclist {
|
|||
|
||||
struct dvec *dvec_alloc(char *name, int type, short flags, int length, void *storage);
|
||||
void dvec_realloc(struct dvec *v, int length, void *storage);
|
||||
void dvec_extend(struct dvec *v, int length);
|
||||
void dvec_trunc(struct dvec *v, int length);
|
||||
void dvec_free(struct dvec *);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue