Guest User

Untitled

a guest
Oct 30th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <hpx/hpx_init.hpp>
  4. #include <hpx/util/high_resolution_timer.hpp>
  5. #include <hpx/runtime/get_worker_thread_num.hpp>
  6. #include <hpx/runtime/get_os_thread_count.hpp>
  7. #include <hpx/parallel/algorithms/for_each.hpp>
  8. #include <hpx/parallel/executors/static_chunk_size.hpp>
  9. #include <hpx/parallel/executors/dynamic_chunk_size.hpp>
  10. #include <boost/range/irange.hpp>
  11.  
  12. int get_time() {
  13.     return hpx::util::high_resolution_clock::now() * 1e-9;
  14. }
  15.  
  16. int hpx_main(int argc, char *argv[]) {
  17.  
  18.     std::vector<std::vector<int>> Threads(hpx::get_os_thread_count(), std::vector<int>());
  19.     std::cout << "Working on " << hpx::get_os_thread_count() << " threads " <<std::endl;
  20.  
  21.     auto range = boost::irange(0, 10);
  22.     hpx::parallel::for_each(hpx::parallel::execution::par.with(hpx::parallel::execution::static_chunk_size(3)), range.begin(), range.end(), [&](int i){
  23.     Threads[hpx::get_worker_thread_num()].push_back(i);});
  24.  
  25.     std::cout << "         Iterations    " << std::endl;
  26.     for (int i(0); i < hpx::get_os_thread_count(); i++) {
  27.         std::cout << "Thread " << i << " : ";
  28.         for(int j(0); j < Threads[i].size(); j++) {
  29.             std::cout << Threads[i][j] << " ";
  30.         }
  31.         std::cout << "\n";
  32.     }
  33.  
  34.  
  35.     return hpx::finalize();
  36. }
  37.  
  38. int main(int argc, char *argv[]){
  39.     return hpx::init(argc, argv);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment