Advertisement
Guest User

Untitled

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