fixes ticket 26 and another race condition/memory leak issue
This commit is contained in:
parent
68c210d184
commit
fb2a414839
@ -138,30 +138,13 @@ static void GetListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate&
|
|||||||
|
|
||||||
template<bool WriteAccess = false>
|
template<bool WriteAccess = false>
|
||||||
class NNGrid {
|
class NNGrid {
|
||||||
struct _ThreadData{
|
|
||||||
_ThreadData(const char * iif) {
|
|
||||||
stream.open(iif, std::ios::in | std::ios::binary);
|
|
||||||
}
|
|
||||||
~_ThreadData() {
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
ifstream stream;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef HashTable<unsigned, unsigned> ThreadLookupTable;
|
|
||||||
public:
|
public:
|
||||||
ThreadLookupTable threadLookup;
|
|
||||||
|
|
||||||
NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); if( WriteAccess) { entries = new stxxl::vector<GridEntry>(); }}
|
NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); if( WriteAccess) { entries = new stxxl::vector<GridEntry>(); }}
|
||||||
|
|
||||||
NNGrid(const char* rif, const char* iif, unsigned numberOfThreads = omp_get_num_procs()) {
|
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()) {
|
||||||
|
iif = _i;
|
||||||
ramIndexTable.resize((1024*1024), UINT_MAX);
|
ramIndexTable.resize((1024*1024), UINT_MAX);
|
||||||
// indexInFile.open(iif, std::ios::in | std::ios::binary);
|
|
||||||
ramInFile.open(rif, std::ios::in | std::ios::binary);
|
ramInFile.open(rif, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
for(int i = 0; i< omp_get_num_procs(); i++) {
|
|
||||||
indexFileStreams.push_back(new _ThreadData(iif));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~NNGrid() {
|
~NNGrid() {
|
||||||
@ -170,12 +153,6 @@ public:
|
|||||||
if (WriteAccess) {
|
if (WriteAccess) {
|
||||||
delete entries;
|
delete entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned i = 0; i< indexFileStreams.size(); i++) {
|
|
||||||
delete indexFileStreams[i];
|
|
||||||
}
|
|
||||||
threadLookup.EraseAll();
|
|
||||||
ramIndexTable.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenIndexFiles() {
|
void OpenIndexFiles() {
|
||||||
@ -526,21 +503,21 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_Edge>& result) {
|
void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_Edge>& result) {
|
||||||
unsigned threadID = threadLookup.Find(boost_thread_id_hash(boost::this_thread::get_id()));
|
// unsigned threadID = threadLookup.Find(boost_thread_id_hash(boost::this_thread::get_id()));
|
||||||
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
|
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
|
||||||
unsigned startIndexInFile = ramIndexTable[ramIndex];
|
unsigned startIndexInFile = ramIndexTable[ramIndex];
|
||||||
// ifstream indexInFile( indexFileStreams[threadID]->stream );
|
// ifstream indexInFile( indexFileStreams[threadID]->stream );
|
||||||
if(startIndexInFile == UINT_MAX){
|
if(startIndexInFile == UINT_MAX){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::ifstream localStream(iif, std::ios::in | std::ios::binary);
|
||||||
std::vector<unsigned> cellIndex;
|
std::vector<unsigned> cellIndex;
|
||||||
cellIndex.resize(32*32);
|
cellIndex.resize(32*32);
|
||||||
google::dense_hash_map< unsigned, unsigned > * cellMap = new google::dense_hash_map< unsigned, unsigned >(1024);
|
google::dense_hash_map< unsigned, unsigned > * cellMap = new google::dense_hash_map< unsigned, unsigned >(1024);
|
||||||
cellMap->set_empty_key(UINT_MAX);
|
cellMap->set_empty_key(UINT_MAX);
|
||||||
|
|
||||||
|
|
||||||
indexFileStreams[threadID]->stream.seekg(startIndexInFile);
|
localStream.seekg(startIndexInFile);
|
||||||
|
|
||||||
unsigned lineBase = ramIndex/1024;
|
unsigned lineBase = ramIndex/1024;
|
||||||
lineBase = lineBase*32*32768;
|
lineBase = lineBase*32*32768;
|
||||||
@ -561,7 +538,7 @@ private:
|
|||||||
unsigned numOfElementsInCell = 0;
|
unsigned numOfElementsInCell = 0;
|
||||||
for(int i = 0; i < 32*32; i++)
|
for(int i = 0; i < 32*32; i++)
|
||||||
{
|
{
|
||||||
indexFileStreams[threadID]->stream.read((char *)&cellIndex[i], sizeof(unsigned));
|
localStream.read((char *)&cellIndex[i], sizeof(unsigned));
|
||||||
numOfElementsInCell += cellIndex[i];
|
numOfElementsInCell += cellIndex[i];
|
||||||
}
|
}
|
||||||
assert(cellMap->find(fileIndex) != cellMap->end());
|
assert(cellMap->find(fileIndex) != cellMap->end());
|
||||||
@ -571,18 +548,18 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsigned position = cellIndex[cellMap->find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
|
unsigned position = cellIndex[cellMap->find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
|
||||||
indexFileStreams[threadID]->stream.seekg(position);
|
localStream.seekg(position);
|
||||||
unsigned numberOfEdgesInFileBucket = 0;
|
unsigned numberOfEdgesInFileBucket = 0;
|
||||||
NodeID start, target; int slat, slon, tlat, tlon;
|
NodeID start, target; int slat, slon, tlat, tlon;
|
||||||
do{
|
do{
|
||||||
indexFileStreams[threadID]->stream.read((char *)&(start), sizeof(NodeID));
|
localStream.read((char *)&(start), sizeof(NodeID));
|
||||||
if(start == UINT_MAX || indexFileStreams[threadID]->stream.eof())
|
if(localStream.eof() || start == UINT_MAX)
|
||||||
break;
|
break;
|
||||||
indexFileStreams[threadID]->stream.read((char *)&(target), sizeof(NodeID));
|
localStream.read((char *)&(target), sizeof(NodeID));
|
||||||
indexFileStreams[threadID]->stream.read((char *)&(slat), sizeof(int));
|
localStream.read((char *)&(slat), sizeof(int));
|
||||||
indexFileStreams[threadID]->stream.read((char *)&(slon), sizeof(int));
|
localStream.read((char *)&(slon), sizeof(int));
|
||||||
indexFileStreams[threadID]->stream.read((char *)&(tlat), sizeof(int));
|
localStream.read((char *)&(tlat), sizeof(int));
|
||||||
indexFileStreams[threadID]->stream.read((char *)&(tlon), sizeof(int));
|
localStream.read((char *)&(tlon), sizeof(int));
|
||||||
|
|
||||||
_Edge e(start, target);
|
_Edge e(start, target);
|
||||||
e.startCoord.lat = slat;
|
e.startCoord.lat = slat;
|
||||||
@ -593,7 +570,7 @@ private:
|
|||||||
result.push_back(e);
|
result.push_back(e);
|
||||||
numberOfEdgesInFileBucket++;
|
numberOfEdgesInFileBucket++;
|
||||||
} while(true);
|
} while(true);
|
||||||
|
localStream.close();
|
||||||
delete cellMap;
|
delete cellMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,9 +620,9 @@ private:
|
|||||||
|
|
||||||
ofstream indexOutFile;
|
ofstream indexOutFile;
|
||||||
ifstream ramInFile;
|
ifstream ramInFile;
|
||||||
std::vector < _ThreadData* > indexFileStreams;
|
|
||||||
stxxl::vector<GridEntry> * entries;
|
stxxl::vector<GridEntry> * entries;
|
||||||
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
|
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
|
||||||
|
const char * iif;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +71,6 @@ public:
|
|||||||
readOnlyGrid->FindNearestPointOnEdge(input, output);
|
readOnlyGrid->FindNearestPointOnEdge(input, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void RegisterThread(const unsigned k, const unsigned v) {
|
|
||||||
readOnlyGrid->threadLookup.Add(k, v);
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
vector<_Coordinate> * int2ExtNodeMap;
|
vector<_Coordinate> * int2ExtNodeMap;
|
||||||
ReadOnlyGrid * readOnlyGrid;
|
ReadOnlyGrid * readOnlyGrid;
|
||||||
|
@ -83,8 +83,8 @@ public:
|
|||||||
bool startReverse = false;
|
bool startReverse = false;
|
||||||
bool targetReverse = false;
|
bool targetReverse = false;
|
||||||
|
|
||||||
_Heap * _forwardHeap = new _Heap(nodeHelpDesk->getNumberOfNodes());
|
_Heap _forwardHeap(nodeHelpDesk->getNumberOfNodes());
|
||||||
_Heap * _backwardHeap = new _Heap(nodeHelpDesk->getNumberOfNodes());
|
_Heap _backwardHeap(nodeHelpDesk->getNumberOfNodes());
|
||||||
NodeID middle = ( NodeID ) 0;
|
NodeID middle = ( NodeID ) 0;
|
||||||
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
|
||||||
|
|
||||||
@ -102,8 +102,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(currentEdge == UINT_MAX){
|
if(currentEdge == UINT_MAX){
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,39 +126,33 @@ public:
|
|||||||
getNodeInfo(phantomNodes->startNode2, result);
|
getNodeInfo(phantomNodes->startNode2, result);
|
||||||
|
|
||||||
EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance;
|
EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance;
|
||||||
_forwardHeap->Insert(phantomNodes->startNode2, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode2);
|
_forwardHeap.Insert(phantomNodes->startNode2, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode2);
|
||||||
_backwardHeap->Insert(phantomNodes->startNode1, absDouble( w-w*phantomNodes->targetRatio), phantomNodes->startNode1);
|
_backwardHeap.Insert(phantomNodes->startNode1, absDouble( w-w*phantomNodes->targetRatio), phantomNodes->startNode1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if(phantomNodes->startNode1 != UINT_MAX)
|
} else if(phantomNodes->startNode1 != UINT_MAX) {
|
||||||
{
|
|
||||||
EdgeID edge = _graph->FindEdge( phantomNodes->startNode1, phantomNodes->startNode2);
|
EdgeID edge = _graph->FindEdge( phantomNodes->startNode1, phantomNodes->startNode2);
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
edge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 );
|
edge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 );
|
||||||
startReverse = true;
|
startReverse = true;
|
||||||
}
|
}
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
const EdgeData& ed = _graph->GetEdgeData(edge);
|
const EdgeData& ed = _graph->GetEdgeData(edge);
|
||||||
EdgeWeight w = ed.distance;
|
EdgeWeight w = ed.distance;
|
||||||
if( (ed.backward && !startReverse) || (ed.forward && startReverse) )
|
if( (ed.backward && !startReverse) || (ed.forward && startReverse) )
|
||||||
_forwardHeap->Insert(phantomNodes->startNode1, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode1);
|
_forwardHeap.Insert(phantomNodes->startNode1, absDouble( w*phantomNodes->startRatio), phantomNodes->startNode1);
|
||||||
if( (ed.backward && startReverse) || (ed.forward && !startReverse) )
|
if( (ed.backward && startReverse) || (ed.forward && !startReverse) )
|
||||||
_forwardHeap->Insert(phantomNodes->startNode2, absDouble(w-w*phantomNodes->startRatio), phantomNodes->startNode2);
|
_forwardHeap.Insert(phantomNodes->startNode2, absDouble(w-w*phantomNodes->startRatio), phantomNodes->startNode2);
|
||||||
}
|
}
|
||||||
if(phantomNodes->targetNode1 != UINT_MAX && !onSameEdgeReversed)
|
if(phantomNodes->targetNode1 != UINT_MAX && !onSameEdgeReversed) {
|
||||||
{
|
|
||||||
EdgeID edge = _graph->FindEdge( phantomNodes->targetNode1, phantomNodes->targetNode2);
|
EdgeID edge = _graph->FindEdge( phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
edge = _graph->FindEdge( phantomNodes->targetNode2, phantomNodes->targetNode1 );
|
edge = _graph->FindEdge( phantomNodes->targetNode2, phantomNodes->targetNode1 );
|
||||||
targetReverse = true;
|
targetReverse = true;
|
||||||
}
|
}
|
||||||
if(edge == UINT_MAX){
|
if(edge == UINT_MAX){
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,33 +160,30 @@ public:
|
|||||||
EdgeWeight w = ed.distance;
|
EdgeWeight w = ed.distance;
|
||||||
|
|
||||||
if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) )
|
if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) )
|
||||||
_backwardHeap->Insert(phantomNodes->targetNode2, absDouble( w*phantomNodes->targetRatio), phantomNodes->targetNode2);
|
_backwardHeap.Insert(phantomNodes->targetNode2, absDouble( w*phantomNodes->targetRatio), phantomNodes->targetNode2);
|
||||||
if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) )
|
if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) )
|
||||||
_backwardHeap->Insert(phantomNodes->targetNode1, absDouble(w-w*phantomNodes->startRatio), phantomNodes->targetNode1);
|
_backwardHeap.Insert(phantomNodes->targetNode1, absDouble(w-w*phantomNodes->startRatio), phantomNodes->targetNode1);
|
||||||
}
|
}
|
||||||
// double time = get_timestamp();
|
// double time = get_timestamp();
|
||||||
|
|
||||||
NodeID sourceHeapNode = 0;
|
NodeID sourceHeapNode = 0;
|
||||||
NodeID targetHeapNode = 0;
|
NodeID targetHeapNode = 0;
|
||||||
if(onSameEdgeReversed) {
|
if(onSameEdgeReversed) {
|
||||||
sourceHeapNode = _forwardHeap->Min();
|
sourceHeapNode = _forwardHeap.Min();
|
||||||
targetHeapNode = _backwardHeap->Min();
|
targetHeapNode = _backwardHeap.Min();
|
||||||
}
|
}
|
||||||
while(_forwardHeap->Size() + _backwardHeap->Size() > 0)
|
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
|
||||||
{
|
if ( _forwardHeap.Size() > 0 ) {
|
||||||
if ( _forwardHeap->Size() > 0 ) {
|
_RoutingStep( &_forwardHeap, &_backwardHeap, true, &middle, &_upperbound );
|
||||||
_RoutingStep( _forwardHeap, _backwardHeap, true, &middle, &_upperbound );
|
|
||||||
}
|
}
|
||||||
if ( _backwardHeap->Size() > 0 ) {
|
if ( _backwardHeap.Size() > 0 ) {
|
||||||
_RoutingStep( _backwardHeap, _forwardHeap, false, &middle, &_upperbound );
|
_RoutingStep( &_backwardHeap, &_forwardHeap, false, &middle, &_upperbound );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// std::cout << "[debug] computing distance took " << get_timestamp() - time << std::endl;
|
// std::cout << "[debug] computing distance took " << get_timestamp() - time << std::endl;
|
||||||
// time = get_timestamp();
|
// time = get_timestamp();
|
||||||
|
|
||||||
if ( _upperbound == std::numeric_limits< unsigned int >::max() || onSameEdge ) {
|
if ( _upperbound == std::numeric_limits< unsigned int >::max() || onSameEdge ) {
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +191,7 @@ public:
|
|||||||
deque< NodeID > packedPath;
|
deque< NodeID > packedPath;
|
||||||
|
|
||||||
while ( onSameEdgeReversed ? pathNode != sourceHeapNode : pathNode != phantomNodes->startNode1 && pathNode != phantomNodes->startNode2 ) {
|
while ( onSameEdgeReversed ? pathNode != sourceHeapNode : pathNode != phantomNodes->startNode1 && pathNode != phantomNodes->startNode2 ) {
|
||||||
pathNode = _forwardHeap->GetData( pathNode ).parent;
|
pathNode = _forwardHeap.GetData( pathNode ).parent;
|
||||||
packedPath.push_front( pathNode );
|
packedPath.push_front( pathNode );
|
||||||
}
|
}
|
||||||
// NodeID realStart = pathNode;
|
// NodeID realStart = pathNode;
|
||||||
@ -210,19 +199,16 @@ public:
|
|||||||
pathNode = middle;
|
pathNode = middle;
|
||||||
|
|
||||||
while ( onSameEdgeReversed ? pathNode != targetHeapNode : pathNode != phantomNodes->targetNode2 && pathNode != phantomNodes->targetNode1 ){
|
while ( onSameEdgeReversed ? pathNode != targetHeapNode : pathNode != phantomNodes->targetNode2 && pathNode != phantomNodes->targetNode1 ){
|
||||||
pathNode = _backwardHeap->GetData( pathNode ).parent;
|
pathNode = _backwardHeap.GetData( pathNode ).parent;
|
||||||
packedPath.push_back( pathNode );
|
packedPath.push_back( pathNode );
|
||||||
}
|
}
|
||||||
|
|
||||||
path->push_back( _PathData(packedPath[0]) );
|
path->push_back( _PathData(packedPath[0]) );
|
||||||
for(deque<NodeID>::size_type i = 0; i < packedPath.size()-1; i++)
|
for(deque<NodeID>::size_type i = 0; i < packedPath.size()-1; i++) {
|
||||||
{
|
|
||||||
_UnpackEdge(packedPath[i], packedPath[i+1], path);
|
_UnpackEdge(packedPath[i], packedPath[i+1], path);
|
||||||
}
|
}
|
||||||
|
|
||||||
packedPath.clear();
|
packedPath.clear();
|
||||||
delete _forwardHeap;
|
|
||||||
delete _backwardHeap;
|
|
||||||
// std::cout << "[debug] unpacking path took " << get_timestamp() - time << std::endl;
|
// std::cout << "[debug] unpacking path took " << get_timestamp() - time << std::endl;
|
||||||
|
|
||||||
return _upperbound/10;
|
return _upperbound/10;
|
||||||
|
Loading…
Reference in New Issue
Block a user