CSCI 3366 (Introduction to Parallel and Distributed Processing), Spring 2009:
Using OpenMP on the Linux Lab Machines

As of Fall 2006, the version of the GNU compilers installed on the lab machines includes support for the OpenMP extensions, so you should be able to compile and run OpenMP programs on any of our machines. Whether multithreading helps performance will depend on the program and the hardware configuration (with hyperthreading giving some potential for speedup, and more than one processor/core giving more potential for speedup). You can find out information about processors by looking at the pseudofile /proc/cpuinfo (looks like a text file).

Compiling OpenMP programs

Use the command gcc with the -fopenmp flag to compile C programs with OpenMP extensions. Typical usage:

gcc -fopenmp -o foo foo.c

Running OpenMP programs

To execute the compiled program, just type the name of the executable. By default, the number of threads is set to the number of processors (with each hyperthreaded processor counting as two). You can override this by setting the environment variable OMP_NUM_THREADS. With some compilers, using schedule(runtime) in your program will result in the runtime environment picking what it thinks is the best schedule. This does not seem to work with gcc. Either specify the type of thread scheduling in your program, or use schedule(runtime) and set the environment variable OMP_SCHEDULE. Example usages:

foo

foo arg1 arg2

OMP_NUM_THREADS=10 foo

OMP_SCHEDULE=static OMP_NUM_THREADS=10 foo

Useful links



Berna Massingill
2009-01-27