Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1.       static const unsigned int ncores = 8;//std::thread::hardware_concurrency();
  2.  
  3.       auto doWork = [&](unsigned int part) -> void {
  4.         std::uint32_t N = lhs.height()/ncores;
  5.         std::uint32_t end = (part+1)*N;
  6.         typename SA::Scalar partSum = 0.0;
  7.         for (std::uint32_t i = part*N; i < end; i++){
  8.           processRow(i, partSum);
  9.         }
  10.         std::lock_guard<std::mutex> guard(sumMutex);
  11.         sum += partSum;
  12.       };
  13.  
  14.       ADD_ELAPSED_TIME_AND_RESET_MARK( profiler, START);
  15.       std::vector<std::thread> threads;
  16.       for (unsigned int i=0; i<ncores; ++i) {
  17.         threads.emplace_back( doWork, i );
  18.         ADD_ELAPSED_TIME_AND_RESET_MARK( profiler, EMPLACE);
  19.       }
  20.       for (unsigned int i=0; i<ncores; ++i) {
  21.         threads.at(i).join();
  22.         ADD_ELAPSED_TIME_AND_RESET_MARK( profiler, JOIN);
  23.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement