Text-only Table of Contents (frame/ no frame)
(9) How to Compile and Run An OpenMP Program Previous Top Next

How to Compile and Run an OpenMP Program


CompilerCompiler OptionsDefault behavior for # of threads
(OMP_NUM_THREADS not set)
GNU (gcc, g++, gfortran)-fopenmpas many threads as available cores
Intel (icc ifort)-openmpas many threads as available cores
Portland Group (pgcc,pgCC,pgf77,pgf90)-mpone thread


Environment Variable  OMP_NUM_THREADS sets the number of threads


GNU Compiler Example
$ gcc -o omp_helloc -fopenmp omp_hello.c
$ export OMP_NUM_THREADS=2
$ ./omp_helloc
Hello World from thread = 0
Hello World from thread = 1
Number of threads = 2
$
$ gfortran -o omp_hellof -fopenmp omp_hello.f
$ export OMP_NUM_THREADS=4
$ ./omp_hellof
Hello World from thread = 2
Hello World from thread = 1
Hello World from thread = 3
Hello World from thread = 0

Number of threads = 4

Intel Compiler Example
$ icc -o omp_helloc -openmp omp_hello.c
omp_hello.c(22): (col. 1) remark: OpenMP DEFINED REGION WAS PARALLELIZED.
$ export OMP_NUM_THREADS=3
$ ./omp_helloc
Hello World from thread = 0
Hello World from thread = 2
Hello World from thread = 1
Number of threads = 3
$
$ ifort -o omp_hellof -openmp omp_hello.f
omp_hello.f(20): (col. 7) remark: OpenMP DEFINED REGION WAS PARALLELIZED.
$ export OMP_NUM_THREADS=2
$ ./omp_hellof
Hello World from thread = 0
Number of threads = 2
Hello World from thread = 1


Portland Group Example
[sas@discovery intro_openmp]$ pgcc -o omp_helloc -mp omp_hello.c
[sas@discovery intro_openmp]$ export OMP_NUM_THREADS=2
[sas@discovery intro_openmp]$ ./omp_helloc
Hello World from thread = 0
Number of threads = 2
Hello World from thread = 1
$
$ pgf90 -o omp_hellof -mp omp_hello.f
$ export OMP_NUM_THREADS=2
$ ./omp_hellof
Hello World from thread = 0
Number of threads = 2
Hello World from thread = 1






Previous Top Next


compile_run.src  last modified Mar 23, 2009 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College