use pairwise algorithm for reduce as well as mapreduce. fixes #4702