From 97ed64f438f12703bbe473d854b3a6025323d0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 9 May 2012 19:15:41 +0200 Subject: [PATCH] Call malloc() once, at pimpl construction time, rather than in each *_increment(). It's slightly wasteful, however. Maybe we can just reuse h->x for the mult_csr_matrix() output? --- opm/core/pressure/tpfa/ifs_tpfa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opm/core/pressure/tpfa/ifs_tpfa.c b/opm/core/pressure/tpfa/ifs_tpfa.c index 81d16d016..6b0967e82 100644 --- a/opm/core/pressure/tpfa/ifs_tpfa.c +++ b/opm/core/pressure/tpfa/ifs_tpfa.c @@ -33,6 +33,7 @@ mult_csr_matrix(const struct CSRMatrix *A, struct ifs_tpfa_impl { double *fgrav; /* Accumulated grav contrib/face */ + double *work; /* Linear storage */ double *ddata; @@ -70,6 +71,7 @@ impl_allocate(struct UnstructuredGrid *G, ddata_sz = 2 * nnu; /* b, x */ ddata_sz += 1 * G->number_of_faces; /* fgrav */ + ddata_sz += 1 * nnu; /* work */ new = malloc(1 * sizeof *new); @@ -677,6 +679,7 @@ ifs_tpfa_construct(struct UnstructuredGrid *G, new->x = new->b + new->A->m; new->pimpl->fgrav = new->x + new->A->m; + new->pimpl->work = new->pimpl->fgrav + G->number_of_faces; } return new; @@ -766,8 +769,7 @@ ifs_tpfa_assemble_comprock_increment(struct UnstructuredGrid *G , assemble_incompressible(G, F, trans, gpress, h, &system_singular, &ok); - v = malloc(h->A->m * sizeof *v); - + v = h->pimpl->work; mult_csr_matrix(h->A, prev_pressure, v); /* We want to solve a Newton step for the residual @@ -783,8 +785,6 @@ ifs_tpfa_assemble_comprock_increment(struct UnstructuredGrid *G , } } - free(v); - return ok; }