Book Image

Learning Concurrent Programming in Scala

By : Aleksandar Prokopec
5 (1)
Book Image

Learning Concurrent Programming in Scala

5 (1)
By: Aleksandar Prokopec

Overview of this book

Table of Contents (18 chapters)
Learning Concurrent Programming in Scala
About the Author
About the Reviewers

Caveats of parallel collections

Parallel collections were designed to provide a programming API similar to sequential Scala collections. Every sequential collection has a parallel counterpart and most operations have the same signature in both sequential and parallel collections. Still, there are some caveats when using parallel collections, and we will study them in this section.

Non-parallelizable collections

Parallel collections use splitters, represented with the Splitter[T] type, in order to provide parallel operations. A splitter is a more advanced form of an iterator; in addition to the iterator's next and hasNext methods, splitters define the split method that divides the splitter S into a sequence of splitters that traverse parts of S:

def split: Seq[Splitter[T]]

This method allows separate processors to traverse separate parts of the input collection. The split method must be implemented efficiently, as this method is invoked many times during the execution of a parallel operation...