Chapter 11. Designing Components That Support Concurrency

Chapter 11. Designing Components That Support Concurrency

"As we cross the divide to instantiate ourselfs into our computational technology, our indentity will be based on our evolving mind file. We will be software, not hardware."

Ray Kurzweil , The Age of Spiritual Machines

In this Chapter

  • Taking Advantage of Interface Classes

  • A Closer Look at Object-Oriented Mutual Exclusion and Interface Classes

  • Maintaining the Stream Metaphor

  • User -Defined Classes Designed to Work with PVM Streams

  • Object-Oriented Pipes and fifos as Low-Level Building Blocks

  • Framework Classes Components for Concurrency

  • Summary

As a rule of thumb the requirement for parallelism and concurrency within a piece of software should be discovered and not introduced. Sometimes the goal of speeding up a program is not enough justification to force parallellism into logic that is naturally sequential. The parallelism within a design should be a natural consequence of the requirements of a system. Once concurrency is identified in the system requirements, then architectures and algorithms that support parallelism should be considered . In other cases the need for parallelism will emerge within an existing system that was originally designed with only sequential processing in mind. This is often the case for systems that started as single-user systems and grew into multiuser systems or systems that have evolved functionally far beyond the original specifications. In these systems the requirement for parallelism is after the fact and the system architecture must be augmented to support concurrency. In this book we are concerned with describing techniques for implementing natural parallelism. That is, once we know we need parallelism, how do we do it using C++?

We present an architectural approach to managing parallelism within a program. We take advantage of the C++ support for object-oriented programming and genericity. Particularly C++'s support for inheritance, polymorphism, and templates is used to cleanly implement architectures and components that support concurrency. Object-oriented programming techniques supply support for 10 class types shown in Table 11-1.

Table 11-1. Types of Object-Oriented Classes

Types of Classes

Description

Template classes

A parameterized type containing generic code that can use or manipulate any type; an actual type is the parameter for the code body.

Container class

A class used to hold objects in memory or external storage.

Virtual base class

A base class where during multiple inheritance, the class is the indirect and/or direct base of a derived class; only one copy of the class is shared by all the derived classes.

Abstract class

A class that supplies the interface for derived classes that can only be used as a base class; used as the layout for the construction of other classes.

Interface class

A class used to adjust the interface of other classes.

Node class

A class that has added new services or functionality beyond the services inherited from its base class.

Domain class

A class created to simulate some entity within a specific domain; the meaning of the class is relative to the domain.

Aggregate class

A class that contains other classes; has a "whole “part" relationship with other classes.

Concrete class

A complete class whose implementation is defined and instances of the class can be declared; not intended to be a base class and no attempt to create operations of commonality .

Framework class

A class or collection of classes that has a predefined structure and represents a generalized pattern of work.

These class types prove to be especially useful for designs that require concurrency. This is because these class types aid with the building-block approach. We start with primitive components, using them to build synchronization classes. We use the synchronization classes to build concurrency-safe container classes and framework classes. The framework classes are the building blocks for higher level parallel architectures such as multiagent systems and blackboards . At each level the complexity of the parallel and distributed programming is reduced with the help of the various class types in Table 11-1.

We start our discussion with the interface class. An interface or adapter class is used to modify or enhance the interface of another class or set of classes. The interface class may also act as a wrapper around one or more functions that are not members of any particular class. This use of the interface class allows us to provide an object-oriented interface to software that is not necessarily object-oriented. Furthermore, interface classes allow us to simplify the interfaces of function libraries such as POSIX threads, PVM and MPI. We can either wrap a non-object-oriented function in an object-oriented interface; or we might want to wrap a piece of data, encapsulate it, and give it an object-oriented interface. In addition to simplifying the complexity of some function libraries, the interface classes are used to present a consistent API (Application Programmer Interface) to the developers. For example, C++ programmers that have grown accustomed to the advantages of the iostreams classes tend to think of input and output in terms of object-oriented streams. The learning curve is minimized when new input and output techniques can be presented within the iostream metaphor. For instance, we might present the MPI message passing library as a collection of streams:

 mpi_stream Stream1; mpi_stream Stream2; Stream1 << Message1 << Message2 << Message3; Stream2 >> Message4; //... 

In this way, the programmer can focus on the logic of the program without getting bogged down in the syntax requirements of the MPI library.



Parallel and Distributed Programming Using C++
Parallel and Distributed Programming Using C++
ISBN: 0131013769
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net