diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h index c5cbdcecb..12961fc94 100644 --- a/Contractor/ContractionCleanup.h +++ b/Contractor/ContractionCleanup.h @@ -42,8 +42,11 @@ private: parent = p; } }; +#ifdef _MANYCORES + typedef BinaryHeap< NodeID, NodeID, int, _HeapData, DenseStorage > _Heap; +#else typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap; - +#endif struct _ThreadData { _Heap* _heapForward; _Heap* _heapBackward; @@ -99,11 +102,8 @@ public: } void Run() { - double time = _Timestamp(); - RemoveUselessShortcuts(); - time = _Timestamp() - time; cout << "Postprocessing Time: " << time << " s" << endl; } @@ -159,7 +159,11 @@ private: #else sort( _graph.begin(), _graph.end(), Edge::CompareBySource ); #endif + try { _firstEdge.resize( _numNodes + 1 ); + } catch(...) { + cerr << "Not enough RAM on machine" << endl; + } _firstEdge[0] = 0; for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) { while ( _graph[i].source != node ) diff --git a/Contractor/GraphLoader.h b/Contractor/GraphLoader.h index 754ec8550..235a8352a 100644 --- a/Contractor/GraphLoader.h +++ b/Contractor/GraphLoader.h @@ -96,6 +96,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector& edgeList, vect edgeList.push_back(inputEdge); } ext2IntNodeMap.clear(); + vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. cout << "ok" << endl; return n; } diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 97f2e26cb..9246989ac 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -338,8 +338,8 @@ public: private: unsigned FillCell(std::vector& entriesWithSameRAMIndex, unsigned fileOffset ) { - vector tmpBuffer; - tmpBuffer.resize(32*32*4096,0); + vector * tmpBuffer = new vector(); + tmpBuffer->resize(32*32*4096,0); unsigned indexIntoTmpBuffer = 0; unsigned numberOfWrittenBytes = 0; assert(indexOutFile.is_open()); @@ -417,16 +417,18 @@ private: //write contents of tmpbuffer to disk for(int i = 0; i < indexIntoTmpBuffer; i++) { - indexOutFile.write(&tmpBuffer[i], sizeof(char)); + indexOutFile.write(&(tmpBuffer->at(i)), sizeof(char)); numberOfWrittenBytes += sizeof(char); } + delete tmpBuffer; delete cellMap; return numberOfWrittenBytes; } - unsigned FlushEntriesWithSameFileIndexToBuffer(const std::vector &vectorWithSameFileIndex, vector& tmpBuffer, const unsigned index) + unsigned FlushEntriesWithSameFileIndexToBuffer(const std::vector &vectorWithSameFileIndex, vector * tmpBuffer, const unsigned index) { + tmpBuffer->resize(tmpBuffer->size()+(sizeof(NodeID)+sizeof(NodeID)+4*sizeof(int)+sizeof(unsigned))*vectorWithSameFileIndex.size() ); unsigned counter = 0; unsigned max = UINT_MAX; @@ -441,44 +443,44 @@ private: char * start = (char *)&et->edge.start; for(int i = 0; i < sizeof(NodeID); i++) { - tmpBuffer[index+counter] = start[i]; + tmpBuffer->at(index+counter) = start[i]; counter++; } char * target = (char *)&et->edge.target; for(int i = 0; i < sizeof(NodeID); i++) { - tmpBuffer[index+counter] = target[i]; + tmpBuffer->at(index+counter) = target[i]; counter++; } char * slat = (char *) &(et->edge.startCoord.lat); for(int i = 0; i < sizeof(int); i++) { - tmpBuffer[index+counter] = slat[i]; + tmpBuffer->at(index+counter) = slat[i]; counter++; } char * slon = (char *) &(et->edge.startCoord.lon); for(int i = 0; i < sizeof(int); i++) { - tmpBuffer[index+counter] = slon[i]; + tmpBuffer->at(index+counter) = slon[i]; counter++; } char * tlat = (char *) &(et->edge.targetCoord.lat); for(int i = 0; i < sizeof(int); i++) { - tmpBuffer[index+counter] = tlat[i]; + tmpBuffer->at(index+counter) = tlat[i]; counter++; } char * tlon = (char *) &(et->edge.targetCoord.lon); for(int i = 0; i < sizeof(int); i++) { - tmpBuffer[index+counter] = tlon[i]; + tmpBuffer->at(index+counter) = tlon[i]; counter++; } } char * umax = (char *) &max; for(int i = 0; i < sizeof(unsigned); i++) { - tmpBuffer[index+counter] = umax[i]; + tmpBuffer->at(index+counter) = umax[i]; counter++; } return counter; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 16168dadd..cca624c16 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -93,9 +93,9 @@ int main (int argc, char *argv[]) Percent p(edgeList.size()); for(NodeID i = 0; i < edgeList.size(); i++) { + p.printIncrement(); if(!edgeList[i].isLocatable()) continue; - p.printIncrement(); int slat = int2ExtNodeMap->at(edgeList[i].source()).lat; int slon = int2ExtNodeMap->at(edgeList[i].source()).lon; int tlat = int2ExtNodeMap->at(edgeList[i].target()).lat; @@ -123,9 +123,12 @@ int main (int argc, char *argv[]) } mapOutFile.close(); int2ExtNodeMap->clear(); + delete int2ExtNodeMap; + cout << "initializing contractor ..." << flush; Contractor* contractor = new Contractor( n, edgeList ); - + vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. + cout << "ok" << endl; contractor->Run(); cout << "checking data sanity ..." << flush; @@ -143,8 +146,11 @@ int main (int argc, char *argv[]) ofstream edgeOutFile(edgeOut, ios::binary); //Serializing the edge list. + cout << "Serializing edges " << flush; + p.reinit(cleanedEdgeList.size()); for(std::vector< GridEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++) { + p.printIncrement(); int distance= it->data.distance; assert(distance > 0); bool shortcut= it->data.shortcut; @@ -168,5 +174,4 @@ int main (int argc, char *argv[]) delete cleanup; delete contractor; - delete int2ExtNodeMap; } diff --git a/routed.cpp b/routed.cpp index a6d31e6f8..6fa96b3fa 100644 --- a/routed.cpp +++ b/routed.cpp @@ -64,7 +64,7 @@ int main (int argc, char *argv[]) time = get_timestamp(); cout << "deserializing edge data from " << argv[1] << " ..." << flush; - std::vector< GridEdge> * edgelist = new std::vector< GridEdge>(); + std::vector< GridEdge> * edgeList = new std::vector< GridEdge>(); while(!in.eof()) { GridEdge g; @@ -89,7 +89,7 @@ int main (int argc, char *argv[]) e.backward = backward; e.distance = distance; e.forward = forward; e.middle = middle; e.shortcut = shortcut; g.data = e; g.source = source; g.target = target; - edgelist->push_back(g); + edgeList->push_back(g); } in.close(); @@ -99,8 +99,8 @@ int main (int argc, char *argv[]) nodeInfoHelper->initNNGrid(in2); cout << "in " << get_timestamp() - time << "s" << endl; // time = get_timestamp(); - StaticGraph * graph = new StaticGraph(nodeInfoHelper->getNumberOfNodes()-1, *edgelist); - delete edgelist; + StaticGraph * graph = new StaticGraph(nodeInfoHelper->getNumberOfNodes()-1, *edgeList); + delete edgeList; // cout << "checking data sanity ..." << flush; // NodeID numberOfNodes = graph->GetNumberOfNodes(); // for ( NodeID node = 0; node < numberOfNodes; ++node ) {