Caveats with 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, which divides the splitter S
into a sequence of splitters that traverse parts of the S
splitter:
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...