ActionScript 3.0 Communication in Parallel Programming
Communication in a Parallel Environment
This week I decided to do one post for beginners and one for those of you interested in parallel programming and was able to use a simple program for both. The program is one with a client that communicates through a single abstract class requesting house parts in the form of Shape instances. Not a true design pattern, but no matter; it illustrates OOP communication and parallel decomposition.
Since I got tired of writing out “parallel programming” I decided to use the following symbol–//P–as a shorthand. The two slashes reminded me of two sides of a parallelogram and the P is…well for “Programming.” It’s handy, short, and easy to remember.
Having been thinking about decomposition in parallel programming, I thought that it might be interesting to use the beginner’s communication example to first illustrate decomposition. The program I used calls up four house shapes—a wall, a roof, a door and a window. It then assembles then one the screen. (Take a look at the previous post to see the program.)
The Client has methods that calls each of four Shape instances from an IShapeCity concrete implementation and then arranges them in a Sprite object. The four shapes are very inexpensive and the entire process appears as though the house appears in one fell swoop instead of in a sequence of four operations. However, suppose that instead of four very inexpensive operations, the application was made up of four very expensive ones but followed the same process. Further, instead of using a single core, the process was decomposed into four tasks. Further, each task was assigned a single core. The following little Flash movie shows the process (click Replay):
[swfobj src="http://www.as3dp.com/wp-content/uploads/2011/04/QuadHouse.swf" align="none"]
I’ve been wading through Parallel Programming with Microsoft.NET: Design Patterns for Decomposition and Coordination on Multicore Architectures by Colin Campbell, Ralph Johnson, Ade Miller and Stephen Toub. (I’m going to summarize that mouthful too—the book will be //P DP and the authors the Quad Core or just 4C.) The process, according to the authors, is called parallelizing, and it refers to taking a program designed for single core computations and decomposing it for //P. In fact, the entire process of designing for //P involves only three key operations:
- Decomposing the work into discrete units know as tasks
- Coordinating these tasks as they run in parallel
- Sharing the data so that the solution is scalable.
Naturally, it’s not that easy. Not by a long shot.
Can It Scale?
The 4C warn about parallelizing a single core program by simply looking for hotspots and give each a core. That’s what was done above. Assuming that the house parts are each very expensive (involve lots of processing), it makes sense on one level to do exactly that—find the expensive tasks and assign each one a core. I suppose that the decomposition process can be relatively easy using that approach. Besides, that allows the developer to keep the current structure using the same design patterns created for single core programming.
First of all, that approach doesn’t bode well for any program run on a single or dual core chip. It’ll be looking for additional cores that just aren’t there. The Quad Four suggest that programs be developed for single cores but have the ability to run on multiple cores. Any programming language that has access to multiple cores in the language has to have some way of knowing the number of cores are available for processing. Second of all, what happens to a program that decomposed to a certain number of task when it gets new tasks. For instance, the house has four tasks—build a wall, a roof, a door and a window. What happens when you decide to add a chimney?
Scaling has at least two dimensions—scaling to the hardware and scaling to the program development. If the program doesn’t do both, you’ll have problems down the road. It’s bad enough when you have to re-write a program for single core programming because you made some changes. However, imagine having to rewrite all of your programs every time a computer manufacturer uses a different chip. Most of the programs I have will run on my single core Pentium box, my dual-core laptop or my quad-core I have in my office at work. I realize that those programs do not handle processing, but since that’s what is going to be the future of program development and scale, it’s an important consideration.
Coordination is Communication
The second key issue in //P development is coordination of tasks. Here, I just wanted to throw out some issues that I’m hoping you’ll comment on. Later on, I’d like to devote a post or two to the coordination issue in //P for a little more in-depth consideration.
Up until now, coordination in programming has been isolated in a sequence along a single core. A hint of what the future holds in coordination can be found in work with databases and multi-server processing like Flash Media Server (FMS). The server-side and client-side processing does involve multiple processors, and what’s more, you can address them independently. For example, in FMS, you can send a job to be handled by the server-side code (play a video) and then let you know when that video is ended so that you can do something else in the program on the client-side. The event-notices that the server side code sends between client and server-side processors help coordinate program flow.
If any beginners are happening to be reading this, it underscores the importance of understanding that OOP programming is really about communication, and communication is the key to coordination. For those of you veterans who have toiled in the fields of OOP and design patterns for years, it’s another challenge. It’s one thing to change programming behavior from procedural to OOP and to begin building abstract structures like design patterns to increase programming effectiveness, but with the introduction of //P, the landscape has changed in another direction. The solutions that are emerging seemed to have bubbled up from the hardware folks, and while I like wire monkeys as much as the next guy, I’m not sure that their modeling is what software developers need. In snailing through //P DP, I see some of the same understanding for the need for abstraction as can be found in GoF, but then I see solutions that have a hardware origin and get nervous. The solutions have to be more than asking,
Is the hardware ready?
Your comments are welcomed.






This post is one that I can easily reference for beginners in OOP and Design Patterns when writing the posts for the Beginners Series. For many, including beginners, it may be too basic, but just in case a developer interested in taking the OOP route is unfamiliar with programming ActionScript 3.0 off the Timeline in Flash Professional or away from a Flex Project in Flash Builder, this will be a quick starting point to take the road less traveled in OOP and Design Patterns. (The instructions for getting started with Flash Builder are a bit long. However, you’ll find the instructions for getting started with Flash Pro following them.)







Bill Sanders
Recent Comments