Using OpenMP on the CS Linux Machines

The versions of the GNU compilers installed on the classroom/lab machines include support for the OpenMP extensions, so you should be able to compile and run OpenMP programs on any of them. Whether multithreading helps performance will depend on the program and the hardware configuration. 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 (g++ for C++) with the -fopenmp flag to compile C programs with OpenMP extensions. Simple usage:

gcc -fopenmp -o foo foo.c

See my notes on the GNU compilers for notes on using the GNU compilers.

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 hyperthreaded processors counting as two each). 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. How well this works may depend on the compiler; it may be useful to experiment with specifying the type of thread scheduling in your program or using schedule(runtime) and setting the environment variable OMP_SCHEDULE. Example usages:


foo arg1 arg2



Useful links

Berna Massingill