void CPathEstimator::InitEstimator(const std::string& name) { int numThreads = configHandler.GetInt("HardwareThreadCount", 0); #if 0 // FIXME mantis #1033 #if (BOOST_VERSION >= 103500) if (numThreads == 0) numThreads = boost::thread::hardware_concurrency(); #else # ifdef USE_GML if (numThreads == 0) numThreads = GML_CPU_COUNT; # endif #endif #else //if 0 numThreads = 1; #endif if (numThreads > 1) { // spawn the threads for InitVerticesAndBlocks() SpawnThreads(numThreads, 0); JoinThreads(numThreads, 0); char loadMsg[512]; sprintf(loadMsg, "Reading estimate path costs (%d threads)", numThreads); PrintLoadMsg(loadMsg); if (!ReadFile(name)) { char calcMsg[512]; sprintf(calcMsg, "Analyzing map accessibility [%d] (%d threads)", BLOCK_SIZE, numThreads); PrintLoadMsg(calcMsg); // re-spawn the threads for CalculateBlockOffsets() SpawnThreads(numThreads, 1); JoinThreads(numThreads, 1); // re-spawn the threads for EstimatePathCosts() SpawnThreads(numThreads, 2); JoinThreads(numThreads, 2); WriteFile(name); } } else { // no threading InitVerticesAndBlocks(0, nbrOfVertices, 0, nbrOfBlocks); PrintLoadMsg("Reading estimate path costs (1 thread)"); if (!ReadFile(name)) { char calcMsg[512]; sprintf(calcMsg, "Analyzing map accessibility [%d] (1 thread)", BLOCK_SIZE); PrintLoadMsg(calcMsg); CalcOffsetsAndPathCosts(0, nbrOfBlocks); WriteFile(name); } } }
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); } }