Getting Started with OpenMP
A couple of quick ideas for getting started with OpenMP.
Compile a cute example
I am assuming that you are using a garden-variety Unix or Unix-like operating system. This should also work even on MS Windows with Cygwin if you install GCC 4.3.0.
Go to the web page Guide into OpenMP: Easy multithreading programming for C++ and grab the example Calculating the Mandelbrot fractal in parallel and compile it as follows:
$ export PATH=/usr/local/gcc-4.3.2/bin:$PATH Of course, substitute here your own path to a reasonably recent build of gcc which supports OpenMP on your own machine! Ditto below in the LD_LIBRARY_PATH statement. $ which gcc /usr/local/gcc-4.3.2/bin/gcc $ gcc --version gcc (GCC) 4.3.2 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc -fopenmp mandlebrot_ascii.cpp -lm $ export LD_LIBRARY_PATH=/usr/local/gcc-4.3.2/lib $ ./a.out ,,,,,,,cccccccccccccccccccccccc888888888MMM@jprajwaM888888cccccc,,,,| ,,,,,,,ccccccccccccccccccccccc8888888888MMM@@jwoOQrj@M8888888cccccc,,| ,,,,,cccccccccccccccccccccccc8888888888MMMM@jaroEpaj@MM8888888cccccc,| ,,,,,ccccccccccccccccccccccc8888888888MMMM@@aOrOJ .raj@MMM888888cccccc| ,,,,,cccccccccccccccccccccc88888888888MMM@@@wQQGa MO8w@MMMMM88888ccccc| ,,,ccccccccccccccccccccccc8888888888MMM@@@jjarP @wj@@MMMMM8888cccc| ,,,cccccccccccccccccccccc8888888888MM@@@@@jjawo@ Qwaj@@@@MMMM88cccc| ,,cccccccccccccccccccccc88888888MMM@aaaraaawwrpQ Ogrwwaj@@@@wjM88ccc| ,,,cccccccccccccccccccc8888888MMMMM@jrpjgrro8EQcr@. oM.PJgEraajapr@M88cc| ,,ccccccccccccccccccc888888MMMMMM@@@jQQjgrOQQE p grp8ogg8MM8cc| ,,ccccccccccccccccccc8888MMMMMMMM@@@jawGP c O.. rgwMM88c| ,ccccccccccccccccc8888MMMMMMMMMM@@@jawrgGP crj@MM88| ,ccccccccccccccc888MMMMMMMMMMM@@@@jwOgQo Epaj@MM88| ,cccccccccccc88888Mja@@@@@@@@@@@jjjawOM ,waj@M88| ,cccccccc8888888MM@jwaajjjaoajjjjjaarPP OOpPjM88| cccccc88888888MMM@@aoorrwwrOrwwaaawro JjM88| cccc88888888MMMMM@@jwpJJPggPOO8pwwrpp jpa@M88| ,cc888888888MMMMMM@jjwr. @ .Epogp og@M88| cc888888888MMMMMM@jjapoPg GjOE pww@M88| c88888888MMMMMM@aaawrgQc ,. oQjMM88| c8888888M@@@@@jjaGpggP w Oa@MM88| 8MMMMM@j@@@@jjjwwo@wGc a Jwj@MM88| MM@@jjrgwawwawpggOJ .wj@@MM88| MM@@jjrgwawwawpggOJ .wj@@MM88| 8MMMMM@j@@@@jjjwwo@wGc a Jwj@MM88| c8888888M@@@@@jjaGpggP w Oa@MM88| c88888888MMMMMM@aaawrgQO ,. oQjMM88| cc888888888MMMMMM@jjapoPg GjOE pww@M88| ,cc888888888MMMMMM@jjwr. @ .Epogp og@M88| cccc88888888MMMMM@@jwpJJPggPOO8pwwrpp rpa@M88| cccccc88888888MMM@@aoorrwwrOrwwaaawro JjM88| ,cccccccc8888888MM@jwaajjjaoajjjjjaarPP OOpPjM88| ,cccccccccccc88888Mja@@@@@@@@@@@jjjawOM ,waj@M88| ,ccccccccccccccc888MMMMMMMMMMM@@@@jwOgQo Epaj@MM88| ,ccccccccccccccccc8888MMMMMMMMMM@@@jawrgGP crj@MM88| ,,ccccccccccccccccccc8888MMMMMMMM@@@jawGP c O.. rgwMM88c| ,,ccccccccccccccccccc888888MMMMMM@@@jQQjgrOQQE p grp8ogg8MM8cc| ,,,cccccccccccccccccccc8888888MMMMM@jrpjgrro8EQcr@. oM.PJgEraajapr@M88cc| ,,cccccccccccccccccccccc88888888MMM@aaaraaawwrpQ Ogrwwaj@@@@wjM88ccc| ,,,cccccccccccccccccccccc8888888888MM@@@@@jjawo@ Qwaj@@@@MMMM88cccc| ,,,ccccccccccccccccccccccc8888888888MMM@@@jjarP @wj@@MMMMM8888cccc| ,,,,,cccccccccccccccccccccc88888888888MMM@@@wQQGa MO8w@MMMMM88888ccccc| ,,,,,ccccccccccccccccccccccc8888888888MMMM@@aOrOJ .raj@MMM888888cccccc| ,,,,,cccccccccccccccccccccccc8888888888MMMM@jaroEpaj@MM8888888cccccc,| $
Read a book
Parallel Programming in OpenMP (Morgan Kaufman [Elsevier], 2000) has never gone beyond its approximately ten-year-old first edition, to the best of my knowledge and minimal research on the Web. But it's still awesome.
The book introduces the topic of parallelism and narrows it down to shared memory parallelism which is the domain of OpenMP. Then it teaches the concepts and their implementation in OpenMP ... for C/C++ programmers, it all comes down to #pragmas and libraries (d'oh).
The things you can do in parallel using OpenMP, why you do them, how you do them, and how you can go wrong are described in an orderly, scientific and concise fashion.
The only pain for the "average" programmer is that the book is essentially in Fortran. Some examples are show also in C/C++ but you're translating on the fly in your mind if C/C++ is your main praxis. It's like reading a French Horn score while playing the Trumpet.

