12. Week 11: Data-Parallel Collections
12.1. Useful Resources
12.2. Code Commentary
A short summary of the files from the accompanying code is given below, outlining the characteristic aspects of working with Scala Parallel Collections. We suggest you explore the files in the order they appear in the following list.
Measuring Performance
package object parallel
— a package object defining common functions used for benchmarking.warmedTimed
is used to take advantage of JIT-based speed-up.ParDemoTimed
— showcasing a simple parallel collection example. Notice the oddities with timing parallel vs. sequential execution.ParDemoWarmed
— the same as before, but now with warmed-up times, hence a better comparison.
Basic Usage of Parallel Collections
ParConfig
— controlling the level of parallelism for a collection.GoodParallelism
— showcasing an operation that allows for good parallelism.BadParallelism
— a case of a bad parallel speed-up (or the lack thereof) due to introduced contention in the operation applied to a collection.
Caveats of Using Parallel Collections
NonParallelizableCollections
— comparing the inherent parallelism in different collections.NonParallelizableOperations
— analysing parallelism allowed by certain operations.ParSideEffectsIncorrect
andParSideEffectsCorrect
— parallel processing in the presence of side effects.ParNonCommutativeOperator
— exploiting the effects of commutativity in parallel collections.ArrayBuffer
preserves the ordering of elements, while Scala’s set does not.ParNonAssociativeOperator
— exploiting the influence of operation associativity when processing parallel collections.ConcurrentCollectionsWrong
andConcurrentCollectionsGood
— exploring interactions between parallel and concurrent collections. In the bad case, a sequential collection is used in a parallel setting, which leads to an error.
Parallel Splitters and Combiners
ParString
— implementation of a parallel immutable stringParStringSplitter
— Recursive splitter for parallel stringsParStringSplitterTests
— Testing parallel string splitterParStringSplitterBenchmarks
— benchmarks for string splittersParStringCombiner
— two-phase combiner for parallel stringsParStringCombinerTests
— Testing parallel string combinerParStringCombinerBenchmarks
— benchmarks for combiners