Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static const unsigned int ncores = 8;//std::thread::hardware_concurrency();
- auto doWork = [&](unsigned int part) -> void {
- std::uint32_t N = lhs.height()/ncores;
- std::uint32_t end = (part+1)*N;
- typename SA::Scalar partSum = 0.0;
- for (std::uint32_t i = part*N; i < end; i++){
- processRow(i, partSum);
- }
- std::lock_guard<std::mutex> guard(sumMutex);
- sum += partSum;
- };
- ADD_ELAPSED_TIME_AND_RESET_MARK( profiler, START);
- std::vector<std::thread> threads;
- for (unsigned int i=0; i<ncores; ++i) {
- threads.emplace_back( doWork, i );
- ADD_ELAPSED_TIME_AND_RESET_MARK( profiler, EMPLACE);
- }
- for (unsigned int i=0; i<ncores; ++i) {
- threads.at(i).join();
- ADD_ELAPSED_TIME_AND_RESET_MARK( profiler, JOIN);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement