Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 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 <boost/format.hpp>
  8.  
  9. #include <cstddef>
  10. #include <list>
  11. #include <mutex>
  12. #include <set>
  13. #include <vector>
  14.  
  15. //#include "../../common.h"
  16.  
  17. int total_tasks;
  18.  
  19. void task_worker(std::size_t id)
  20. {
  21.     printf("task: %d\n", id);
  22. }
  23.  
  24. HPX_PLAIN_ACTION(task_worker, task_worker_action);
  25.  
  26. hpx::future<void> task_foreman()
  27. {
  28.     std::size_t id = 0;
  29.  
  30.     hpx::naming::id_type const here = hpx::find_here();
  31.  
  32.     std::vector<hpx::lcos::future<void> > futures;
  33.     futures.reserve(total_tasks);
  34.  
  35.     typedef task_worker_action action_type;
  36.     futures.push_back(hpx::async<action_type>(here, id) );
  37.     for(id = 1; id < total_tasks; id++) {
  38.         typedef task_worker_action action_type;
  39.         futures.push_back(futures[id-1].then( hpx::async<action_type>(here, id) ));
  40.     }  
  41.  
  42.     return hpx::when_all(futures);
  43. }
  44.  
  45. HPX_PLAIN_ACTION(task_foreman, task_foreman_action);
  46.  
  47. int main(int argc, char **argv)
  48. {
  49.     total_tasks = 4;
  50.  
  51.     std::vector<hpx::id_type> localities = hpx::find_all_localities();
  52.  
  53.     std::vector<hpx::future<void> > futures;
  54.     futures.reserve(localities.size());
  55.  
  56.     for (hpx::id_type const& node : localities)
  57.     {  
  58.         typedef task_foreman_action action_type;
  59.         futures.push_back(hpx::async<action_type>(node));
  60.     }  
  61.  
  62.  
  63.     hpx::wait_all(futures);
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement