I have an #askFedi for the #GPGPU folks. Do you differentiate between a segmented reduction and a reduction by key?
I have a feeling the Thrust's “reduce by key” is improperly named, as it only reduces *consecutive runs* of values with the same key, so it's actually a segmented reduction: if the same keys reappear in subsequent segments, the corresponding values are reduced independently from the previous (e.g. if your keys are {1, 1, 3, 3, 1, 1} you'll get three runs, the first and the last for key 1, and the middle one for the 3).
OTOH, I would expect a reduction by key to reduce all values with the same key, even if they are scattered through the list. Yes, you can achieve this by pre-sorting the key-value pairs, but that has obviously an additional cost.
Are there known algorithms to do complete reductions by key *directly*, possibly in specific circumstances (e.g. keys are known to be [0, max_key])? I can't find any literature because everyone seems to focus on segmented reductions.
(I've developed an implementation that seems to perform around as well as a sort + segmented scan and wanted to compare.)