Computation

Overview

In the context of this chapter, computation involves using actors to manage and execute tasks in parallel. The primary focus is on distributing tasks efficiently among worker actors and handling the results asynchronously. This approach aims to improve performance and manage mutable state effectively.

Parallel Computation

Parallel computation is achieved by utilizing actors to distribute tasks among multiple worker actors. The Manager actor plays a crucial role in coordinating the distribution and collection of results. This setup allows for the efficient execution of tasks, even when they have varying execution times.

Actor Framework in Action

To illustrate the actor framework in action, consider a scenario where a computation is run in parallel. In this example, a list of random numbers between 0 and 30 is chosen, and the corresponding Fibonacci value is computed using a slow algorithm. The application is composed of three types of actors:

  1. Manager: Responsible for creating a specified number of worker actors and distributing tasks to them.
  2. Workers: Multiple instances of worker actors that perform parts of the computation.
  3. Client: Implemented in the main program class as an anonymous actor.

Worker Actor

The Worker actor is the simplest class among the three types of actors. It is responsible for running parts of the computation. Below is the figure illustrating the Worker actor:

Listing 14.6. The Worker actor, in charge of running parts of the computation Listing 14.6. The Worker actor, in charge of running parts of the computation

This setup demonstrates how actors can be used to manage parallel computation effectively, distributing tasks among multiple workers and handling results asynchronously to optimize performance.