Using Scala's parallel collections

Scala's parallel collections are a way to provide users with simple and safe tools to perform parallel programming. They come at the expense of reduced generality; however, for a vast number of parallel applications, they will be a simple and sufficient solution. Parallel collections work by providing parallel versions of various Scala collection classes. How that works can be easily seen with an example. First, we import the ParSeq class:

scala> import scala.collection.parallel.ParSeq
import scala.collection.parallel.ParSeq

We then create a list and get it's parallel counterpart. For all collections, this works the same way—by invoking the par method on the instance of that collection. The par method simply ...

Get Scientific Computing with Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.