12/27/2009

Parallel Programming - Using OpenMP

OpenMP is a parallel programming model for shared memory parallel computers.

It's based on Fork-Join parallel execution pattern and is suitable for Data Parallel and Task Parallel applications.

Fork-Join Pattern
- OpenMP programs begin as a single thread - the Master thread, which executes sequentially until the first parallel region construct is encountered.
- Fork: the master thread then creates a team of concurrent threads, which will execute some user provided codes.
- Join: when the team threads complete, they are synchronized to wait each other(barrier) and then terminate, leaving only the master thread ahead


Fork/Join Pattern in OpenMP (from[1])

Work Sharing Constructs
The core functionality of OpenMP is to parallelly process data or execution tasks, I.E, sharing work load. It provides several constructs to support it:
- For, OpenMP will automatically divide these (independent) loop iterations and assign them to one of the team thread to execute.
- Section, programmer can define static code sections, each one will be (parallelly) assigned to one of the team thread to execute.
- Task, data and code can be (dynamically) packed as a task and the delivered to team thread to execute them.

Implementation
OpenMP is designed for Fortran and C/C++. Its functionalities often exist in the following form:
- New Construct as Language Directive
- APIs as runtime library
- Environment Variables

Currently, visual studio 2008 supports OpenMP 2.5, OpenMP@MSDN

To use OpenMP in VS2008 c++ developing, you only need to include omp.h header and enable compiler flag /openmp (project property -> c/c++ -> language -> OpenMP Support)

More detailed tutorial can be found at [4][5].

I had written some OpenMP sample applications, it's compiled with vs2008 (except the task example).

[Reference]
[1] http://en.wikipedia.org/wiki/OpenMP
[2] http://openmp.org/wp/

[3] Introduction to Parallel Programming
[4] OpenMP tutorial at LLNL
[5] OpenMP hands-on Tutorial at SC08

[6] Parallel Programming with OpenMP and MPI
[7] Blog on OpenMP programming
[8] Intel on OpenMP traps
[9] Parallel Programming Model Comparison
[10] Microsoft on OpenMP version in Visual Studio
[11] More OpenMP sample applications

No comments: