Skip to content

Commit ea4b239

Browse files
authored
Corrected Memory Leak in Partitioning (#230)
Analized with Valgrind Fix #229 Signed-off-by: ZigRazor <[email protected]> Signed-off-by: ZigRazor <[email protected]>
1 parent 8b92387 commit ea4b239

19 files changed

+75
-19826
lines changed

Diff for: benchmark/GraphSlicing_BM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ static void GraphSlicing_X(benchmark::State &state)
1919
auto &result = g.graph_slicing(*(range_start->second->getNodePair().first));
2020
}
2121
}
22-
BENCHMARK(GraphSlicing_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 12);
22+
BENCHMARK(GraphSlicing_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 8);

Diff for: benchmark/Graph_BM.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static void ReadGraphCitHep(benchmark::State &state)
5050
for (auto _ : state)
5151
{
5252
auto g = readGraph("CitHepPh");
53+
delete g;
5354
}
5455
}
5556

@@ -95,21 +96,19 @@ BENCHMARK(getNodeSetX)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned l
9596

9697
static void getEdgeSetCitHep(benchmark::State &state)
9798
{
98-
auto g = readGraph("CitHepPh");
9999
for (auto _ : state)
100100
{
101-
auto edgeSet = g->getEdgeSet();
101+
auto edgeSet = cit_graph_ptr->getEdgeSet();
102102
}
103103
}
104104

105105
BENCHMARK(getEdgeSetCitHep);
106106

107107
static void getNodeSetCitHep(benchmark::State &state)
108108
{
109-
auto g = readGraph("CitHepPh");
110109
for (auto _ : state)
111110
{
112-
auto nodeSet = g->getNodeSet();
111+
auto nodeSet = cit_graph_ptr->getNodeSet();
113112
}
114113
}
115114

@@ -135,23 +134,11 @@ static void getAdjMatrixX(benchmark::State &state)
135134

136135
BENCHMARK(getAdjMatrixX)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);
137136

138-
static void readCitHep(benchmark::State &state)
139-
{
140-
141-
for (auto _ : state)
142-
{
143-
auto g = readGraph("CitHepPh");
144-
}
145-
}
146-
147-
BENCHMARK(readCitHep);
148-
149137
static void getAdjMatrixCitHep(benchmark::State &state)
150138
{
151-
auto g = readGraph("CitHepPh");
152139
for (auto _ : state)
153140
{
154-
auto adjMatrix = g->getAdjMatrix();
141+
auto adjMatrix = cit_graph_ptr->getAdjMatrix();
155142
}
156143
}
157144

Diff for: benchmark/Utilities.hpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
static std::map<unsigned long, CXXGRAPH::Node<int> *> generateRandomNodes(unsigned long numberOfNodes, int MaxValue)
88
{
99
std::map<unsigned long, CXXGRAPH::Node<int> *> nodes;
10-
srand((unsigned)time(NULL));
10+
unsigned int randSeed = (unsigned int)time(NULL);
11+
srand(randSeed);
1112
int randomNumber;
1213
for (auto index = 0; index < numberOfNodes; index++)
1314
{
14-
randomNumber = (rand_r(NULL) % MaxValue) + 1;
15+
randomNumber = (rand_r(&randSeed) % MaxValue) + 1;
1516
CXXGRAPH::Node<int> *newNode = new CXXGRAPH::Node<int>(std::to_string(index), randomNumber);
1617
nodes[index] = newNode;
1718
}
@@ -21,14 +22,15 @@ static std::map<unsigned long, CXXGRAPH::Node<int> *> generateRandomNodes(unsign
2122
static std::map<unsigned long, CXXGRAPH::Edge<int> *> generateRandomEdges(unsigned long numberOfEdges, std::map<unsigned long, CXXGRAPH::Node<int> *> nodes)
2223
{
2324
std::map<unsigned long, CXXGRAPH::Edge<int> *> edges;
24-
srand((unsigned)time(NULL));
25+
unsigned int randSeed = (unsigned int)time(NULL);
26+
srand(randSeed);
2527
int randomNumber1;
2628
int randomNumber2;
2729
auto MaxValue = nodes.size();
2830
for (auto index = 0; index < numberOfEdges; index++)
2931
{
30-
randomNumber1 = (rand_r(NULL) % MaxValue);
31-
randomNumber2 = (rand_r(NULL) % MaxValue);
32+
randomNumber1 = (rand_r(&randSeed) % MaxValue);
33+
randomNumber2 = (rand_r(&randSeed) % MaxValue);
3234
CXXGRAPH::Edge<int> *newEdge = new CXXGRAPH::Edge<int>(index, *(nodes.at(randomNumber1)), *(nodes.at(randomNumber2)));
3335
edges[index] = newEdge;
3436
}
@@ -38,14 +40,15 @@ static std::map<unsigned long, CXXGRAPH::Edge<int> *> generateRandomEdges(unsign
3840
static std::map<unsigned long, CXXGRAPH::UndirectedEdge<int> *> generateRandomUndirectedEdges(unsigned long numberOfEdges, std::map<unsigned long, CXXGRAPH::Node<int> *> nodes)
3941
{
4042
std::map<unsigned long, CXXGRAPH::UndirectedEdge<int> *> edges;
41-
srand((unsigned)time(NULL));
43+
unsigned int randSeed = (unsigned int)time(NULL);
44+
srand(randSeed);
4245
int randomNumber1;
4346
int randomNumber2;
4447
auto MaxValue = nodes.size();
4548
for (auto index = 0; index < numberOfEdges; index++)
4649
{
47-
randomNumber1 = (rand_r(NULL) % MaxValue);
48-
randomNumber2 = (rand_r(NULL) % MaxValue);
50+
randomNumber1 = (rand_r(&randSeed) % MaxValue);
51+
randomNumber2 = (rand_r(&randSeed) % MaxValue);
4952
CXXGRAPH::UndirectedEdge<int> *newEdge = new CXXGRAPH::UndirectedEdge<int>(index, *(nodes.at(randomNumber1)), *(nodes.at(randomNumber2)));
5053
edges[index] = newEdge;
5154
}

0 commit comments

Comments
 (0)