Skip to content

Commit fe7070f

Browse files
committed
Reviewed some unclear comments
1 parent 29dca81 commit fe7070f

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

mpi_omp_mmap.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,14 @@ static void pairwise_merge_tree(std::vector<IndexRec>& local_sorted_index,
7878
std::vector<IndexRec> partner_buf;
7979
std::vector<IndexRec> concat;
8080

81-
// Iterate merge rounds where the stride doubles each time
82-
// 1 << round computes 2^round as the current stride
83-
// Partner for this rank is rank XOR stride
84-
// Stop when stride reaches world_size
85-
// If partner exceeds world_size we skip that pair
86-
// Example P=8 -> r=0 stride=1: 0-1 2-3 4-5 6-7
87-
// Example P=8 -> r=1 stride=2: 0-2 1-3 4-6 5-7
88-
// Example P=8 -> r=2 stride=4: 0-4 1-5 2-6 3-7
81+
// Pairwise reduction tree: at round r, partner = rank ^ (1<<r).
82+
// Skip partners >= world_size. (P=8: r0->(0,1)(2,3)(4,5)(6,7); r1->(0,2)(1,3)(4,6)(5,7); r2->(0,4)(1,5)(2,6)(3,7))
8983
for (int round = 0; (1 << round) < world_size; ++round) {
9084

9185
// Pick partner by flipping the bit for this round
9286
// ^ is bitwise XOR and (1 << round) selects the bit to flip
9387
// Example rank 5 (101b): r0 stride 1 -> 5^1=4 (100b), r1 stride 2 -> 5^2=7 (111b), r2 stride 4 -> 5^4=1 (001b)
94-
// Works like a hypercube edge per round; skip if partner >= world_size
88+
// skip if partner >= world_size
9589
const int partner = world_rank ^ (1 << round);
9690
if (partner >= world_size) continue;
9791

0 commit comments

Comments
 (0)