Commit 432cf0c5 authored by incardon's avatar incardon

Fixing memory leak

parent 1bc30abe
Pipeline #2097 passed with stages
in 20 minutes and 45 seconds
......@@ -177,6 +177,24 @@ class Metis
Mg.xadj[id] = prev;
}
void reset_pointer()
{
Mg.nvtxs = NULL;
Mg.ncon = NULL;
Mg.xadj = NULL;
Mg.adjncy = NULL;
Mg.vwgt = NULL;
Mg.adjwgt = NULL;
Mg.nparts = NULL;
Mg.tpwgts = NULL;
Mg.ubvec = NULL;
Mg.options = NULL;
Mg.objval = NULL;
Mg.part = NULL;
Mg.vsize = NULL;
}
public:
/*! \brief Constructor
......@@ -191,6 +209,7 @@ public:
Metis(Graph & g, size_t nc, bool useWeights)
:g(g),n_dec(0)
{
reset_pointer();
initMetisGraph(nc,useWeights);
}
......@@ -205,6 +224,7 @@ public:
Metis(Graph & g, size_t nc)
:g(g),n_dec(0)
{
reset_pointer();
initMetisGraph(nc,false);
}
......@@ -219,19 +239,7 @@ public:
Metis(Graph & g)
:g(g),n_dec(0)
{
Mg.nvtxs = NULL;
Mg.ncon = NULL;
Mg.xadj = NULL;
Mg.adjncy = NULL;
Mg.vwgt = NULL;
Mg.adjwgt = NULL;
Mg.nparts = NULL;
Mg.tpwgts = NULL;
Mg.ubvec = NULL;
Mg.options = NULL;
Mg.objval = NULL;
Mg.part = NULL;
Mg.vsize = NULL;
reset_pointer();
}
......@@ -246,24 +254,34 @@ public:
// Get the number of vertex
if (Mg.nvtxs != NULL)
{delete[] Mg.nvtxs;}
Mg.nvtxs = new idx_t[1];
Mg.nvtxs[0] = g.getNVertex();
// Set the number of constrains
if (Mg.ncon != NULL)
{delete[] Mg.ncon;}
Mg.ncon = new idx_t[1];
Mg.ncon[0] = 1;
// Set to null the weight of the vertex
if (Mg.vwgt != NULL)
{delete[] Mg.vwgt;}
Mg.vwgt = NULL;
// Put the total communication size to NULL
if (Mg.vsize != NULL)
{delete[] Mg.vsize;}
Mg.vsize = NULL;
// Set to null the weight of the edge
if (Mg.adjwgt != NULL)
{delete[] Mg.adjwgt;}
Mg.adjwgt = NULL;
// construct the adjacency list
......@@ -274,25 +292,36 @@ public:
// Set the total number of partitions
if (Mg.nparts != NULL)
{delete[] Mg.nparts;}
Mg.nparts = new idx_t[1];
Mg.nparts[0] = nc;
// Set to null the desired weight for each partition (one for each constrain)
if (Mg.tpwgts != NULL)
{delete[] Mg.tpwgts;}
Mg.tpwgts = NULL;
//! Set to null the partition load imbalance tolerance
if (Mg.ubvec != NULL)
{delete[] Mg.ubvec;}
Mg.ubvec = NULL;
//! Set tp null additional option for the graph partitioning
if (Mg.options != NULL)
{delete[] Mg.options;}
Mg.options = NULL;
//! set the objective value
if (Mg.objval != NULL)
{delete[] Mg.objval;}
Mg.objval = new idx_t[1];
//! Is an output vector containing the partition for each vertex
if (Mg.part != NULL)
{delete[] Mg.part;}
Mg.part = new idx_t[g.getNVertex()];
for (size_t i = 0; i < g.getNVertex(); i++)
......
......@@ -282,6 +282,16 @@ public:
{
delete[] Mg.wgtflag;
}
if (Mg.itr != NULL)
{
delete[] Mg.itr;
}
if (Mg.vsize != NULL)
{
delete[] Mg.vsize;
}
}
/*! \brief Set the Sub-graph
......@@ -295,20 +305,28 @@ public:
// Get the number of vertex
if (Mg.nvtxs != NULL)
{delete[] Mg.nvtxs;}
Mg.nvtxs = new idx_t[1];
Mg.nvtxs[0] = sub_g.getNVertex();
// Set the number of constrains
if (Mg.ncon != NULL)
{delete[] Mg.ncon;}
Mg.ncon = new idx_t[1];
Mg.ncon[0] = 1;
// Set to null the weight of the vertex (init after in constructAdjList) (can be removed)
if (Mg.vwgt != NULL)
{delete[] Mg.vwgt;}
Mg.vwgt = NULL;
// Set to null the weight of the edge (init after in constructAdjList) (can be removed)
if (Mg.adjwgt != NULL)
{delete[] Mg.adjwgt;}
Mg.adjwgt = NULL;
// construct the adjacency list
......@@ -317,11 +335,15 @@ public:
// Set the total number of partitions
if (Mg.nparts != NULL)
{delete[] Mg.nparts;}
Mg.nparts = new idx_t[1];
Mg.nparts[0] = nc;
//! Set option for the graph partitioning (set as default)
if (Mg.options != NULL)
{delete[] Mg.options;}
Mg.options = new idx_t[4];
Mg.options[0] = 0;
Mg.options[1] = 0;
......@@ -329,11 +351,17 @@ public:
Mg.options[3] = 0;
//! adaptiveRepart itr value
if (Mg.itr != NULL)
{delete[] Mg.itr;}
Mg.itr = new real_t[1];
Mg.itr[0] = 1000.0;
//! init tpwgts to have balanced vertices and ubvec
if (Mg.tpwgts != NULL)
{delete[] Mg.tpwgts;}
if (Mg.ubvec != NULL)
{delete[] Mg.ubvec;}
Mg.tpwgts = new real_t[Mg.nparts[0]];
Mg.ubvec = new real_t[Mg.nparts[0]];
......@@ -343,14 +371,20 @@ public:
Mg.ubvec[s] = 1.05;
}
if (Mg.edgecut != NULL)
{delete[] Mg.edgecut;}
Mg.edgecut = new idx_t[1];
Mg.edgecut[0] = 0;
//! This is used to indicate the numbering scheme that is used for the vtxdist, xadj, adjncy, and part arrays. (0 for C-style, start from 0 index)
if (Mg.numflag != NULL)
{delete[] Mg.numflag;}
Mg.numflag = new idx_t[1];
Mg.numflag[0] = 0;
//! This is used to indicate if the graph is weighted.
if (Mg.wgtflag != NULL)
{delete[] Mg.wgtflag;}
Mg.wgtflag = new idx_t[1];
Mg.wgtflag[0] = 3;
}
......
......@@ -559,6 +559,8 @@ class DistGraph_CSR
openfpm::vector<size_t> size;
openfpm::vector<void *> ptr;
openfpm::vector<HeapMemory> packs(vcl.getProcessingUnits());
openfpm::vector<HeapMemory *> to_release;
openfpm::vector<ExtPreAlloc<HeapMemory> *> to_release_ext;
// Total number of vertex to send
size_t nvts = 0;
......@@ -613,9 +615,11 @@ class DistGraph_CSR
HeapMemory & pmem = *(new HeapMemory());
// pmem.allocate(req);
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req, pmem));
mem.incRef();
to_release.add(&pmem);
to_release_ext.add(&mem);
Pack_stat sts;
size_t e_it = 0;
......@@ -657,6 +661,14 @@ class DistGraph_CSR
// Exchange informations through processors
vcl.sendrecvMultipleMessagesNBX(prc.size(), (size_t *)size.getPointer(), (size_t *)prc.getPointer(), (void **)ptr.getPointer(), gr_receive, &packs, NONE);
for (int i = 0 ; i < to_release_ext.size(); i++)
{
to_release_ext.get(i)->decRef();
delete to_release_ext.get(i);
delete to_release.get(i);
}
for (size_t i = 0; i < vcl.getProcessingUnits(); i++)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment