Advertisement
satacker

Untitled

Sep 13th, 2023
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.27 KB | None | 0 0
  1. diff --git a/library/include/chplx/begin.hpp b/library/include/chplx/begin.hpp
  2. index 95ec4a5a..456b50cc 100644
  3. --- a/library/include/chplx/begin.hpp
  4. +++ b/library/include/chplx/begin.hpp
  5. @@ -20,20 +20,20 @@
  6.  namespace chplx {
  7.  
  8.      template <typename F, typename... Args>
  9. -    void begin(hpx::source_location const& location, F&& f, Args&&... args)
  10. +        requires(!std::is_same_v<std::decay_t<F>, hpx::source_location>)
  11. +    void begin(F&& f, Args&&... args)
  12.      {
  13. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  14.          hpx::parallel::execution::post(hpx::execution::par.executor(),
  15. +            std::forward<F>(f),
  16. +            detail::task_intent<std::decay_t<Args>>::call(
  17. +                std::forward<Args>(args))...);
  18. +#else
  19. +        px::parallel::execution::post(hpx::execution::par.executor(),
  20.              hpx::annotated_function(
  21.                  std::forward<F>(f), detail::generate_annotation(location)),
  22.              detail::task_intent<std::decay_t<Args>>::call(
  23.                  std::forward<Args>(args))...);
  24. -    }
  25. -
  26. -    template <typename F, typename... Args>
  27. -        requires(!std::is_same_v<std::decay_t<F>, hpx::source_location>)
  28. -    void begin(F&& f, Args&&... args)
  29. -    {
  30. -        begin(HPX_CURRENT_SOURCE_LOCATION(), std::forward<F>(f),
  31. -            std::forward<Args>(args)...);
  32. +#endif
  33.      }
  34.  }    // namespace chplx
  35. diff --git a/library/include/chplx/cobegin.hpp b/library/include/chplx/cobegin.hpp
  36. index 82a6d1f9..e393fdfc 100644
  37. --- a/library/include/chplx/cobegin.hpp
  38. +++ b/library/include/chplx/cobegin.hpp
  39. @@ -34,7 +34,15 @@ namespace chplx {
  40.          requires(!std::is_same_v<std::decay_t<F>, hpx::source_location>)
  41.      void cobegin(F&& f, Fs&&... fs)
  42.      {
  43. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  44. +        auto exec = hpx::execution::par.executor();
  45. +        hpx::experimental::task_group g;
  46. +        g.run(exec, std::forward<F>(f));
  47. +        (g.run(exec, std::forward<F>(fs)), ...);
  48. +        g.wait();
  49. +#else
  50.          cobegin(HPX_CURRENT_SOURCE_LOCATION(), std::forward<F>(f),
  51.              std::forward<Fs>(fs)...);
  52. +#endif
  53.      }
  54.  }    // namespace chplx
  55. diff --git a/library/include/chplx/coforall_loop.hpp b/library/include/chplx/coforall_loop.hpp
  56. index a07130b0..2ca238f7 100644
  57. --- a/library/include/chplx/coforall_loop.hpp
  58. +++ b/library/include/chplx/coforall_loop.hpp
  59. @@ -77,20 +77,28 @@ namespace chplx {
  60.      void coforall(hpx::source_location const& location, Tuple<Ts...>& t, F&& f,
  61.          Args&&... args)
  62.      {
  63. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  64. +        detail::coforall(t, std::forward<F>(f), std::forward<Args>(args)...);
  65. +#else
  66.          detail::coforall(t,
  67.              hpx::annotated_function(
  68.                  std::forward<F>(f), detail::generate_annotation(location)),
  69.              std::forward<Args>(args)...);
  70. +#endif
  71.      }
  72.  
  73.      template <typename... Ts, typename F, typename... Args>
  74.      void coforall(hpx::source_location const& location, Tuple<Ts...> const& t,
  75.          F&& f, Args&&... args)
  76.      {
  77. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  78. +        detail::coforall(t, std::forward<F>(f), std::forward<Args>(args)...);
  79. +#else
  80.          detail::coforall(t,
  81.              hpx::annotated_function(
  82.                  std::forward<F>(f), detail::generate_annotation(location)),
  83.              std::forward<Args>(args)...);
  84. +#endif
  85.      }
  86.  
  87.      //-----------------------------------------------------------------------------
  88. @@ -103,6 +111,17 @@ namespace chplx {
  89.          auto policy =
  90.              hpx::parallel::util::adapt_sharing_mode(hpx::execution::par,
  91.                  hpx::threads::thread_sharing_hint::do_not_combine_tasks);
  92. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  93. +        hpx::wait_all(hpx::parallel::execution::bulk_async_execute(
  94. +            policy.executor(),
  95. +            [&](std::size_t idx, auto&&... fargs) {
  96. +                return f(r.orderToIndex(idx),
  97. +                    std::forward<decltype(args)>(fargs)...);
  98. +            },
  99. +            r.size(),
  100. +            detail::task_intent<std::decay_t<Args>>::call(
  101. +                std::forward<Args>(args))...));
  102. +#else
  103.          auto wrapped =
  104.              hpx::annotated_function(f, detail::generate_annotation(location));
  105.  
  106. @@ -115,6 +134,7 @@ namespace chplx {
  107.              r.size(),
  108.              detail::task_intent<std::decay_t<Args>>::call(
  109.                  std::forward<Args>(args))...));
  110. +#endif
  111.      }
  112.  
  113.      //-----------------------------------------------------------------------------
  114. @@ -126,6 +146,18 @@ namespace chplx {
  115.          auto policy =
  116.              hpx::parallel::util::adapt_sharing_mode(hpx::execution::par,
  117.                  hpx::threads::thread_sharing_hint::do_not_combine_tasks);
  118. +
  119. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  120. +        hpx::wait_all(hpx::parallel::execution::bulk_async_execute(
  121. +            policy.executor(),
  122. +            [&](std::size_t idx, auto&&... fargs) {
  123. +                return f(d.orderToIndex(idx),
  124. +                    std::forward<decltype(args)>(fargs)...);
  125. +            },
  126. +            d.size(),
  127. +            detail::task_intent<std::decay_t<Args>>::call(
  128. +                std::forward<Args>(args))...));
  129. +#else
  130.          auto wrapped =
  131.              hpx::annotated_function(f, detail::generate_annotation(location));
  132.  
  133. @@ -138,6 +170,7 @@ namespace chplx {
  134.              d.size(),
  135.              detail::task_intent<std::decay_t<Args>>::call(
  136.                  std::forward<Args>(args))...));
  137. +#endif
  138.      }
  139.  
  140.      //-----------------------------------------------------------------------------
  141. @@ -149,6 +182,17 @@ namespace chplx {
  142.          auto policy =
  143.              hpx::parallel::util::adapt_sharing_mode(hpx::execution::par,
  144.                  hpx::threads::thread_sharing_hint::do_not_combine_tasks);
  145. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  146. +        hpx::wait_all(hpx::parallel::execution::bulk_async_execute(
  147. +            policy.executor(),
  148. +            [&](std::size_t idx, auto&&... fargs) {
  149. +                return f(d.orderToIndex(idx),
  150. +                    std::forward<decltype(args)>(fargs)...);
  151. +            },
  152. +            d.size(),
  153. +            detail::task_intent<std::decay_t<Args>>::call(
  154. +                std::forward<Args>(args))...));
  155. +#else
  156.          auto wrapped =
  157.              hpx::annotated_function(f, detail::generate_annotation(location));
  158.  
  159. @@ -161,6 +205,7 @@ namespace chplx {
  160.              d.size(),
  161.              detail::task_intent<std::decay_t<Args>>::call(
  162.                  std::forward<Args>(args))...));
  163. +#endif
  164.      }
  165.  
  166.      //-----------------------------------------------------------------------------
  167. @@ -172,6 +217,18 @@ namespace chplx {
  168.          auto policy =
  169.              hpx::parallel::util::adapt_sharing_mode(hpx::execution::par,
  170.                  hpx::threads::thread_sharing_hint::do_not_combine_tasks);
  171. +
  172. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  173. +        hpx::wait_all(hpx::parallel::execution::bulk_async_execute(
  174. +            policy.executor(),
  175. +            [&](std::size_t idx, auto&&... fargs) {
  176. +                return f(zr.orderToIndex(idx),
  177. +                    std::forward<decltype(args)>(fargs)...);
  178. +            },
  179. +            zr.size(),
  180. +            detail::task_intent<std::decay_t<Args>>::call(
  181. +                std::forward<Args>(args))...));
  182. +#else
  183.          auto wrapped =
  184.              hpx::annotated_function(f, detail::generate_annotation(location));
  185.  
  186. @@ -184,6 +241,7 @@ namespace chplx {
  187.              zr.size(),
  188.              detail::task_intent<std::decay_t<Args>>::call(
  189.                  std::forward<Args>(args))...));
  190. +#endif
  191.      }
  192.  
  193.      //-----------------------------------------------------------------------------
  194. @@ -195,6 +253,16 @@ namespace chplx {
  195.          auto policy =
  196.              hpx::parallel::util::adapt_sharing_mode(hpx::execution::par,
  197.                  hpx::threads::thread_sharing_hint::do_not_combine_tasks);
  198. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  199. +        hpx::wait_all(hpx::parallel::execution::bulk_async_execute(
  200. +            policy.executor(),
  201. +            [&](std::size_t idx, auto&&... fargs) {
  202. +                return f(a[idx], std::forward<decltype(args)>(fargs)...);
  203. +            },
  204. +            a.size(),
  205. +            detail::task_intent<std::decay_t<Args>>::call(
  206. +                std::forward<Args>(args))...));
  207. +#else
  208.          auto wrapped =
  209.              hpx::annotated_function(f, detail::generate_annotation(location));
  210.  
  211. @@ -206,6 +274,7 @@ namespace chplx {
  212.              a.size(),
  213.              detail::task_intent<std::decay_t<Args>>::call(
  214.                  std::forward<Args>(args))...));
  215. +#endif
  216.      }
  217.  
  218.      template <typename Target, typename F, typename... Args>
  219. diff --git a/library/src/detail/generate_annotation.cpp b/library/src/detail/generate_annotation.cpp
  220. index e07ac7a1..de44db84 100644
  221. --- a/library/src/detail/generate_annotation.cpp
  222. +++ b/library/src/detail/generate_annotation.cpp
  223. @@ -16,9 +16,13 @@ namespace chplx::detail {
  224.      std::string generate_annotation(hpx::source_location const& location)
  225.      {
  226.  #if defined(HPX_HAVE_THREAD_DESCRIPTION)
  227. +#if defined(CHPLX_NO_SOURCE_LOCATION)
  228. +        return {};
  229. +#else
  230.          std::filesystem::path p(location.file_name());
  231.          return hpx::util::format("%s(%d): %s", p.filename(), location.line(),
  232.              location.function_name());
  233. +#endif
  234.  #else
  235.          return {};
  236.  #endif
  237.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement