From 4d41c47187f28a26fadd4bc20dc1055bf67291a3 Mon Sep 17 00:00:00 2001 From: Louis Jenkins Date: Wed, 6 Jan 2021 14:57:23 -0500 Subject: [PATCH] Revising for paper deadline --- src/main.cpp | 2 +- src/rideables/TGraph.hpp | 37 ++++++++++++++++++++++++++----------- src/tests/GraphTest.hpp | 12 +++++++++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index db97eba3..fe618c8c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { GlobalTestConfig gtc; const size_t numVertices = 1024; - const size_t meanEdgesPerVertex = 32; + const size_t meanEdgesPerVertex = 20; const size_t vertexLoad = 50; /* queues */ diff --git a/src/rideables/TGraph.hpp b/src/rideables/TGraph.hpp index b3739f06..d86d34d2 100644 --- a/src/rideables/TGraph.hpp +++ b/src/rideables/TGraph.hpp @@ -93,9 +93,9 @@ class TGraph : public RGraph{ // Allocates data structures and pre-loads the graph TGraph(GlobalTestConfig* gtc) { - idxToVertex = new Vertex*[numVertices]; - vertexLocks = new std::atomic[numVertices]; - vertexSeqs = new uint32_t[numVertices]; + this->idxToVertex = new Vertex*[numVertices]; + this->vertexLocks = new std::atomic[numVertices]; + this->vertexSeqs = new uint32_t[numVertices]; std::mt19937_64 gen(0xDEADBEEF); std::uniform_int_distribution<> verticesRNG(0, numVertices - 1); std::uniform_int_distribution<> coinflipRNG(0, 100); @@ -108,14 +108,14 @@ class TGraph : public RGraph{ idxToVertex[i] = nullptr; } vertexLocks[i] = false; - vertexSeqs = 0; + vertexSeqs[i] = 0; } std::cout << "Filled vertexLoad" << std::endl; // Fill to mean edges per vertex for (int i = 0; i < numVertices; i++) { - for (int i = 0; i < meanEdgesPerVertex; i++) { + for (int i = 0; i < meanEdgesPerVertex * 100 / vertexLoad; i++) { if (idxToVertex[i] == nullptr) continue; int j = verticesRNG(gen); while (j == i) { @@ -185,6 +185,13 @@ class TGraph : public RGraph{ lock(dest); } + if (idxToVertex[src] == nullptr) { + idxToVertex[src] = new Vertex(src, src); + } + if (idxToVertex[dest] == nullptr) { + idxToVertex[dest] = new Vertex(dest, dest); + } + Relation r(src,dest,weight); auto& srcSet = source(src); auto& destSet = destination(dest); @@ -220,6 +227,10 @@ class TGraph : public RGraph{ // We utilize `get_unsafe` API because the Relation destination and vertex id will not change at all. lock(src); + if (idxToVertex[src] == nullptr) { + unlock(src); + return false; + } Relation r(src, dest, -1); retval = has_relation(source(src), &r); unlock(src); @@ -243,7 +254,7 @@ class TGraph : public RGraph{ lock(dest); } - { + if (idxToVertex[src] != nullptr && idxToVertex[dest] != nullptr) { Relation r(src, dest, -1); remove_relation(source(src), &r); remove_relation(destination(dest), &r); @@ -266,13 +277,13 @@ class TGraph : public RGraph{ int src = -1; int dest = -1; - if (idxToVertex[src] != nullptr) { + if (idxToVertex[vid] != nullptr) { // Check source first - auto search = source(src).begin(); - if (search == source(src).end()) { + auto search = source(vid).begin(); + if (search == source(vid).end()) { // Then destination - search = destination(src).begin(); - if (search == destination(src).end()) { + search = destination(vid).begin(); + if (search == destination(vid).end()) { goto failure; } } @@ -297,6 +308,10 @@ class TGraph : public RGraph{ // Step 1: Acquire vertex and collect neighbors... std::vector vertices; lock(vid); + if (idxToVertex[vid] == nullptr) { + unlock(vid); + return false; + } uint32_t seq = get_seq(vid); for (auto r : source(vid)) { vertices.push_back(r->dest); diff --git a/src/tests/GraphTest.hpp b/src/tests/GraphTest.hpp index 35dbfbf4..f09e9120 100644 --- a/src/tests/GraphTest.hpp +++ b/src/tests/GraphTest.hpp @@ -57,12 +57,14 @@ class GraphTest : public Test { // 2) clearProb = min(0, max(1, delta / 33%)) // 3) lookupProb = 100% - insertProb - removalProb - clearProb void update_ratio(double averageDegree) { - double ratio = min(2.0, max(desiredAvgDegree / averageDegree - 1, averageDegree / desiredAvgDegree - 1)); - int delta = 1650 * ratio; // 16.5% is half of 33% + int sign = averageDegree > desiredAvgDegree ? -1 : averageDegree < desiredAvgDegree ? 1 : 0; + double ratio = min(2.0, max((double) desiredAvgDegree / averageDegree - 1, averageDegree / (double) desiredAvgDegree - 1)); + int delta = 1650 * ratio * sign; // 16.5% is half of 33% insertionProb = 3300 + delta; removalProb = 3300 - delta; - clearProb = min(0.0, max(1.0, delta / 3300.0)); + clearProb = min(0.0, max(1.0, (double) delta / 3300.0)) * 100; lookupProb = 10000 - insertionProb - removalProb - clearProb; + std::cout << "sign(" << sign << "), ratio(" << ratio << "), delta(" << delta << ")" << std::endl; std::cout << "(" << insertionProb / 100.0 << "," << removalProb / 100.0 << "," << lookupProb / 100.0 << "," << clearProb / 100.0 << ")" << std::endl; } @@ -116,12 +118,16 @@ class GraphTest : public Test { } int rng = dist(gen_p); if (rng <= insertionProb) { + // std::cout << "rng(" << rng << ") is add_edge <= " << insertionProb << std::endl; g->add_edge(distv(gen_v), distv(gen_v), -1); } else if (rng <= insertionProb + removalProb) { + // std::cout << "rng(" << rng << ") is remove_any_edge <= " << insertionProb + removalProb << std::endl; g->remove_any_edge(distv(gen_v)); } else if (rng <= insertionProb + removalProb + lookupProb) { + // std::cout << "rng(" << rng << ") is has_edge <= " << insertionProb + removalProb + lookupProb << std::endl; g->has_edge(distv(gen_v), distv(gen_v)); } else { + // std::cout << "rng(" << rng << ") is remove_vertex..."; g->remove_vertex(distv(gen_v)); } }