Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contains and contains_subrange parallel algorithm implementation GSOC 2024 #6497

Merged
merged 11 commits into from
Oct 8, 2024

Conversation

Zak-K-Abdi
Copy link
Contributor

@Zak-K-Abdi Zak-K-Abdi commented May 29, 2024

Implementing parallel algorithms for contains and contains_subrange. GSOC 2024 proposal.
Will attempt to fix hpx::search so hpx::contains_subrange can make a call to hpx::search.

@jenkins-cscs
Copy link
Collaborator

Can one of the admins verify this patch?

@hkaiser hkaiser added this to the 1.11.0 milestone May 29, 2024
Comment on lines 46 to 79
template <typename ExPolicy, typename Iterator, typename Sentinel,
typename T, typename Proj>
static util::detail::algorithm_result_t<ExPolicy, bool> parallel(
ExPolicy&& policy, Iterator first, Sentinel last, const T& val,
Proj&& proj)
{
const auto distance = detail::distance(first, last);
if (distance <= 0)
{
return util::detail::algorithm_result<ExPolicy, bool>::get(
false);
}

const auto itr = util::loop_pred<
std::decay_t<ExPolicy>>(first, last, [&val, &proj]
(const auto& cur) { return HPX_INVOKE(proj, *cur) == val; });

if (itr == last)
{
return util::detail::algorithm_result<ExPolicy, bool>::get(
false);
}

return util::detail::algorithm_result<ExPolicy, bool>::get(true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably work-in-progress, but I just want to mention that util::loop_pred doesn't actually use the execution policy to run in parallel, so this will not run in multiple threads. You'll have to use a partitioner, which splits the work and launches it on multiple (the equal algorithm is a a nice example).

Copy link
Contributor Author

@Zak-K-Abdi Zak-K-Abdi Jun 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I was unaware at the time I wrote that, I should have been more mindful of what I was using. I checked out equal algorithm and I made some changes that now use the partitioner in the parallel overload. Also, I was hesitant to do this but I created a file in the parallel/algorithms/detail called contains.hpp, holding the implementation details for the algorithm.

@Pansysk75 Pansysk75 changed the title Contains and contains_subrange parallel algorithm implementaion GSOC 2024 Contains and contains_subrange parallel algorithm implementation GSOC 2024 May 29, 2024
Copy link

codacy-production bot commented May 29, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.10% 90.96%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f4ff6e8) 232431 198777 85.52%
Head commit (1b22fae) 205360 (-27071) 175429 (-23348) 85.43% (-0.10%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6497) 509 463 90.96%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@hkaiser
Copy link
Member

hkaiser commented Jun 3, 2024

@Zak-K-Abdi: Please take a look at the clang-format problems (https://gist.github.com/hkaiser/26bced03497017f481dbb9ee7d0df67c) and the cmake issues:

Missing hpx/parallel/algorithms/detail/contains.hpp in libs/core/algorithms/CMakeLists.txt

Also here is the list of inspect issues reported:

/libs/core/algorithms/include/hpx/parallel/algorithms/contains.hpp: END file doesn't end with a newline, Endline Whitespace: 74, C, Lic, SPDX-Lic
/libs/core/algorithms/include/hpx/parallel/algorithms/detail/contains.hpp: END file doesn't end with a newline, C, Lic, SPDX-Lic

@Zak-K-Abdi Zak-K-Abdi force-pushed the contains/contains_subrange branch 5 times, most recently from 7b69479 to 711ca44 Compare June 11, 2024 17:21
static hpx::future<bool> get(hpx::future<T>& itr, T& last)
{
return itr.then(
[&last](hpx::future<T> it) { return it.get() != last; });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pansysk75 Hi Panos, I'm not sure if this is correct, could you check this line of code I changed? I changed the helper function to return hpx::future, a continuation to the previous future, by using .then().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks right, i think you might want to capture last by value and not by reference, as it is a local variable of the parallel function. Otherwise looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pansysk75 Just to make sure, should I also pass last by value for the functions in my contains_subrange_helper_class or only for the lambda?

@@ -148,8 +137,7 @@ namespace hpx::parallel { namespace detail {
HPX_FORWARD(Proj2, proj2));

return util::detail::algorithm_result<ExPolicy, bool>::get(
contains_subrange_helper<ExPolicy, FwdIter1>().get(itr) !=
last1);
contains_subrange_helper<ExPolicy, FwdIter1>().get(itr, last1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning contains_subrange_helper<ExPolicy, FwdIter1>().get(itr, last1) would suffice here.
The return types of your helper function already match with algorithm_result_t. Calling that additional ::get will call .get() on your future before returning it, which undermines your latest change on your helper.

@Pansysk75
Copy link
Member

@Zak-K-Abdi Could you please address this: #6497 (comment)
Otherwise this looks ready to merge, thanks for your efforts!

@Zak-K-Abdi
Copy link
Contributor Author

@Zak-K-Abdi Could you please address this: #6497 (comment) Otherwise this looks ready to merge, thanks for your efforts!

Apologies, I completely forgot about that comment. I will make that change soon. Thanks.

Copy link
Member

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@hkaiser hkaiser merged commit 6e59829 into STEllAR-GROUP:master Oct 8, 2024
71 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants