Beispiel #1
0
void CPathEstimator::InitEstimator(const std::string& cacheFileName, const std::string& map)
{
	int numThreads_tmp = configHandler->Get("HardwareThreadCount", 0);
	size_t numThreads = ((numThreads_tmp < 0) ? 0 : numThreads_tmp);

	if (numThreads == 0) {
		#if (BOOST_VERSION >= 103500)
		numThreads = boost::thread::hardware_concurrency();
		#elif defined(USE_GML)
		numThreads = gmlCPUCount();
		#else
		numThreads = 1;
		#endif
	}

	if (threads.size() != numThreads) {
		threads.resize(numThreads);
		pathFinders.resize(numThreads);
	}
	pathFinders[0] = pathFinder;

	// Not much point in multithreading these...
	InitVertices();
	InitBlocks();

	PrintLoadMsg("Reading estimate path costs");

	if (!ReadFile(cacheFileName, map)) {
		char calcMsg[512];
		sprintf(calcMsg, "Analyzing map accessibility [%d]", BLOCK_SIZE);
		PrintLoadMsg(calcMsg);

		pathBarrier=new boost::barrier(numThreads);

		// Start threads if applicable
		for(size_t i=1; i<numThreads; ++i) {
			pathFinders[i] = new CPathFinder();
			threads[i] = new boost::thread(boost::bind(&CPathEstimator::CalcOffsetsAndPathCosts, this, i));
		}

		// Use the current thread as thread zero
		CalcOffsetsAndPathCosts(0);

		for(size_t i=1; i<numThreads; ++i) {
			threads[i]->join();
			delete threads[i];
			delete pathFinders[i];
		}

		delete pathBarrier;

		PrintLoadMsg("Writing path data file...");
		WriteFile(cacheFileName, map);
	}
}
// wrapper
void CPathEstimator::InitVerticesAndBlocks(int minVertex, int maxVertex, int minBlock, int maxBlock) {
	InitVertices(minVertex, maxVertex);
	InitBlocks(minBlock, maxBlock);
}