Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <hpx/hpx_main.hpp>
  2. #include <hpx/include/lcos.hpp>
  3. #include <hpx/include/actions.hpp>
  4. #include <hpx/include/components.hpp>
  5. #include <hpx/include/iostreams.hpp>
  6.  
  7. #include <cstddef>
  8. #include <list>
  9. #include <mutex>
  10. #include <set>
  11. #include <vector>
  12.  
  13. std::size_t total_tasks = 100000;
  14. std::size_t n = 1000;
  15.  
  16. void ep_worker()
  17. {
  18.     std::vector<double> a(n);
  19.     std::vector<double> b(n);
  20.     std::vector<double> c(n);
  21.  
  22.     /* fill it with random */
  23.     for(int i = 0; i < n; i++ ) {
  24.         a[i] = rand() % 10;
  25.         b[i] = rand() % 10;
  26.     }
  27.  
  28.     for(int i = 0; i < n; i++ ) {
  29.         c[i] = a[i] * b[i];
  30.     }
  31. }
  32.  
  33. hpx::future<void> ep_foreman()
  34. {
  35.     std::vector<hpx::future<std::size_t> > futures;
  36.     futures.reserve(total_tasks);
  37.  
  38.     for(std::size_t i = 0; i != total_tasks; ++i)
  39.         futures.push_back(hpx::async(&ep_worker));
  40.  
  41.     return hpx::when_all(futures);
  42. }
  43.  
  44. HPX_PLAIN_ACTION(ep_foreman, ep_foreman_action);
  45.  
  46. int main(int argc, char **argv)
  47. {
  48.     cores = 1;
  49.     n = 1000;
  50.     total_tasks = 1000;
  51.  
  52.     process_input(&argc, &argv, 3);
  53.  
  54.     std::vector<hpx::id_type> localities = hpx::find_all_localities();
  55.  
  56.     std::vector<hpx::future<void> > futures;
  57.     futures.reserve(localities.size());
  58.  
  59.     for (hpx::id_type const& node : localities)
  60.     {
  61.         typedef ep_foreman_action action_type;
  62.         futures.push_back(hpx::async<action_type>(node));
  63.     }
  64.  
  65.     START_TIMER;
  66.  
  67.     hpx::wait_all(futures);
  68.  
  69.     /* stop timer */
  70.     STOP_TIMER_AND_PRINT(("Cores: %d Tasks: %d\tn: %d\n", cores, total_tasks, n));
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement