Archive

Archive for October, 2008

Threads, it’s easy to overlook the dependencies

October 27th, 2008

At CriticalBlue, we often hear that thread based programming is hard and that it requires us all to ‘think parallel’. Conceptually though, I don’t think the fundamentals of thread programming are all that hard to grasp. In pthreads, we create threads so functions can execute in parallel; we use mutexes to coordinate mutual exclusion through critical regions, and we use condition variables to wait until conditions are right before proceeding. Seems simple enough.

Rather, what really is hard is to constrain a parallel program such that all possible interleavings of program execution are correct. While it’s easy to create threads and run them in parallel, it’s hard to catch all the data dependencies between the threads which must be properly ordered to ensure always race free execution.

I recently proved once again just how easy it is to overlook a critical dependency. I was preparing some examples for a talk I was giving at the ARM Developers’ Conference this October. I was extending a simple edge detection example to show different ways the image pipeline could be parallelized. I’d previously parallelized just the Sobel function using a row-based data decomposition strategy. No problem here I thought, all I need to do is replace the Sobel slice function with one processing a slice through the correction, noise filter and sobel functions. I ran the program, and I ended up with a pretty good looking result.

I say pretty good, because there was one line of pixels which looked a little off, but that was probably just an artifact, right? Wrong. That artifact saved me a lot of embarrassment, because, I’d blindly introduced data races into my code.

When you think it through, it’s easy to see that a filter slice can’t start processing until the correcting slice has completed and the edges of it’s neighbors have completed processing. Within a slice, the processing is sequential, but at the edges, there’s no guarantee that the edges of one slice will be corrected before another slice needs them. A simple but slightly overconstrained solution is to ensure that all correction processing completes before any filtering processing occurs, and, likewise, that all filtering completes before the Sobel slices begin.

The lesson learned is that it is very easy to overlook a critical dependency. I was lucky that my visual result gave me a tiny hint that something was wrong. It could have very easily passed all my tests, and I could have had an observant conference attendee put me in my place.

Simple though it was, this incident gave me a real appreciation for the importance of good tools, in this case, not so much for doing my parallel thinking for me, but for checking that what I did wasn’t doing anything wrong, and when there are mistakes, helping me understand what they are and ensuring that I’ve corrected them. I’ve added data race detection tools to my list of must haves for parallel programming.

Alas, there are still plenty of other ways I routinely embarrass myself…

- Skip Hovsmith

Skip

Welcome to ‘Common Thread’

October 20th, 2008

Welcome to ‘Common Thread’, CriticalBlue’s blog, which is dedicated to all things multicore and multithreaded, practical and pragmatic. Our multicore journey started several years ago when we developed our Cascade product for extracting instruction level parallelism out of optimized ARM binaries. Since then we’ve expanded our capabilities to help with task level parallelism exploitation and verification of multithreaded code. We also have some new products in the works, which you will hear much about in early 2009. Add to that the fact that we co-chair the Multicore Association’s Multicore Programming Practices (MPP) working group and you can see that we are steeped in all the various aspects of creating and programming multicore and multithreaded architectures.

In the course of our multicore journey we have stuck to our guiding principles of leveraging, as much as possible, existing languages, tools and environments. We’ve listened to man of you on the way and we have learned a lot. The result? We’ve only invented tools that fit into the methodologies that developers already use and where they add value in the process. We are the practical and pragmatic multicore guys!

In this blog and in our community pages you’ll find the team here at CriticalBlue will share our views and experiences on technical and business insight and aspects of multicore and multithreaded market discontinuity. You’ll also find links to educational and opinionated writers who will give their own views; sometime complementary, sometimes not. Overall we hope you’ll find a wealth of useful information. If you have opinions, we’d love to hear them.

- David Stewart, CEO

David