Skip to content

Commit bceb336

Browse files
committed
fix issue boostorg#774 by force swapping keys when they are identical
1 parent 22e04ea commit bceb336

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/boost/compute/algorithm/detail/merge_sort_on_gpu.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ inline size_t bitonic_block_sort(KeyIterator keys_first,
170170
k.decl<bool>("compare") << " = " <<
171171
compare(k.var<key_type>("sibling_key"),
172172
k.var<key_type>("my_key")) << ";\n" <<
173+
k.decl<bool>("equal") << " = !(compare || " <<
174+
compare(k.var<key_type>("my_key"),
175+
k.var<key_type>("sibling_key")) << ");\n" <<
173176
k.decl<bool>("swap") <<
174177
" = compare ^ (sibling_idx < lid) ^ direction;\n" <<
178+
"swap |= equal;\n" <<
175179
"my_key = swap ? sibling_key : my_key;\n";
176180
if(sort_by_key)
177181
{
@@ -220,8 +224,12 @@ inline size_t bitonic_block_sort(KeyIterator keys_first,
220224
k.decl<bool>("compare") << " = " <<
221225
compare(k.var<key_type>("sibling_key"),
222226
k.var<key_type>("my_key")) << ";\n" <<
227+
k.decl<bool>("equal") << " = !(compare || " <<
228+
compare(k.var<key_type>("my_key"),
229+
k.var<key_type>("sibling_key")) << ");\n" <<
223230
k.decl<bool>("swap") <<
224231
" = compare ^ (sibling_idx < lid);\n" <<
232+
"swap |= equal;\n" <<
225233
"my_key = swap ? sibling_key : my_key;\n";
226234
if(sort_by_key)
227235
{

0 commit comments

Comments
 (0)