Reduced the memory usage of reduce and similar operations

These operations used to wait for all the results to be available in an
array on the driver program before merging them. They now merge values
incrementally as they arrive.