Skip to content

Implement parallel hpx::uninitialized_relocate_* algorithms for overlapping ranges#6879

Merged
hkaiser merged 12 commits intoTheHPXProject:masterfrom
ArivoliR:trivial-relocatable
Apr 3, 2026
Merged

Implement parallel hpx::uninitialized_relocate_* algorithms for overlapping ranges#6879
hkaiser merged 12 commits intoTheHPXProject:masterfrom
ArivoliR:trivial-relocatable

Conversation

@ArivoliR
Copy link
Copy Markdown
Contributor

@ArivoliR ArivoliR commented Feb 4, 2026

Fixes #6878

Proposed Changes

  • Implemented parallel hpx::uninitialized_relocate_* algorithms for overlapping ranges.
  • Chain-based algorithm: for a left-shift by d positions, the range is split into d independent chains where chain c processes indices c, c+d, c+2d, ....
  • Each chain can be executed in parallel since elements within a chain depend only on each other.

Any background context you want to provide?

P1144 Object relocation in terms of move plus destroy
GSoC Project Wiki

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

@ArivoliR ArivoliR requested a review from hkaiser as a code owner February 4, 2026 17:14
@StellarBot
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ArivoliR ArivoliR changed the title tests: add overlapping range tests for uninitialized_relocate algorithms: handle overlapping ranges in uninitialized_relocate (WIP) Feb 4, 2026
@hkaiser hkaiser added this to the 2.0.0 milestone Feb 4, 2026
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Feb 4, 2026

@isidorostsa I believe this is another PR for you to look at. Would you have the time?

@ArivoliR ArivoliR changed the title algorithms: handle overlapping ranges in uninitialized_relocate (WIP) algorithms: handle overlapping ranges in uninitialized_relocate Feb 6, 2026
Comment thread libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp Outdated
Comment thread libs/core/algorithms/tests/unit/algorithms/uninitialized_relocate.cpp Outdated
Comment thread libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp Outdated
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Feb 8, 2026

@ArivoliR Could you please rebase your branch onto master (and resolve the conflicts)?

@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from 51e050b to d4fd325 Compare February 9, 2026 08:53

// test_uninitialized_relocate_overlap_forward(
// hpx::execution::par(hpx::execution::task))
// .get();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you plan to re-enable these tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No sir, those were only added temporarily for debugging. I’ll be removing them in the next commit. Thank you for pointing it out

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be useful to have those tests functioning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @hkaiser,
I’ve split the original overlap test into two clearer pieces as guided by Isidoros:

  1. A sequenced-only semantics test that validates the expected behavior for overlapping ranges under execution::seq.

  2. A policy comparison test that checks that execution::par (and par_unseq) produce the same observable results as the sequenced implementation.

For now I’ve left par(task) out and added a TODO. I haven’t added a test for the async behavior yet, since it requires explicitly handling the task/sender return path. I’d prefer to add a dedicated test for that once I’ve spent more time understanding the expected testing pattern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can ignore the sender&receiver part for now. I'd focus on the async/future implementation which should be easier to do. However I'd be fine for this ending up in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don’t have a working test for the async/future-based path yet, and I’m still figuring out the right way to implement it. I’d prefer to follow up with a separate PR once I figure it out in sometime. If you’re okay with it, I’d be happy to close this PR here once the current commits are approved

@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from d4fd325 to ac3fc68 Compare February 9, 2026 13:28
@ArivoliR ArivoliR requested a review from isidorostsa February 9, 2026 13:49
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from 2c7490c to fec562e Compare February 9, 2026 22:14
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Feb 10, 2026

There are still some minor things left:

The other reported problems are unrelated.

@ArivoliR ArivoliR force-pushed the trivial-relocatable branch 2 times, most recently from 345ef7f to 4df7159 Compare February 11, 2026 17:37
@ArivoliR ArivoliR requested a review from hkaiser February 12, 2026 05:02
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from 4df7159 to 5fa5d27 Compare February 14, 2026 12:15
@ArivoliR
Copy link
Copy Markdown
Contributor Author

ArivoliR commented Feb 16, 2026

There are still some minor things left:
inspect complains about a missing #include
the spell checker complains about the use of iff, please add that to the while list here: https://github.com/STEllAR-GROUP/hpx/blob/master/tools/.codespell_whitelist
The other reported problems are unrelated.

@hkaiser I believe this PR is ready for merge. I’m rebasing it now, please let me know if youd' like any further changes.

@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from 5fa5d27 to e851773 Compare February 16, 2026 17:55
@isidorostsa
Copy link
Copy Markdown
Contributor

isidorostsa commented Feb 26, 2026

In this PR, ranges that overlap in any direction will be handled by the sequential version of the code, instead of just the ones that overlap in the direction that would work with forward iteration. This means it is still a bug to call this with a range overlapping in the wrong direction, but at least its a bug in the sequential code.

In the case of relocation this will either end up destroying objects and moving from them afterwards (bug) or if the type is trivially relocatable it will keep memcpying the same object (not as bad, but still a bug). In the parallel code case it would do this but also with data races.

All in all, I think we should keep the logic of the check as it was before, since this change is not protecting us from any bugs, but looks like it is. But we should rewrite it in the style you wrote it, as it is clearer than what we had before.

For bug identification we should HPX_ASSERT that the ranges are not overlapping on either direction if we decide to go for the parallel version. When we implement the safe parallel version we can change the selection logic to fit this.

@Sahilll10
Copy link
Copy Markdown
Contributor

Sahilll10 commented Mar 3, 2026

Hi, I've been going through this PR as part of researching the GSoC project on "Implement parallel hpx::uninitialized_relocate_ algorithms for overlapping ranges." Really helpful context here.

@isidorostsa - If I'm understanding correctly, the current check falls back to sequential for all overlaps including d_first > first cases where forward parallel chunking would actually be safe.

The fix should preserve full parallelism when the shift direction is safe, only serialize when there is a genuine hazard, and HPX_ASSERT for the truly undefined cases in the parallel path.

Would appreciate any correction if I’ve misunderstood something.

@ArivoliR ArivoliR force-pushed the trivial-relocatable branch 2 times, most recently from dcf51bc to 6d6d8ca Compare March 5, 2026 09:17
@isidorostsa
Copy link
Copy Markdown
Contributor

@ArivoliR, thanks for working more on this. What is the state of this PR? What does it achieve compared to master?

@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Mar 16, 2026

@ArivoliR any comments to @isidorostsa's question?

@ArivoliR
Copy link
Copy Markdown
Contributor Author

@ArivoliR, thanks for working more on this. What is the state of this PR? What does it achieve compared to master?

The PR essentially adds HPX_ASSERT(!overlap) before any parallel algorithm is executed in all three functions. This catches wrong-direction overlaps in debug builds before they reach parallel execution. There is no other major change. Pushing fix for clang-format now.

@ArivoliR ArivoliR force-pushed the trivial-relocatable branch 2 times, most recently from 2fc4adb to 3dad9a8 Compare March 17, 2026 09:17
…ap detection

Signed-off-by: ArivoliR <arivoli2005@gmail.com>
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
…structors

For non-trivially relocatable types with a potentially-throwing move
constructor, the parallel chain algorithm cannot guarantee the same
move/destruction counts as sequential execution (P1144 requirement).
Fall back to sequential in that case.

Signed-off-by: ArivoliR <arivoli2005@gmail.com>
…ackward

Signed-off-by: ArivoliR <arivoli2005@gmail.com>
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch 2 times, most recently from 0c2c61c to 9a6a0b8 Compare March 29, 2026 23:58
hkaiser
hkaiser previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Contributor

@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!

Please resolve the merge conflicts, however.

@ArivoliR
Copy link
Copy Markdown
Contributor Author

ArivoliR commented Mar 30, 2026

LGTM, thanks!

Please resolve the merge conflicts, however.

There are a few errors sir, still working on them. Will push the fixes soon when I'm done and resolve the conflicts as well

@ArivoliR
Copy link
Copy Markdown
Contributor Author

To be specific, there was a clang-tidy error since there was a pointer to a non-trivially-copyable type.
And a few clang-format errors. Should be fixed now

Signed-off-by: ArivoliR <arivoli2005@gmail.com>
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch 2 times, most recently from 64c2d72 to aebb292 Compare March 30, 2026 16:13
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from aebb292 to bd5d836 Compare March 30, 2026 16:14
@ArivoliR ArivoliR requested a review from hkaiser March 30, 2026 19:19
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch 2 times, most recently from 7ab62e5 to 6f1cc34 Compare March 31, 2026 09:46
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
@ArivoliR ArivoliR force-pushed the trivial-relocatable branch from 6f1cc34 to d5080d9 Compare March 31, 2026 12:36
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@ArivoliR ArivoliR requested a review from hkaiser March 31, 2026 15:48
Copy link
Copy Markdown
Contributor

@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 4803e49 into TheHPXProject:master Apr 3, 2026
107 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.

Parallel uninitialized_relocate does not preserve sequenced semantics for overlapping ranges

5 participants