Grid input streams now implemented as thread local objects.
This commit is contained in:
parent
8d008f9dcc
commit
17a5b7a363
@ -147,17 +147,19 @@ static void GetListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate&
|
|||||||
GetIndicesByBresenhamsAlgorithm(x1*32768, y1*32768, x2*32768, y2*32768, indexList);
|
GetIndicesByBresenhamsAlgorithm(x1*32768, y1*32768, x2*32768, y2*32768, indexList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boost::thread_specific_ptr<std::ifstream> localStream;
|
||||||
|
|
||||||
template<bool WriteAccess = false>
|
template<bool WriteAccess = false>
|
||||||
class NNGrid {
|
class NNGrid {
|
||||||
public:
|
public:
|
||||||
NNGrid() : cellCache(500), fileCache(500) {
|
NNGrid() /*: cellCache(500), fileCache(500)*/ {
|
||||||
ramIndexTable.resize((1024*1024), UINT_MAX);
|
ramIndexTable.resize((1024*1024), UINT_MAX);
|
||||||
if( WriteAccess) {
|
if( WriteAccess) {
|
||||||
entries = new stxxl::vector<GridEntry>();
|
entries = new stxxl::vector<GridEntry>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()): cellCache(500), fileCache(500) {
|
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()) /*: cellCache(500), fileCache(500) */{
|
||||||
if(WriteAccess) {
|
if(WriteAccess) {
|
||||||
ERR("Not available in Write mode");
|
ERR("Not available in Write mode");
|
||||||
}
|
}
|
||||||
@ -173,6 +175,9 @@ public:
|
|||||||
if (WriteAccess) {
|
if (WriteAccess) {
|
||||||
delete entries;
|
delete entries;
|
||||||
}
|
}
|
||||||
|
if(localStream.get() && localStream->is_open()) {
|
||||||
|
localStream->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenIndexFiles() {
|
void OpenIndexFiles() {
|
||||||
@ -518,6 +523,7 @@ private:
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
vectorWithSameFileIndex.clear();
|
vectorWithSameFileIndex.clear();
|
||||||
|
std::vector<GridEntry>().swap(vectorWithSameFileIndex);
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,29 +551,25 @@ private:
|
|||||||
cellMap.insert(std::make_pair(fileIndex, cellIndex));
|
cellMap.insert(std::make_pair(fileIndex, cellIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
if(!localStream.get() || !localStream->is_open()) {
|
||||||
std::ifstream localStream(iif.c_str(), std::ios::in | std::ios::binary);
|
localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary));
|
||||||
localStream.seekg(startIndexInFile);
|
}
|
||||||
localStream.read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
|
localStream->seekg(startIndexInFile);
|
||||||
localStream.close();
|
localStream->read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
|
||||||
assert(cellMap.find(fileIndex) != cellMap.end());
|
assert(cellMap.find(fileIndex) != cellMap.end());
|
||||||
if(cellIndex[cellMap.find(fileIndex)->second] == UINT_MAX) {
|
if(cellIndex[cellMap.find(fileIndex)->second] == UINT_MAX) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const unsigned position = cellIndex[cellMap.find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
|
const unsigned position = cellIndex[cellMap.find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
|
||||||
|
|
||||||
std::ifstream localStream(iif.c_str(), std::ios::in | std::ios::binary);
|
localStream->seekg(position);
|
||||||
localStream.seekg(position);
|
|
||||||
_GridEdge gridEdge;
|
_GridEdge gridEdge;
|
||||||
do {
|
do {
|
||||||
localStream.read((char *)&(gridEdge), sizeof(_GridEdge));
|
localStream->read((char *)&(gridEdge), sizeof(_GridEdge));
|
||||||
if(localStream.eof() || gridEdge.edgeBasedNode == UINT_MAX)
|
if(localStream->eof() || gridEdge.edgeBasedNode == UINT_MAX)
|
||||||
break;
|
break;
|
||||||
result.push_back(gridEdge);
|
result.push_back(gridEdge);
|
||||||
} while(true);
|
} while(true);
|
||||||
localStream.close();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddEdge(_GridEdge edge) {
|
void AddEdge(_GridEdge edge) {
|
||||||
@ -622,8 +624,8 @@ private:
|
|||||||
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
|
||||||
std::string iif;
|
std::string iif;
|
||||||
LRUCache<int,std::vector<unsigned> > cellCache;
|
// LRUCache<int,std::vector<unsigned> > cellCache;
|
||||||
LRUCache<int,std::vector<_Edge> > fileCache;
|
// LRUCache<int,std::vector<_Edge> > fileCache;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user