Intel Go Parallel
Intel
Getting Started Concurrent Programming Community And Opinion Tools and Tips Advanced Concepts Go Parallel RSS Feed
 Print Print

Abstractions for Parallelism: Start with OpenMP
If parallelism is still something you have not tried, I encourage you to take a look at OpenMP right now. You can write a "Hello World" program using OpenMP today and be on the road to utilizing multi-core processors. 

Read Alexa Weber Morales' counter to this article.

While OpenMP is a decade-old set of extensions supported by virtually every compiler, it has become quite timely as we move to multi-core processors. You can use it today—no need to wait another decade for a new proposal to be available everywhere.

Abstraction for parallelism is very important so we can avoid coding in the world of POSIX threads (p-threads) and Windows threads. Our first consideration should go to OpenMP, an abstraction available in most compilers, on most systems, for C++ and Fortran.

The OpenMP specification (learn more at openmp.org) is now in version 2.5, which tidied up the document to make these extensions documented for C++ and Fortran in one common specification.

The heart of OpenMP is a set of compiler directives that extend C++ and Fortran to take advantage of shared memory parallelism. You add these directives as pragmas in C++, or special comments in Fortran. This means that compilers without support for OpenMP will simply ignore the directives and your program will compile and run as if you had done nothing. This backward compatibility is very useful.

When a compiler does support OpenMP, it will use the directives as hints from the programmer on when and how to exploit parallelism in the code it generates.

The OpenMP standard was formed by a number of companies that were all supporting some form of directives for parallelism and desired a standard for themselves and their customers. It was generally the compiler-writers at these companies who wanted to get together and make a standard—and so they did.

OpenMP is focused on loop-level parallelism in the current standard. Intel has implemented extensions on OpenMP to allow for task-level parallelism, but these are not in the current OpenMP standard—so portable use is limited to loop-level parallelism for now.

OpenMP can be used with threading libraries in the same program. Since OpenMP is easy to use on existing loops, this is the logical place to start when thinking of adding parallelism to your program.

While OpenMP is clearly designed for shared-memory machines, Intel recently introduced Cluster OpenMP as an optional add-on for their compilers. This will use the same directives (with a few optional extensions) to create code for clusters of processors that do not share memory. While it is true that you can write code in OpenMP with such fine-grained parallelism that this 'Cluster OpenMP' will not work, initial results from the team at Intel indicate it works well on quite a few programs.

I encourage you to take a look at OpenMP. This is an easy way to move many programs to parallelism and see your application performance improve as it takes advantage of multi-core processors.

You can find a C and a Fortran "Hello World" program with OpenMP on Wikipedia, or try the sample code below:

#include <omp.h>
#include <stdio.h> 
int main() {
#pragma omp paralllel
  {
    printf( "Hello world from thread %d\n", omp_get_num_thread() );
  }
}

Go ahead—write a parallel "Hello, World" app today!


Page 1 of 1
James Reinders is a senior engineer and is currently the director of business development and marketing for Intel's Software Development Products and serves as the chief evangelist and spokesperson. He has been a leader in the creation of Intel's Software Products including product plans, support, technical marketing, marketing and business development. Reinders' is also the author of Intel Press book titled 'VTune Performance Analyzer Essentials' and contributor to the new book 'Multi-Core Programming.'
Submit article to:
Ever wonder why we don't hear more from threading practitioners about how they managed to grok concurrency? Perhaps it's because they're too busy enjoying the performance increases. They won't say it's easy, but the Vegas Pro developers at Sony Creative Software are understandably proud of their growing expertise in threading and OpenMP. »
While threading can be a challenge, new software development tools help simplify the process by identifying thread correctness issues and performance opportunities. We present a methodology that has been used to successfully thread many applications and discuss tools that can assist in developing multi-threaded applications. »
This paper describes the performance analysis phase of the threading methodology we presented in our previous paper, "Best Practices for Developing and Optimizing Threaded Applications." »
How Can Theory of Constraints Help in Software Optimization?
Performance Scaling in the Multi-Core Era
» More Personalized Content
Getting Started (91)
Concurrent Programming (108)
Community and Opinion (48)
Tools and Tips (85)
Advanced Concepts (59)
What concurrency info do you need right now?
(Choose your top answer.)
An introduction
Threading basics
Advanced parallelism concepts
Optimization tools and techniques

View Results
Past Votes