Multi-core Support and Parallel Processing

Posted by Matt | Filed under , , , , ,

I have been playing around with multi-core support and parallel processing recently because we want to add multi-core support to our application.  So I’ve been investigating some tools like Intel’s Threading Building Blocks and Microsoft’s Parallel Patterns.

The nice thing about the above frameworks is that they use structures and templates to make multi-threaded programming “look” like single-threaded programming.  They’re pretty good at easing a developer into the world of multi-threading.

For example, both have a parallel_for function which can be used in place of a traditional for loop.  The framework does the dirty work of splitting the loop iterations into separate threads (as necessary).  To the single-threaded programmer, it doesn’t have a very foreign feel to it.

The biggest difference between the two is that Intel’s solution requires the creation of classes to do the loop contents, whereas Microsoft’s solution makes use of lambda functions to put the loop contents inline with the function call.  Microsoft’s solution is less “preparation” and generally looks better to the reader.

Another difference is that Intel’s solution is not free for commercial use.  It’s free for non-commercial use, however.  Microsoft’s solution is not available yet unless you want to use the Visual Studio 2010 CTP.  I’m not prepare for that yet because I’m not willing to move compilers yet, especially this early in VS2010’s development.

So, based on the documentation from both toolkits, I’ve been trying to come with with my own threading framework.  I’ve managed to create my own ParallelFor function similar to Intel’s (I don’t like underscores in indentifiers, instead I like multi-case identifiers).  It works pretty well and it’s good enough to deal with multiple cores.

However, using a simple Fibonacci example based on this video from Channel9, my framework falls apart.  For the 20th Fibonacci number, I get the following results on a dual core processor:

  • Single threaded: 110 ms
  • My framework: 66,812 ms
  • Intel’s framework: 63 ms

I think the memory allocations are severely slowing things down.  Also, I run out of stack in larger Fibonacci numbers, like 31, which run fine under Intel’s and Microsoft’s frameworks. 

Intel’s framework is not easy to use outside of the parallel_for functions, etc.  Microsoft’s framework at least looks easier to use when dealing with pure tasks.

After all this, I just hope that Microsoft releases their Parallel Patterns framework early for Visual Studio 2008.  It looks easier to use and it should be free.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading