concept parallel reduce in category data

appears as: parallel reduce, parallel reduce
Mastering Large Datasets with Python: Parallelize and Distribute Your Python Code

This is an excerpt from Manning's book Mastering Large Datasets with Python: Parallelize and Distribute Your Python Code.

That we’re prevented from using parallelization here is a pretty undesirable side effect. After all, one of the big reasons we’re exploring these techniques is that they’re supposed to be good for big datasets. If we can’t use parallelization, we can’t scale our processing with our data and we’ll ultimately be limited in the size of data we can use. Fortunately for us, we can always use parallelization at the reduce level instead of at the map level. We’ll take a look at that in the next chapter, on parallel reduce.

  • By using a parallel reduce
  • Parallel map, which I introduced in section 2.2, is a great technique for transforming a large amount of data quickly. However, we did gloss over some nuances when we were learning the basics. We’ll dig into those nuances in this chapter. Parallel reduce is parallelization that occurs at the reduce step of our map and reduce pattern. That is, we’ve already called map, and now we’re ready to accumulate the results of all those transformations. With parallel reduce, we use parallelization in the accumulation process instead of the transformation process.

    Figure 6.3. Parallel reduce has six parameters: an accumulation function, a sequence, an initializer value, a map, a chunksize, and a combination function—three more than the standard reduce function.

    The map parameter to parallel reduce is exactly what we would expect it to be, given its name: it’s a map function. The parallel reduce implementation we’ll use piggy-backs off the parallelism we implemented in our parallel map. That’s why our parallel reduce will share all of its benefits and drawbacks—a lot of the behavior is directly inherited.

    That being said, we don’t have to pass our parallel reduce a parallel map. We are free to pass it a lazy map. For example, we could pass it the lazy map that comes standard with Python. If we do this, we won’t have a parallel reduce, we’ll have a lazy reduce. This is much less useful than a lazy map, however, because reduce only results in a single accumulated value—even if that value is a complex data structure—and we have to operate on the entire sequence to know what it is.

    So far in this chapter, we’ve looked at implementation nuances of parallelism. Specifically, we’ve looked at when we should use parallel workflows and how the parallel reduce workflow differs from the parallel map workflow with which we were already familiar. Now that we’ve got that down, we can finally solve the problem we noticed at the end of chapter 5 of reduce working more slowly in parallel. We’re finally ready to use parallel reduce.

    Like our standard map and our parallel map, the moving from standard reduce to parallel reduce is a little anticlimactic. Assuming that we have our accumulation and combination functions in place, implementing parallel reduce requires only three steps: