Skip to content

Commit a9fe4c2

Browse files
committed
updates to support memory leak reductions in biotissue
1 parent 2f1330b commit a9fe4c2

File tree

6 files changed

+57
-9
lines changed

6 files changed

+57
-9
lines changed

src/las.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ namespace las
156156
* @param cm The comm over which the vector is collective.
157157
*/
158158
virtual Vec * create(unsigned lcl, unsigned bs, MPI_Comm cm) = 0;
159+
/**
160+
* Create a vector from an existing array
161+
* @param data The array which the vector will use as data storage
162+
* @param lcl The local number of rows (per-process in cm)
163+
* @param bs The block size (should be the same over cm)
164+
* @param cm The comm over which the vector is collective.
165+
*/
166+
virtual Vec * create(scalar * data, unsigned lcl, unsigned bs, MPI_Comm cm)=0;
159167
virtual void destroy(Vec * v) = 0;
160168
/**
161169
* Create a vector suitable to act as the RHS vector to a

src/lasDense_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ namespace las
9999
{
100100
return createVector(lcl);
101101
}
102+
virtual Vec * create(scalar * data, unsigned lcl, unsigned, MPI_Comm)
103+
{
104+
return createVector(data, lcl);
105+
}
102106
virtual void destroy(Vec * v)
103107
{
104108
destroyVector(v);

src/lasPETSc_impl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ namespace las
230230
CHKERRABORT(LAS_COMM_WORLD, ierr);
231231
return reinterpret_cast<las::Vec*>(v);
232232
}
233+
LAS_INLINE las::Vec * createPetscVector(scalar * data, unsigned l, unsigned bs, MPI_Comm cm = LAS_COMM_WORLD)
234+
{
235+
::Vec * v = new ::Vec;
236+
PetscErrorCode ierr = VecCreateMPIWithArray(cm, bs, l,PETSC_DECIDE,data, v);
237+
CHKERRABORT(LAS_COMM_WORLD, ierr);
238+
ierr = VecSetOption(*v,VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE);
239+
CHKERRABORT(LAS_COMM_WORLD, ierr);
240+
return reinterpret_cast<las::Vec*>(v);
241+
}
233242
LAS_INLINE void destroyPetscVec(las::Vec * v)
234243
{
235244
PetscErrorCode ierr = VecDestroy(getPetscVec(v));
@@ -255,6 +264,10 @@ namespace las
255264
{
256265
return createPetscVector(lcl,bs,cm);
257266
}
267+
virtual Vec * create(scalar * data, unsigned lcl, unsigned bs, MPI_Comm cm)
268+
{
269+
return createPetscVector(data, lcl,bs,cm);
270+
}
258271
virtual Vec * createRHS(Mat * m)
259272
{
260273
return createRHSVec(m);

src/lasSparse_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ namespace las
103103
{
104104
return createVector(lcl);
105105
}
106+
virtual Vec * create(scalar * data, unsigned lcl, unsigned, MPI_Comm)
107+
{
108+
return createVector(data, lcl);
109+
}
106110
virtual void destroy(Vec * v)
107111
{
108112
destroyVector(v);

src/lasSparskitExterns.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ namespace las
5959
matrix.assign(matrix.size(),0.0);
6060
}
6161
void SparskitBuffers::resizeMatrixBuffer(int newSize) {
62-
assert((newSize-matrixLength()) > 0);
63-
heuristic_length = newSize;
64-
matrix.resize(heuristic_length);
65-
cols.resize(heuristic_length);
66-
assert(cols.size() == heuristic_length);
67-
assert(matrix.size() == heuristic_length);
62+
// only support increasing the buffer size
63+
if(newSize > matrixLength())
64+
{
65+
heuristic_length = newSize;
66+
matrix.resize(heuristic_length);
67+
cols.resize(heuristic_length);
68+
assert(cols.size() == heuristic_length);
69+
assert(matrix.size() == heuristic_length);
70+
}
6871
}
6972
};

src/lasVec_impl.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@
55
#include <lasSys.h>
66
#include <cassert>
77
#include <cstring> // memset
8+
#include <iostream>
89
namespace las
910
{
1011
class lasVec
1112
{
1213
private:
1314
scalar * vls;
1415
int cnt;
16+
// this is a data location that any negative indices will
17+
// sum into
18+
scalar dummy_data;
1519
public:
1620
lasVec(int n)
1721
: vls(nullptr)
1822
, cnt(n)
23+
, dummy_data(0)
24+
{
25+
alloc<Malloc>((void**)&vls,sizeof(scalar)*n);
26+
}
27+
lasVec(scalar * data, int n)
28+
: vls(data)
29+
, cnt(n)
30+
, dummy_data(0)
1931
{
20-
alloc<Malloc>((void**)&vls,sizeof(scalar)*(n+1));
2132
}
2233
~lasVec()
2334
{
@@ -27,7 +38,7 @@ namespace las
2738
{
2839
assert(idx < cnt);
2940
if(idx < 0)
30-
idx = cnt;
41+
return dummy_data;
3142
return vls[idx];
3243
}
3344
void setVls(scalar * values) {
@@ -41,7 +52,8 @@ namespace las
4152
// too coupled to the implementation to leave external
4253
void zero()
4354
{
44-
memset(&vls[0],0,sizeof(scalar)*(cnt+1));
55+
memset(&vls[0],0,sizeof(scalar)*cnt);
56+
dummy_data = 0;
4557
}
4658
};
4759
LAS_INLINE lasVec * getLASVec(Vec * v)
@@ -52,6 +64,10 @@ namespace las
5264
{
5365
return reinterpret_cast<Vec*>(new lasVec(n));
5466
}
67+
LAS_INLINE Vec * createVector(scalar * data, unsigned n)
68+
{
69+
return reinterpret_cast<Vec*>(new lasVec(data,n));
70+
}
5571
LAS_INLINE void destroyVector(Vec * v)
5672
{
5773
delete getLASVec(v);

0 commit comments

Comments
 (0)