Over half of all computers sold today have more than one processor. While most new computers have two CPUs, the percentage of computers with four CPUs is steadily increasing. This trend will continue to increase well into the future. This is where OpenMP steps in.
OpenMP is an easy way to convert a program which uses one CPU into a program which is able to use multiple CPUs. OpenMP is designed only for shared memory systems, meaning that applications that run on one computer, and only one computer. If you’re planning on writing a high performance application that will run on a cluster of many computers, then MPI is a better choice for you. However, if your program is going to be executed on a single computer, OpenMP may very well be the best and easiest way to make a high performance, multi-threaded program. OpenMP programs are well suited to run on anything from single core computers to high performance 24-core shared memory computers, and everything in between.
The basics of OpenMP
Virtually all programs that require high performance have some sort of loop, namely for loops. Many times, one iteration of a for loop has nothing to do with any of the other iterations. Therefore, it should be easy to parallelize said for loop. Well, with OpenMP, this can be as simple as putting a compiler directive before and after the for loop, specifying that there is parallelism. The compiler will then proceed to take care of all the work for you! OpenMP really is amazing in the respect that by simply inserting compiler directives in the right places can have a profound impact on your application’s performance. If you originally wrote a program to only use one core, it may be easier than you think to convert your program to take advantage of multiple cores in some areas. Of course, there is much more to OpenMP than that, but the concept of having automatic parallelization is a main advantage of OpenMP. Since virtually all home computers are shared memory systems, OpenMP is extremely well suited for commercial programs which will run on many people’s home computers. People expect programs to run faster and faster, and the best way to accomplish this is to utilize as many processor cores as possible.
Developing OpenMP applications
Before reading up too much on OpenMP, it’s important to know a few things. First of all, OpenMP is not supported in the Express or Standard editions of Visual Studio. That means if you want to use Microsoft Visual Studio to develop OpenMP applications, you will need the professional version, which is really too bad. Alternitives do exist, but it is something to take into consideration. Of course, OpenMP can be used on open-source compilers such as GCC without any problems.