Skip to content

Commit

Permalink
Added destructor to AdjListHyperGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisJenkinsCS committed Jul 31, 2018
1 parent fb71970 commit 701d234
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/modules/AdjListHyperGraph.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ module AdjListHyperGraph {
instance = new AdjListHyperGraphImpl(other);
pid = instance.pid;
}

proc destroy() {
if pid == -1 then halt("Attempt to destroy 'AdjListHyperGraph' which is not initialized...");
coforall loc in Locales do on loc {
delete chpl_getPrivatizedCopy(instance.type, pid);
}
pid = -1;
}

forwarding _value;
}
Expand Down Expand Up @@ -331,10 +339,6 @@ module AdjListHyperGraph {
<~> neighborListDom
<~> new ioLiteral(", neighborlist = ")
<~> neighborList
<~> new ioLiteral(", lock$ = ")
<~> lock.read()
<~> new ioLiteral("(isFull: ")
<~> lock.read()
<~> new ioLiteral(") }");
}
}
Expand Down Expand Up @@ -500,6 +504,16 @@ module AdjListHyperGraph {
this._privatizedVerticesPID = other._privatizedVerticesPID;
this._privatizedEdgesPID = other._privatizedEdgesPID;
}

pragma "no doc"
proc deinit() {
// Only delete data from master locale
if this._masterHandle == nil {
_destBuffer.destroy();
delete _vertices;
delete _edges;
}
}

pragma "no doc"
proc dsiPrivatize(pid) {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/AdjListHyperGraph/graph-destroy.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use AdjListHyperGraph;

var graph = new AdjListHyperGraph(1,1);
graph.destroy();
assert(graph.pid == -1, "Graph has non-nil pid!");
Empty file.

0 comments on commit 701d234

Please sign in to comment.