Skip to content

Commit d5e4e36

Browse files
Document segmented sort merge helpers
Signed-off-by: the-ivii <divyanshitalreja12@gmail.com>
1 parent ae7c6ad commit d5e4e36

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎libs/full/segmented_algorithms/include/hpx/parallel/segmented_algorithms/sort.hpp‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,16 @@ namespace hpx::parallel::detail {
695695
/// Find the stable merge partition that leaves left.size() values in
696696
/// the left run. The two returned offsets delimit equally sized
697697
/// crossing ranges: left[i, end) and right[begin, j).
698+
///
699+
/// \tparam ExPolicy The execution policy type.
700+
/// \tparam Comp The comparison function type.
701+
/// \tparam Proj The projection function type.
702+
/// \param policy The execution policy instance.
703+
/// \param left The sorted left run.
704+
/// \param right The sorted right run.
705+
/// \param comp The comparison function.
706+
/// \param proj The projection function.
707+
/// \return The left and right offsets delimiting the crossing ranges.
698708
template <typename ExPolicy, typename Comp, typename Proj>
699709
static std::pair<std::size_t, std::size_t> merge_partition(
700710
ExPolicy const& policy, segmented_sort_run<LocalIter> const& left,
@@ -735,6 +745,14 @@ namespace hpx::parallel::detail {
735745

736746
/// Exchange the crossing suffix and prefix in bounded chunks. At most
737747
/// two transfer chunks are materialized on the coordinator at once.
748+
///
749+
/// \tparam ExPolicy The execution policy type.
750+
/// \param policy The execution policy instance.
751+
/// \param left The run containing the suffix to exchange.
752+
/// \param right The run containing the prefix to exchange.
753+
/// \param left_cut The offset of the crossing suffix in \a left.
754+
/// \param crossing_size The number of values exchanged in each
755+
/// direction.
738756
template <typename ExPolicy>
739757
static void exchange_crossing_ranges(ExPolicy const& policy,
740758
segmented_sort_run<LocalIter> const& left,
@@ -774,6 +792,19 @@ namespace hpx::parallel::detail {
774792

775793
/// Merge the two exchanged runs independently on their owning
776794
/// localities. Parallel policies overlap the two local merges.
795+
///
796+
/// \tparam ExPolicy The execution policy type.
797+
/// \tparam Comp The comparison function type.
798+
/// \tparam Proj The projection function type.
799+
/// \tparam IsSeq A compile-time flag selecting sequenced dispatch.
800+
/// \param policy The execution policy instance.
801+
/// \param left The left run after exchanging its crossing suffix.
802+
/// \param right The right run after exchanging its crossing prefix.
803+
/// \param left_cut The merge boundary in \a left.
804+
/// \param right_cut The merge boundary in \a right.
805+
/// \param comp The comparison function.
806+
/// \param proj The projection function.
807+
/// \param is_seq The sequenced-dispatch flag.
777808
template <typename ExPolicy, typename Comp, typename Proj,
778809
typename IsSeq>
779810
static void merge_exchanged_runs(ExPolicy const& policy,
@@ -839,6 +870,17 @@ namespace hpx::parallel::detail {
839870
}
840871

841872
/// Perform a bounded merge-split of two adjacent sorted runs.
873+
///
874+
/// \tparam ExPolicy The execution policy used for transfers and local
875+
/// merges.
876+
/// \tparam Comp The comparison function type.
877+
/// \tparam Proj The projection function type.
878+
/// \param policy The execution policy instance.
879+
/// \param left The sorted run that retains the lower values.
880+
/// \param right The sorted run that retains the higher values.
881+
/// \param comp The comparison function.
882+
/// \param proj The projection function.
883+
/// \return True if values crossed the run boundary; otherwise false.
842884
template <typename ExPolicy, typename Comp, typename Proj>
843885
static bool execute(ExPolicy const& policy,
844886
segmented_sort_run<LocalIter> const& left,
@@ -890,6 +932,17 @@ namespace hpx::parallel::detail {
890932
/// phases continue until both parities report no changes. Parallel policies
891933
/// overlap the disjoint pairs in each phase, although values can move in
892934
/// multiple phases.
935+
///
936+
/// \tparam ExPolicy The execution policy type.
937+
/// \tparam LocalIter The local iterator type of each run.
938+
/// \tparam Comp The comparison function type.
939+
/// \tparam Proj The projection function type.
940+
/// \tparam IsSeq A compile-time flag selecting sequenced dispatch.
941+
/// \param policy The execution policy instance.
942+
/// \param runs The sorted distributed runs to merge globally.
943+
/// \param comp The comparison function.
944+
/// \param proj The projection function.
945+
/// \param is_seq The sequenced-dispatch flag.
893946
template <typename ExPolicy, typename LocalIter, typename Comp,
894947
typename Proj, typename IsSeq>
895948
void segmented_sort_merge_runs(ExPolicy const& policy,

‎libs/full/segmented_algorithms/tests/unit/partitioned_vector_sort.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ void test_sort_subranges(
332332
}
333333

334334
/// Verify compare-split phases with uneven runs and duplicate values.
335+
///
336+
/// \tparam ExPolicy The execution policy type.
337+
/// \param policy The policy used to invoke segmented sort.
338+
/// \param localities The localities that own the test partitions.
335339
template <typename ExPolicy>
336340
void test_uneven_merge_split(
337341
ExPolicy const& policy, std::vector<hpx::id_type> const& localities)
@@ -356,6 +360,8 @@ void test_uneven_merge_split(
356360
}
357361

358362
/// Verify that a complete two-run exchange remains chunked and distributed.
363+
///
364+
/// \param localities The localities that own the two test partitions.
359365
void test_two_run_merge_split(std::vector<hpx::id_type> const& localities)
360366
{
361367
// Put two reversed runs on different localities. Every value crosses the
@@ -380,6 +386,8 @@ void test_two_run_merge_split(std::vector<hpx::id_type> const& localities)
380386
}
381387

382388
/// Verify convergence when adjacent runs have strongly unequal capacities.
389+
///
390+
/// \param localities The localities used by the explicit partition layout.
383391
void test_unequal_explicit_layout(std::vector<hpx::id_type> const& localities)
384392
{
385393
std::vector<std::size_t> const sizes{100, 1, 100};

0 commit comments

Comments
 (0)