Parallel Hierarchies


The Parallel Hierarchies pattern is a parallel extension of the Layers pattern approach [POSA96, Shaw95, SG96] with elements of functional parallelism. The order of operations on data is the most important feature. Parallelism is introduced when two or more components of a layer are able to exist simultaneously, performing the same operation. Components can be created statically, waiting for calls from higher layers, or dynamically, when a call triggers their creation.

Examples

A Non-programming Example

Consider the control of hand motion by the brain. Nerves conduct impulses from the brain to muscles, controlling their contraction, and sensing their position. A muscle contracts or relaxes, performing forces on points of the bone structure, modifying its position. However, a coordinated movement is only the result of the simultaneous and ordered contraction or relaxation of several muscles, each one returning information of its position through nerves to the brain. A simple or complex movement is achieved as a result of a request from the brain, triggering several nerves to contract or relax muscles, which at the same time return feedback signals until the bone has a precise position. The hierarchy of nervous, muscular and bone tissues accomplishes the motion of any part of the body.

A Programming Example

Suppose a computer-controlled industrial robot system, which consists of several arms with hands [Fro96,PLoP94]. Each hand grabs or releases objects, and each arm moves its hand around. The structure of the robot program is presented as a hierarchy (Figure 4).

Figure 4. A robot system program hierarchy.

In order to manufacture an article, the robot communicates with its hands and arms, activating them and causing them to carry out a set of physical tasks and movements. When a physical hand completes its grab or release operation, the hand sends a message back to its associated arm. Now, the arm knows that it is safe to start moving the physical arm. Similarly, an arm sends back messages to the robot when it has completed its move operation. Arms act simultaneously, until they have manufactured an article.

Problem

It is necessary to perform a computation repeatedly, composed of a series of ordered operations on a set of ordered data. Not every problem meets this criterion. Consider a program whose output may be the result of just a single complex computation as a series of conceptually ordered simple operations, executed not for value but for effect, at different levels. An operation at a high level requires the execution of one or more operations at lower levels. If this program is carried out serially, it could be viewed as a chain of subroutine calls, evaluated one after another. Generally, performance as execution time is the feature of interest.

Forces

From the problem description and other additional considerations of granularity and load balance in parallel design [Fos94, CT92], the following forces should be considered for the Parallel Hierarchies pattern:

Solution

Parallelism is introduced by allowing the simultaneous execution of more than one instance per layer through time. In a Layer pattern system, when an operation triggers an operation, this may involve the execution of operations in several layers. These operations are usually triggered by a function call, and data is shared in the form of arguments for these function calls. During the execution of operations in each layer, usually the higher layers have to wait for a result from lower layers. However, if each layer is represented by more than one component, they can be executed in parallel and service new requests. Therefore, at the same time, several ordered sets of operations can be carried out by the same system. Several computations can be overlapped in time[POSA96, Shaw95].

Structure

This pattern is composed of conceptually-independent entities, ordered in the shape of hierarchies of layers. Each layer, as an implicit different level of abstraction, is composed of several components that perform the same operation. To communicate, layers use function calls, referring to each other as elements of some composed structure. The same computation is performed by different groups of functionally related components. Components simultaneously exist and process during the execution time (Figure 5).

Figure 5. Parallel Hierarchies pattern.

Participants

Dynamics

As the parallel execution of layer elements is allowed, a typical scenario is proposed to describe its basic run-time behaviour. All layer elements are active at the same time, accepting function calls, operating, and returning or sending another function call to elements in lower level layers. If a new function call arrives from the client, a free element of the first layer takes it and starts a new computation.

As stated in the problem description, this pattern is used when it is necessary to perform repeatedly a computation, as series of ordered operations. The scenario presented here takes the simple case when two computations, namely Computation 1 and Computation 2, have to be performed. Computation 1 requires the operations Op.A, which requires the evaluation of Op.B, which needs the evaluation of Op.C. Computation 2 is less complex than Computation 1, but requires to perform the same operations Op.A and Op.B. The parallel execution is as follows (figure 6):

Figure 6. Scenario for Parallel Hierarchies pattern.

Implementation

The implementation process is based on the four stages mentioned above in the Context in general and Implementation in general sections.

Consequences

Benefits

Liabilities

Known uses

Related patterns

The Parallel Hierarchies pattern extends the Layers pattern [POSA96] and the Layers style [Shaw95, SG96] for parallel systems. Several other related patterns are found in [PLoP94]; more precisely, A Hierarchy of Control Layers pattern, Actions Triggered by Events pattern, and those under the generic name of Layered Service Composition pattern.


Contact Information

Jorge Luis Ortega Arjona.

E-mail jortega-arjona@acm.org