Skip to content

algorithms: fix operator!= inconsistency in prefetching_iterator#7294

Merged
hkaiser merged 3 commits into
TheHPXProject:masterfrom
arpittkhandelwal:fix/prefetching-iterator-comparison
May 29, 2026
Merged

algorithms: fix operator!= inconsistency in prefetching_iterator#7294
hkaiser merged 3 commits into
TheHPXProject:masterfrom
arpittkhandelwal:fix/prefetching-iterator-comparison

Conversation

@arpittkhandelwal
Copy link
Copy Markdown
Contributor

This PR fixes an inconsistency in hpx::parallel::util::detail::prefetching_iterator where operator== compared both idx_ and base_, but operator!= only compared idx_.

As a result, two iterators with equal idx_ but different base_ pointers would have both == and != return false simultaneously, which violates the fundamental semantic requirements of C++ iterator comparison. Any range-based or manual loop termination check of it != end relied on operator!=, while other equality checks used operator==, making the two operators silently inconsistent for iterators constructed from different prefetcher contexts over the same-sized ranges.

Fix

  • Modified operator!= to delegate to operator== via !(*this == rhs).
  • Removed both // FIXME comments regarding member and base iterator comparisons.
  • Added a regression unit test in libs/core/algorithms/tests/unit/algorithms/prefetching_iterator.cpp that directly tests this behavior (including test_different_base_consistency which fails prior to the fix).

Copilot AI review requested due to automatic review settings May 24, 2026 10:49
@arpittkhandelwal arpittkhandelwal requested a review from hkaiser as a code owner May 24, 2026 10:49
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 24, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test and fixes prefetching_iterator comparison semantics to eliminate an inconsistency between operator== and operator!=.

Changes:

  • Fix prefetching_iterator::operator!= to be the logical negation of operator==.
  • Add a new unit test covering equality/inequality consistency (including the previously failing scenario).
  • Register the new unit test target in the algorithms unit test CMake list.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
libs/core/algorithms/tests/unit/algorithms/prefetching_iterator.cpp New regression/unit tests for prefetching_iterator equality/inequality invariants.
libs/core/algorithms/tests/unit/algorithms/CMakeLists.txt Adds the new prefetching_iterator test to the unit test set.
libs/core/algorithms/include/hpx/parallel/util/prefetching.hpp Makes operator!= consistent by implementing it as !(*this == rhs).

Comment thread libs/core/algorithms/tests/regressions/prefetching_iterator.cpp
Comment thread libs/core/algorithms/tests/unit/algorithms/prefetching_iterator.cpp Outdated
Comment thread libs/core/algorithms/tests/unit/algorithms/prefetching_iterator.cpp Outdated
Comment thread libs/core/algorithms/tests/regressions/prefetching_iterator.cpp
@StellarBot
Copy link
Copy Markdown
Collaborator

Performance test report

HPX Performance

Comparison

BENCHMARKFORK_JOIN_EXECUTORPARALLEL_EXECUTORSCHEDULER_EXECUTOR
For Each(=)(=)(=)

Info

PropertyBeforeAfter
HPX Datetime2026-03-09T14:08:29+00:002026-05-24T10:54:56+00:00
HPX Commit0eeca863c2980c
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Datetime2026-03-09T09:15:24.034803-05:002026-05-24T17:58:19.713700-05:00
Clusternamerostamrostam
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Envfile

Comparison

BENCHMARKNO-EXECUTOR
Future Overhead - Create Thread Hierarchical - Latch++

Info

PropertyBeforeAfter
HPX Datetime2026-03-09T14:08:29+00:002026-05-24T10:54:56+00:00
HPX Commit0eeca863c2980c
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Datetime2026-03-09T09:17:15.638328-05:002026-05-24T18:00:23.884422-05:00
Clusternamerostamrostam
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Envfile

Comparison

BENCHMARKFORK_JOIN_EXECUTOR_DEFAULT_FORK_JOIN_POLICY_ALLOCATORPARALLEL_EXECUTOR_DEFAULT_PARALLEL_POLICY_ALLOCATORSCHEDULER_EXECUTOR_DEFAULT_SCHEDULER_EXECUTOR_ALLOCATOR
Stream Benchmark - Add(=)(=)--
Stream Benchmark - Scale(=)----
Stream Benchmark - Triad(=)----
Stream Benchmark - Copy(=)++++++

Info

PropertyBeforeAfter
HPX Datetime2026-03-09T18:50:37+00:002026-05-24T10:54:56+00:00
HPX Commitba89f5d3c2980c
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Datetime2026-03-09T17:49:10.837937-05:002026-05-24T18:01:09.190387-05:00
Clusternamerostamrostam
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Envfile

Explanation of Symbols

SymbolMEANING
=No performance change (confidence interval within ±1%)
(=)Probably no performance change (confidence interval within ±2%)
(+)/(-)Very small performance improvement/degradation (≤1%)
+/-Small performance improvement/degradation (≤5%)
++/--Large performance improvement/degradation (≤10%)
+++/---Very large performance improvement/degradation (>10%)
?Probably no change, but quite large uncertainty (confidence interval with ±5%)
??Unclear result, very large uncertainty (±10%)
???Something unexpected…

operator== checked both idx_ and base_, but operator!= only checked
idx_. This meant two iterators with equal idx_ but different base_
pointers would have both operator== and operator!= return false
simultaneously -- a logical impossibility for a well-formed iterator.

All loop termination code using 'it != end' relied on operator!=, while
equality checks used operator==, making the two operators silently
inconsistent for iterators constructed from different prefetcher contexts
over the same-sized ranges.

Fix: delegate operator!= to operator== via !(*this == rhs), making
the two operators proper logical negations as required by the C++
EqualityComparable concept. Remove both FIXME comments that noted the
uncertainty.

Also add a regression test (prefetching_iterator.cpp) that directly
exercises the pre-fix contradiction in test_different_base_consistency.

Signed-off-by: arpittkhandelwal <arpitkhandelwal810@gmail.com>
Copilot AI review requested due to automatic review settings May 28, 2026 15:40
@hkaiser hkaiser force-pushed the fix/prefetching-iterator-comparison branch from cab4048 to 20b43fb Compare May 28, 2026 15:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

- flyby: move test to regressions directory

Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
@hkaiser hkaiser force-pushed the fix/prefetching-iterator-comparison branch from 20b43fb to 44ba229 Compare May 28, 2026 16:23
@StellarBot
Copy link
Copy Markdown
Collaborator

Performance test report

HPX Performance

Comparison

BENCHMARKFORK_JOIN_EXECUTORPARALLEL_EXECUTORSCHEDULER_EXECUTOR
For Each(=)(=)(=)

Info

PropertyBeforeAfter
HPX Datetime2026-03-09T14:08:29+00:002026-05-28T16:23:19+00:00
HPX Commit0eeca86cc95369
Datetime2026-03-09T09:15:24.034803-05:002026-05-28T11:52:19.505823-05:00
Clusternamerostamrostam
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Envfile

Comparison

BENCHMARKNO-EXECUTOR
Future Overhead - Create Thread Hierarchical - Latch++

Info

PropertyBeforeAfter
HPX Datetime2026-03-09T14:08:29+00:002026-05-28T16:23:19+00:00
HPX Commit0eeca86cc95369
Datetime2026-03-09T09:17:15.638328-05:002026-05-28T11:54:23.907490-05:00
Clusternamerostamrostam
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Envfile

Comparison

BENCHMARKFORK_JOIN_EXECUTOR_DEFAULT_FORK_JOIN_POLICY_ALLOCATORPARALLEL_EXECUTOR_DEFAULT_PARALLEL_POLICY_ALLOCATORSCHEDULER_EXECUTOR_DEFAULT_SCHEDULER_EXECUTOR_ALLOCATOR
Stream Benchmark - Add(=)(=)--
Stream Benchmark - Scale(=)---
Stream Benchmark - Triad(=)---
Stream Benchmark - Copy(=)+++++

Info

PropertyBeforeAfter
HPX Datetime2026-03-09T18:50:37+00:002026-05-28T16:23:19+00:00
HPX Commitba89f5dcc95369
Datetime2026-03-09T17:49:10.837937-05:002026-05-28T11:55:09.134833-05:00
Clusternamerostamrostam
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Envfile

Explanation of Symbols

SymbolMEANING
=No performance change (confidence interval within ±1%)
(=)Probably no performance change (confidence interval within ±2%)
(+)/(-)Very small performance improvement/degradation (≤1%)
+/-Small performance improvement/degradation (≤5%)
++/--Large performance improvement/degradation (≤10%)
+++/---Very large performance improvement/degradation (>10%)
?Probably no change, but quite large uncertainty (confidence interval with ±5%)
??Unclear result, very large uncertainty (±10%)
???Something unexpected…

Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
Copilot AI review requested due to automatic review settings May 29, 2026 14:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@StellarBot
Copy link
Copy Markdown
Collaborator

Performance test report

HPX Performance

Comparison

BENCHMARKFORK_JOIN_EXECUTORPARALLEL_EXECUTORSCHEDULER_EXECUTOR
For Each(=)(=)(=)

Info

PropertyBeforeAfter
HPX Commit0eeca86e36c7ff
HPX Datetime2026-03-09T14:08:29+00:002026-05-29T14:28:26+00:00
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Envfile
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Clusternamerostamrostam
Datetime2026-03-09T09:15:24.034803-05:002026-05-29T09:37:04.626206-05:00

Comparison

BENCHMARKNO-EXECUTOR
Future Overhead - Create Thread Hierarchical - Latch++

Info

PropertyBeforeAfter
HPX Commit0eeca86e36c7ff
HPX Datetime2026-03-09T14:08:29+00:002026-05-29T14:28:26+00:00
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Envfile
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Clusternamerostamrostam
Datetime2026-03-09T09:17:15.638328-05:002026-05-29T09:39:12.024749-05:00

Comparison

BENCHMARKFORK_JOIN_EXECUTOR_DEFAULT_FORK_JOIN_POLICY_ALLOCATORPARALLEL_EXECUTOR_DEFAULT_PARALLEL_POLICY_ALLOCATORSCHEDULER_EXECUTOR_DEFAULT_SCHEDULER_EXECUTOR_ALLOCATOR
Stream Benchmark - Add(=)(=)--
Stream Benchmark - Scale(=)---
Stream Benchmark - Triad(=)----
Stream Benchmark - Copy(=)++++++

Info

PropertyBeforeAfter
HPX Commitba89f5de36c7ff
HPX Datetime2026-03-09T18:50:37+00:002026-05-29T14:28:26+00:00
Hostnamemedusa08.rostam.cct.lsu.edumedusa08.rostam.cct.lsu.edu
Envfile
Compiler/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8/opt/apps/llvm/18.1.8/bin/clang++ 18.1.8
Clusternamerostamrostam
Datetime2026-03-09T17:49:10.837937-05:002026-05-29T09:39:57.177105-05:00

Explanation of Symbols

SymbolMEANING
=No performance change (confidence interval within ±1%)
(=)Probably no performance change (confidence interval within ±2%)
(+)/(-)Very small performance improvement/degradation (≤1%)
+/-Small performance improvement/degradation (≤5%)
++/--Large performance improvement/degradation (≤10%)
+++/---Very large performance improvement/degradation (>10%)
?Probably no change, but quite large uncertainty (confidence interval with ±5%)
??Unclear result, very large uncertainty (±10%)
???Something unexpected…

@hkaiser hkaiser merged commit 1d2b97a into TheHPXProject:master May 29, 2026
89 of 101 checks passed
@hkaiser hkaiser added this to the 2.0.0 milestone May 29, 2026
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