Multi-Core OO: Part 3

Gaining freedom from the platform


February 18, 2009
URL:http://www.drdobbs.com/architecture-and-design/multi-core-oo-part-3/214501021

John Gross is chief engineer and Jeremy Orme chief architect at Connective Logic Systems. They can be contacted at [email protected] and [email protected], respectively.


This multi-part article introduces Blueprint, a technology developed Connective Logic Systems (where we work) that provides an alternative approach to multi-core development. The Blueprint toolset is built on the premise that we actually have no problem understanding complex concurrency -- until we project it into the one-dimensional world of text. For this reason, a visual representation is much easier to work with than its textual equivalent. There are some cases where text is obviously more intuitive -- such as parallelizing data-parallel loops. In these cases, technologies such as Microsoft's Task Parallel Library (TPL) and Intel's Threaded Building Blocks, can be intuitive and productive. In this installment, we consider an "infrastructural" class equivalent that rectifies the problems just decribed by transparently distributing its processing load across the available hardware and communicating asynchronously with adjacent infrastructural classes through strongly prototyped connections. Blueprint requires Visual Studio 2005 Standard Edition (or greater), Visual Studio 2005 Service Pack 1, Visual Studio 2005 Service Pack 1 for Vista (if using Windows Vista), and/or Microsoft .NET Framework 2.0 (or greater), and is available in beta for download here.

Conceptually at least, standard object-oriented models let objects invoke adjacent objects by sending messages to their member functions; and so at its highest level of abstraction OO has an inherently concurrent view of the world that is divorced from its eventual mapping to processes and hence CPU cores. Unfortunately the potential parallelism of OO's model is difficult to realize from this high level view alone because there is insufficient information to precisely describe the communication and synchronization which is required to ensure correct scheduling. Applications that do assume particular memory models (distributed or shared), network topologies, core counts, operating systems, and other such details will almost inevitably be tied to them and so all of these issues have to be abstracted out.

Freedom from the Platform

Traditionally, OO has thrived where it has been possible to assume a single core, single machine environment. In such environments, synchronous function calling can replace the asynchronous invocation idealized in the original OO model and the stack takes care of data lifetimes:

However, the advent of multi-core has led programmers to demand OO to work in an environment where synchronous invocation is no longer viable because it would stall threads and waste time and/or resources.

Blueprint was designed to let developers work at the highest levels of OO abstraction and be able to make optimal use of multi-core hardware without needing to consider low level details like threading, message-passing and arbitration (semaphores and locks).

To achieve this, it has to enable developers to describe synchronization and communication at a very high level of abstraction using a visual metaphor. The "heavy lifting" required to implement the lower level synchronization is performed by the diagram translator which can generate C++ and/or C# as required.

This means that the notion of a "class" needs to be extended to include the additional information required by the translator. Blueprint's concurrent equivalents of classes are referred to as "circuits".

What Is A Circuit?

Most developers will be familiar with the concept of a "class" in an OO sense, and the intention of Blueprint circuitry is to provide a concurrent (infrastructural) equivalent. Their purpose is therefore to localize, encapsulate, archive and re-use program logic (algorithmic and infrastructural).

A C++ class consists of a declaration where its members are specified and a definition where the code within those class members resides. Similarly, a circuit has a prototype that describes its public interface and it has a definition that contains the executable concurrent code.

Circuits may contain any of the following items:

  • Blueprint's intrinsic primitives
  • Instantiations of other circuit definitions
  • References to other circuit definitions.

The primitive symbols provide the fundamental language for defining the concurrent behavior of the circuitry. Instantiations and references allow encapsulated circuitry to be re-used by creating a new instance of the circuitry or connecting to an instance that was created elsewhere.

When a new instance of a class is created, it is allocated memory for its data members. This means that any number of classes can be instantiated and they all work on their own area of memory. Similarly, circuits have a concept of definitive state so there is no limit to the number of named circuit instances that can be created.

Circuit instances can be joined together in any way, provided that the prototypes at each end are compatible. This means that the complex array output of an FFT for example, can be directly connected to the input of a complex array filter, an RSS feed adaptor component could be connected to any number of business processes, and so on.

Classes are used for both modeling data (e.g., data collected from a sensor) and for defining active behavioral components (e.g., a sonar beam-former). Circuits can be freely interchanged with the classes but data classes are typically left as classes and exchanged between circuits that implement the active behavior. Due to this interchangeability, migration from legacy application classes to their circuit-equivalents can be performed incrementally. Conventional classes can invoke circuits; and vice-versa.

The Differences between Circuits and Classes

While class instances are passive entities that are "executed" by one or more explicitly created threads, circuit instances can be thought of as active entities that execute asynchronously and communicate through their connections. Synchronization is mostly achieved through the use of high level operations like collection, multiplexing, distribution, repetition and their reciprocal operations; splitting, de-multiplexing, competing and reduction. Explicit locking is provided but is seldom required.

Circuit member functions (methods) can be multi-dimensional, and each element can own its own individual state; this provides implicit concurrency and in many cases replaces constructs like parallel_for. It is also possible to specify the number of times that member function elements can be re-entered simultaneously without blocking (reentrancy).

There is no limit to the concurrency that a circuit component or circuit instance can have. If a multi-dimensional component has multi-dimensional member components then the resulting concurrency will be the product of the two component concurrencies. If the application's synchronization logic permits two or more components to execute simultaneously then the resulting concurrency will be the sum of the two or more component concurrencies, and so-on. This means that concurrency can be incrementally realized and accrued in a top-down manner, rather than starting with low-level loops; but both approaches will work interoperably as appropriate (methods can contain TPL, TBB, etc).

Building Applications from Components

Circuit components are intrinsically "self distributing" and so developer code doesn't typically need to know anything about their internals in order to re-use them; it's usually just a case of connecting the appropriate input and output pins (a prototyped operation). Since most user defined circuits are arbitrarily compose-able, they can be archived into "topic" libraries and re-used across projects. This means that applications can be created by domain experts using a drag-drop-and-connect metaphor.

The example below shows a simplified military sonar system constructed from re-usable components (circuit instances).

Conclusion

The object-oriented model is conceptually asynchronous in that its actors can invoke each other's methods concurrently. In single-core systems, the OO model can be mapped to classes and synchronous invocation, but this approach does not work for multi-core and distributed systems because of the limitations of the stack based call-and-return mechanism. Applications using synchronous invocation are doomed to spend the rest of their life executing in a single thread or suffer huge upheaval on each platform change as the code is modified to break the application into chunks appropriate for that platform.

Blueprint provides an alternative to a regular class, called a "circuit". Circuits have many of the desirable properties of classes that allow code to be encapsulated and re-used but they are self-propelled rather than relying on thread(s) to drive their execution and they use connections instead of calling to invoke each other's operations. This means that complex applications can be built from composing any number of circuit instances, as required, and the computation will be automatically distributed across the available hardware with an even load-balance.

For More Information

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.