30 Oct
My current assignment at work is optimizing some code for DualCore processors using OpenMP.
OpenMP is a portable, scalable model that gives shared-memory parallel programmers a simple and flexible interface for developing parallel applications for platforms ranging from the desktop to the supercomputer.
Sounds pretty impressive, huh? .... Well it actually isn't. All you have to do (VS 2005) is activate OpenMP for your project and then you can use #pragma plus various OpenMP directives to split your code into multiple threads.
Check out the code for this multi-threaded Hello World program using the PARALLEL directive:
Pretty cool! Heres how the output looks:

Another useful OpenMP directive is FOR. Here's the code from a FOR LOOP and the output:
You can see how OpenMP breaks the loop apart and spreads the goodies among the different threads. The first number of each line is the current iteration, followed by the number of the thread (in parentheses) that is executing that iteration. After the semicolon comes the result. Of course this only works with non-linear loop computations and with loops that have a fixed number of iterations.
So that's OpenMP. You can accomplish some severe optimization with very little code....
Leave a reply
You must be logged in to post a comment.