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); } } }
/* RunTest This function runs a particular test for a number of times and reports the result. Parameters func A function with the test str A string with the test name Return Value None. This function prints the result */ void RunTest( void * ( * func)( void * ), char * str ) { // ------------------ Local Variables -------------------- int testnum; int passedtests; double timesum; pthread_t *threads; ThreadParameters_t *threadparameters; // ------------------- Initialization ------------------- passedtests = 0; timesum = 0; printf( "Now running [%s]\n", str ); // ------------------- Run Tests ------------------------ for ( testnum = 0; testnum < REPEATTESTS; testnum++ ) { my_mutex_init( &gMutex ); my_barrier_init( &gBarrier, gP ); CreateThreads( &threads, gP, func, &threadparameters ); JoinThreads( &threads, gP, &threadparameters ); my_mutex_destroy( &gMutex ); my_barrier_destroy( &gBarrier ); timesum += gElapsedTime; if ( gCorrectTest ) { passedtests++; printf( "+" ); fflush( stdout ); } else { printf( "-" ); fflush( stdout ); } } timesum /= REPEATTESTS; // ------------------- Print Outcome --------------------- printf( "\nTests passed: %d of %d. Average Time = %f (sec)\n", passedtests, REPEATTESTS, timesum ); }
void CThread::StopThreads() { AsyncStopThreads(); JoinThreads(); }