Friday, January 28, 2011

Parallel Programming: These Thread Libraries offer Help

Here is Part I of the series of articles on Hands-on Programming for Parallelism using Multi-Cores

Here is Part II of the series of articles on How to assign a cpu core to a Thread?

Two important libraries that attempt to provide a generic programming framework supporting parallel execution of application level tasks are openMp and Intel's Thread building blocks. Both of these libraries have one thing in common. They are capable of creating a team of threads implicitly and assign iterations or tasks to execute in parallel using those threads.

openMP

This is the result of an industry effort to create a portable and unified standard of shared-memory parallelism. Support for openMP is widely present in compilers and the two most popular ones GCC and Microsoft's VS supports this.

The advantage are, these compiler directives for parallel programming are widely available and are easier to use and specify in a program. As an example,




int min = 0;
#pragma omp parallel sections shared(min)
{
#pragma omp section
{
for (It = 0; It < NItems; It++){ // process an iteration } } }

The above code inserts a compiler directive "omp parallel sections" that tells the compiler that a series of parallel code blocks start here.

It is the second directive "omp section" that specifies one such code block. The compiler can then implicitly create a team of threads. Each thread can then be assigned to process a range of the iterations. Notice the specification of a shared variable min. This is a variable the team of threads will share.

Some of the disadvantages with omp are,

1. You are dependent on implicit code generated by the compiler behind your back. This adds a specific risk to your application as it would depending on a third-party tool that inserts code in a dynamic fashion. Is there a guarantee that this will work seemlessly across all of your platforms and scale well, when the number of cores decreases or increases? If you are a technical lead or manager for a product, you must be comfortable with the risk.

2. There is nothing in the OMP directives to suggest object oriented development for parallel computing. While it may not preclude that, the idea of compiler directives strewn across your code makes readability a question.

Intel Thread Building Blocks

Intel TBB is a C++ template based library for loop-level parallelism that works on the idea of tasks and seem to offer promise. I must admit, I am yet to familiarize myself with this library. When I do, I would love to post an article here as part of this series.

Making a case for a more explicit Approach

A parallel framework that offers the advantages of a solid set of generic algorithms and containers as well as allow explicit programmer control over the parallel scheduling is more desirable as an opinion.

In the next article here, a few concepts based on an attempt to create such a framework is discussed.

Here is Part I of the series of articles on Hands-on Programming for Parallelism using Multi-Cores

Here is Part II of the series of articles on How to assign a cpu core to a Thread?

Here is Part III of the series of articles on These Thread Libraries offer Help

Here is Part IV of the series of articles on Building Blocks of a Parallel Framwork

Here is Part V of the series of articles on Rampaging Threads - Erecting an Effective Barrier

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home