From c1c98b16f68e3169fd2a9914f6c6b94b54a74384 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Thu, 23 Apr 2015 13:40:41 -0700 Subject: [PATCH] Added version with broken threads. Computation is correct, but threads do not fire up --- arangod/V8Server/V8Traverser.cpp | 57 +++++++++++++++++++++++++++++--- lib/Basics/Traverser.cpp | 23 +++++++++---- lib/Basics/Traverser.h | 7 ++-- 3 files changed, 74 insertions(+), 13 deletions(-) diff --git a/arangod/V8Server/V8Traverser.cpp b/arangod/V8Server/V8Traverser.cpp index e00888cd77..51604a5621 100644 --- a/arangod/V8Server/V8Traverser.cpp +++ b/arangod/V8Server/V8Traverser.cpp @@ -55,6 +55,8 @@ class SimpleEdgeExpander { CollectionNameResolver const* resolver; bool usesDist; + string dirung; + public: Traverser::VertexId extractFromId(TRI_doc_mptr_copy_t ptr) { @@ -85,6 +87,7 @@ class SimpleEdgeExpander { Traverser::Direction dir, vector& result ) { + cout << dirung << endl; std::vector edges; // Process Vertex Id! size_t split; @@ -105,11 +108,12 @@ class SimpleEdgeExpander { throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } auto collectionCId = col->_cid; - if (dir == Traverser::FORWARD) { - edges = TRI_LookupEdgesDocumentCollection(edgeCollection, forwardDirection, collectionCId, buffer); - } else { - edges = TRI_LookupEdgesDocumentCollection(edgeCollection, backwardDirection, collectionCId, buffer); + edges = TRI_LookupEdgesDocumentCollection(edgeCollection, direction, collectionCId, buffer); + + if (direction == 1) { + cout << edges.size() << endl; } + std::unordered_map candidates; Traverser::VertexId from; Traverser::VertexId to; @@ -160,9 +164,16 @@ class SimpleEdgeExpander { SimpleEdgeExpander( TRI_edge_direction_e edgeDirection, TRI_document_collection_t* edgeCollection, +<<<<<<< HEAD CollectionNameResolver const* resolver +======= + string edgeCollectionName, + CollectionNameResolver const resolver, + string dirung +>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up ) : edgeCollection(edgeCollection), +<<<<<<< HEAD resolver(resolver) { usesDist = false; @@ -181,6 +192,21 @@ class SimpleEdgeExpander { static pathToV8(v8::Isolate* isolate, Traverser::Path p) { v8::Handle result; +======= + resolver(resolver), + usesDist(false), + dirung(dirung) + { + cout << direction << endl; + edgeIdPrefix = edgeCollectionName + "/"; + }; +}; + +static v8::Handle pathIdsToV8(v8::Isolate* isolate, Traverser::Path& p) { + v8::EscapableHandleScope scope(isolate); + TRI_GET_GLOBALS(); + v8::Handle result = v8::Object::New(isolate); +>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up uint32_t const vn = static_cast(p.vertices.size()); v8::Handle vertices = v8::Array::New(isolate, static_cast(vn)); @@ -196,7 +222,12 @@ static pathToV8(v8::Isolate* isolate, Traverser::Path p) for (size_t j = 0; j < en; ++j) { edges->Set(static_cast(j), TRI_V8_ASCII_STRING(p.edges[j])); } +<<<<<<< HEAD result->Set("edges", edges); +======= + result->Set(TRI_V8_STRING("edges"), edges); + result->Set(TRI_V8_STRING("distance"), v8::Number::New(isolate, p.weight)); +>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up return result; }; @@ -316,8 +347,26 @@ void TRI_RunDijkstraSearch (const v8::FunctionCallbackInfo& args) { TRI_V8_THROW_EXCEPTION_MEMORY(); } +<<<<<<< HEAD v8::Handle result; v8::Handle documents; +======= + TRI_document_collection_t* ecol = trx.trxCollection(col->_cid)->_collection->_collection; + CollectionNameResolver resolver1(vocbase); + CollectionNameResolver resolver2(vocbase); + SimpleEdgeExpander forwardExpander(TRI_EDGE_OUT, ecol, edgeCollectionName, resolver1, "A"); + SimpleEdgeExpander backwardExpander(TRI_EDGE_IN, ecol, edgeCollectionName, resolver2, "B"); + + Traverser traverser(forwardExpander, backwardExpander); + unique_ptr path(traverser.ShortestPath(startVertex, targetVertex)); + if (path.get() == nullptr) { + res = trx.finish(res); + v8::EscapableHandleScope scope(isolate); + TRI_V8_RETURN(scope.Escape(v8::Object::New(isolate))); + } + auto result = pathIdsToV8(isolate, *path); + res = trx.finish(res); +>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up // This is how to get the data out of the collections! // Vertices diff --git a/lib/Basics/Traverser.cpp b/lib/Basics/Traverser.cpp index 0da777231e..2a234761e5 100644 --- a/lib/Basics/Traverser.cpp +++ b/lib/Basics/Traverser.cpp @@ -90,11 +90,16 @@ void Traverser::lookupPeer (ThreadInfo& info, //////////////////////////////////////////////////////////////////////////////// void Traverser::searchFromVertex ( - ThreadInfo myInfo, - ThreadInfo peerInfo, + ThreadInfo* myInfo_p, + ThreadInfo* peerInfo_p, VertexId start, - ExpanderFunction expander + ExpanderFunction expander, + string id ) { + ThreadInfo& myInfo(*myInfo_p); + ThreadInfo& peerInfo(*peerInfo_p); + + cout << id << ": inserting " << start << endl; insertNeighbor(myInfo, start, "", "", 0); auto nextVertexIt = myInfo.queue.begin(); std::vector neighbors; @@ -103,9 +108,12 @@ void Traverser::searchFromVertex ( // there still is a vertex on the stack. while (!bingo && nextVertexIt != myInfo.queue.end()) { auto nextVertex = *nextVertexIt; + cout << id << ": next " << nextVertex.vertex << endl; myInfo.queue.erase(nextVertexIt); + neighbors.clear(); expander(nextVertex.vertex, neighbors); - for (auto neighbor : neighbors) { + for (auto& neighbor : neighbors) { + cout << id << ": neighbor " << neighbor.neighbor << endl; insertNeighbor(myInfo, neighbor.neighbor, nextVertex.vertex, neighbor.edge, nextVertex.weight + neighbor.weight); } @@ -115,6 +123,7 @@ void Traverser::searchFromVertex ( auto nextVertexLookup = myInfo.lookup.find(nextVertex.vertex); TRI_ASSERT(nextVertexLookup != myInfo.lookup.end()); + cout << id << ": done " << nextVertexLookup->first << endl; nextVertexLookup->second.done = true; myInfo.mutex.unlock(); @@ -145,12 +154,14 @@ Traverser::Path* Traverser::ShortestPath (VertexId const& start, ThreadInfo backwardInfo(_backwardLookup, _backwardQueue, _backwardMutex); std::thread forwardSearcher(&Traverser::searchFromVertex, - this, forwardInfo, backwardInfo, start, forwardExpander); + this, &forwardInfo, &backwardInfo, start, forwardExpander, "X"); std::thread backwardSearcher(&Traverser::searchFromVertex, - this, backwardInfo, forwardInfo, target, backwardExpander); + this, &backwardInfo, &forwardInfo, target, backwardExpander, "Y"); forwardSearcher.join(); backwardSearcher.join(); + cout << forwardInfo.lookup.size() << backwardInfo.lookup.size() << endl; + if (!bingo) { return nullptr; } diff --git a/lib/Basics/Traverser.h b/lib/Basics/Traverser.h index 57cc6d71e4..e144e5670d 100644 --- a/lib/Basics/Traverser.h +++ b/lib/Basics/Traverser.h @@ -574,10 +574,11 @@ namespace triagens { VertexId& neighbor, EdgeWeight& weight ); - void searchFromVertex ( ThreadInfo myInfo, - ThreadInfo peerInfo, + void searchFromVertex ( ThreadInfo* myInfo, + ThreadInfo* peerInfo, VertexId start, - ExpanderFunction expander + ExpanderFunction expander, + std::string id ); }; }