Skip to content

Commit e955387

Browse files
author
Sai Charan
committed
for each test 1
1 parent 862697f commit e955387

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

libs/core/algorithms/include/hpx/parallel/algorithms/for_each.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ namespace hpx::parallel {
324324
util::loop_n<execution_policy_type>(part_begin, part_size,
325325
util::invoke_projected_ind<fun_type, proj_type>{f_, proj_});
326326
}
327+
328+
// Overload for stdexec bulk: receives single index
329+
// called when using stdexec bulk with a single size_t index
330+
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr void operator()(
331+
std::size_t idx)
332+
{
333+
HPX_INVOKE(f_, HPX_INVOKE(proj_, idx));
334+
}
327335
};
328336

329337
template <typename ExPolicy, typename F>
@@ -390,6 +398,14 @@ namespace hpx::parallel {
390398
{
391399
return (*this)(part_begin, part_size);
392400
}
401+
402+
// Overload for stdexec bulk: receives single index
403+
// called when using stdexec bulk with a single size_t index
404+
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr void operator()(
405+
std::size_t idx)
406+
{
407+
HPX_INVOKE(f_, idx);
408+
}
393409
};
394410

395411
///////////////////////////////////////////////////////////////////////

libs/core/algorithms/include/hpx/parallel/util/detail/partitioner_iteration.hpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,45 @@
1616
///////////////////////////////////////////////////////////////////////////////
1717
namespace hpx::parallel::util::detail {
1818

19+
// Helper to detect if a type is tuple-like
20+
template <typename T, typename = void>
21+
struct is_tuple_like : std::false_type
22+
{
23+
};
24+
25+
template <typename T>
26+
struct is_tuple_like<T,
27+
std::void_t<decltype(hpx::tuple_size<std::decay_t<T>>::value)>>
28+
: std::true_type
29+
{
30+
};
31+
32+
template <typename T>
33+
inline constexpr bool is_tuple_like_v = is_tuple_like<T>::value;
34+
1935
// Hand-crafted function object allowing to replace a more complex
2036
// bind(hpx::functional::invoke_fused(), f1, _1)
2137
template <typename Result, typename F>
2238
struct partitioner_iteration
2339
{
2440
std::decay_t<F> f_;
2541

26-
template <typename T>
42+
// Overload for tuple-like types
43+
template <typename T,
44+
typename = std::enable_if_t<is_tuple_like_v<T>>>
2745
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Result operator()(T&& t)
2846
{
2947
return hpx::invoke_fused_r<Result>(f_, HPX_FORWARD(T, t));
3048
}
3149

50+
// Overload for non-tuple types (std::size_t from stdexec bulk)
51+
template <typename T,
52+
typename = std::enable_if_t<!is_tuple_like_v<T>>, typename = void>
53+
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Result operator()(T&& t)
54+
{
55+
return HPX_INVOKE_R(Result, f_, HPX_FORWARD(T, t));
56+
}
57+
3258
template <std::size_t... Is, typename... Ts>
3359
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Result operator()(
3460
hpx::util::index_pack<Is...>, hpx::tuple<Ts...>& t)

0 commit comments

Comments
 (0)