Implementing Master-Slave

Implementing Master-Slave is straightforward. Before starting, however, decide how you'll divide the work among the master and slaves. You also need to answer a few questions that will guide your implementation:

  • Will the master and slaves be in separate processes or separate threads, or will you let the operating system decide for you? The latter method is called black-box execution; you don't know what's being used. The answer to this question influences the mechanisms that the master uses to communicate with the slaves.
  • If your application requires coordination of the slaves, will that coordination be done by the slaves themselves or by the master?

Step 1: Divide the work

Define how the computation can be split into equal subtasks. You could base the split on the memory size of the task, for example, or the expected execution time. Sometimes, the work is divided based on the number of elements to be analyzed by the subtasks.

images

When defining subtasks, consider the environment that will process them. It's possible to define tasks that are too fine-grained for some processor architectures and that require extra overhead at the master level to manage the subtasks.

Step 2: Combine the subtasks

In Step 1, you decide how the work is going to be defined. In this step, you decide how the results from the subtasks will be combined.

Step 3: Define how master and ...

Get Pattern-Oriented Software Architecture For Dummies 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.