2.3-DD2356-OpenMP Definitions
2.3-DD2356-OpenMP Definitions
Stefano Markidis
OpenMP
2
OpenMP - The Whole Cathedral
End User
layer
User
Application
Directives, Environment
Prog.
layer
OpenMP library
Compiler variables
System
3
Our Focus
End User
layer
User
Application
Prog. Layer
Directives, Environment
OpenMP library
Compiler variables
4
Compiler Directives
5
OpenMP Directives
6
OpenMP Library
OpenMP Function prototypes and types in the file: #include <omp.h>
7
OpenMP Environment Variables
The most important environment variables you could use when running a code compiled
with OpenMP are to:
• Set the default number of threads to use
• OMP_NUM_THREADS int_literal
• Process binding is enabled if this variable is true … i.e. if true the runtime will not
move threads around between processors.
• OMP_PROC_BIND true | false
• Control how “omp for schedule(RUNTIME)” loop iterations are scheduled
• OMP_SCHEDULE schedule [chunk_size]
8
How to set an environment variable in Linux/Mac?
We can set the number of threads using the environment variable OMP_NUM_THREADS.
9
Exercise 1: our first OpenMP code
10
Exercise 1: Compile OpenMP with OpenMP flag
11
Exercise 1
12