OpenMP Tutorial
Introduction
Parallel processing used to be reserved for supercomputers. Algorithms run on these systems were very carefully developed by researchers at DARPA, JPL, etc. and were reserved for modeling nuclear explosions and the like. Then came the Internet.
With it came the need for many companies to have web and database capable of handling thousands of requests a second. These servers used a technology known as symmetric multiple processing (SMP), which is still the mot common form of parallel processing. Requests for web pages, however, are atomic and so, if you have a mainframe with 4 CPUs, you can run four copies of the web server (one on each CPU) and dispatch incoming requests to whichever CPU is the least busy.
Now, parallel computing is becoming extremely common. Dual CPU systems (using SMP) are much cheaper than they used to be putting them in the reach of many consumers. Moreover, many single CPU machines now have parallel capabilities. Intel's hyperthreading CPUs are capable of running multiple threads simultaneously under certain conditions. Now with Intel's and AMD's dual core processors, many people who buy a single CPU system actually have the functionality of a dual CPU system. OpenMP is a set of extensions that make it easy for programmers to take full advantage of a system.
Writing Parallelized Programs
As we have said before, it has been possible to write parallel programs for a long time. Historically this has been done by forking the main program into multiple processes or multiple threads manually. This strategy has two major drawbacks. First, spawning processes is extremely platform dependent. Second it creates a lot of overhead for both the CPU and the programmer as it can be quite complicated keeping track of what is going on in all of the threads. OpenMP takes most of the work out of it for you. Most importantly, OpenMP makes it much easier to parallelize computationally intensive mathematic calculations.
Getting Started
The first thing you need is a compiler that implements the OpenMP standard. gcc 4.2 is supposed to be such a compiler but as of this writing it is not available yet. Consequently I will use Intel's ICL compiler which is free for non-commercial use on Linux. There is a 30 trial for Windows available also. This is not a tutorial on installing a compiler so go get it and set it up on your system first. (If you have another OpenMP capable C compiler available feel free to use that but the command line flags might be different).
One last note. The running times shown are from a computer with a 3.2GHz Pentium D with 2GB RAM. Your performance may be different but if you have an SMP, dual-core, or hyperthreading computer you should see performance improvements with OpenMP over without.
|
|
|
Copyright 2006 kallipolis.com |