While my wife and I were watching House, M.D. the other night, we were doing shots of Basil Hayden's every time one of the characters said "Hi, Bob." (I must confess, we got a lot more hammered playing this game when Bob Newhart was still on the air.*) We've both been big Hugh Laurie fans from his work in Blackadder, A Bit of Fry and Laurie, and Jeeves and Wooster.
As I was putting the full, unopened bottle back in the cupboard to await next week's episode, due to my total lack of any sort of alcoholic haze, I realized that the methods used by House and his underlings are similar to the methods you need to employ when threading an application. When first presented with an intriguing case, the doctors do a differential. Once they have formed some hypotheses about the cause, a battery of tests usually follows. This is to gather evidence that will support or refute each hypothesis and get a better idea about what the cause of this week's ailment is. Before threading a serial application, you need to survey the algorithms to find independent computations that can be executed concurrently. If you know the app well, you may already have an idea about what parts of the code should be amenable.
Once a cause is agreed upon and a course of action is determined, treatment is applied to the patient. Since this is television, there's always some complication that arises from the first, second, and (sometimes) third attempts. You just know that House is going to almost kill the patient every other week or so. Your initial multithreaded design may seem correct, but you can run into problems when you actually implement the concurrency. After code modifications, you need to debug and tune the application. This may reveal unanticipated "gotchas" and you end up going through several cycles of design-debug-tune until you get a working solution.
Every once in a while, despite their best efforts, House and his crew lose one. More often (this is television, after all), everything ends up relatively well in the end. You're going to encounter codes that may not be able to execute concurrently or won't scale well enough to achieve the desired levels of performance. You can always look for alternative algorithms or you can just chalk things up to the fact that not everything can be threaded.
There are always those codes that are so obvious about how to parallelize that they practically thread themselves. (Dr. House is be able to almost look at someone--when he can't get out of his assigned clinic hours--and arrive at the correct diagnosis.) When this happens to you, consider taking a page out of House's manual: get your work done and then hide out watching TV with a coma patient (like the guy in the cube next to yours). If your boss starts to think that you can thread whole applications in an afternoon, she'll expect you to work all kinds of miracles on a regular basis.
*Please Drink Responsibly.
The opinions expressed by me on this site are mine alone and do not necessarily reflect the opinions or strategies of Intel Corporation or its worldwide subsidiaries.