diff --git a/src/care/KeyValueSorter_decl.h b/src/care/KeyValueSorter_decl.h index 15f452c7..46a9e66a 100644 --- a/src/care/KeyValueSorter_decl.h +++ b/src/care/KeyValueSorter_decl.h @@ -1491,9 +1491,7 @@ void IntersectKeyValueSorters(RAJADeviceExec exec, KeyValueSorter void IntersectKeyValueSorters(RAJA::seq_exec exec, diff --git a/src/care/KeyValueSorter_impl.h b/src/care/KeyValueSorter_impl.h index 6103a640..2b4b9608 100644 --- a/src/care/KeyValueSorter_impl.h +++ b/src/care/KeyValueSorter_impl.h @@ -464,7 +464,17 @@ CARE_INLINE void IntersectKeyValueSorters(RAJADeviceExec exec, host_device_ptr searches{smaller+1}; host_device_ptr matched{smaller+1}; CARE_STREAM_LOOP(i, 0, smaller+1) { - searches[i] = i != smaller ? care::BinarySearch(largerArray, largeStart, larger, smallerArray[i+smallStart]) : -1; + if (i == smaller) { + searches[i] = -1; + } + else { + // to be consistent with CPU algorithm, find the first match + int match = care::BinarySearch(largerArray, largeStart, larger, smallerArray[i+smallStart]); + while (match > largeStart && largerArray[match-1] == largerArray[match]) { + --match; + } + searches[i] = match; + } matched[i] = i != smaller && searches[i] > -1; } CARE_STREAM_LOOP_END