Chapter 14. Writing parallel functional programs

 

This chapter covers

  • Using immutable data to simplify parallelization
  • Working with the Task Parallel library
  • Expressing parallelism declaratively using LINQ
  • Implementing overloaded operators

We’ve already seen many arguments in favor of functional programming. One reason it’s becoming increasingly important these days is parallelism. Writing code that scales to a large number of cores is much easier in the functional style compared to using the typical imperative approach.

The two concepts from the functional world that are essential for parallel computing are the declarative programming style and working with immutable data structures. These two are closely related. The code becomes more declarative when using immutable data, because the code is more concerned with the expected result of the computation than with the details of copying and changing data. Both concepts are important in different ways when it comes to parallelization.

14.1. Understanding different parallelization techniques

14.1.1. Parallelizing islands of imperative code

14.1.2. Declarative data parallelism

14.1.3. Task-based parallelism

14.2. Running graphical effects in parallel

14.2.1. Calculating with colors in F#

14.2.2. Implementing and running color filters

14.2.3. Designing the main application

14.2.4. Creating and running effects

14.2.5. Parallelizing the application

14.2.6. Implementing a blur effect

14.3. Creating a parallel simulation

14.3.1. Representing the simulated world

14.3.2. Designing simulation operations

14.3.3. Implementing helper functions

14.3.4. Implementing smart animals and predators

14.3.5. Running the simulation in parallel

14.4. Summary