Introduction to OpenMP
Last updated
Last updated
A parallel programming model, an API
Comprised of
Compiler directives
Runtime Library Routines
Environment Variables
Programming Model
All OpenMP programs begin as a single process: the master thread. The master thread executes sequentially until the first parallel region construct is encountered.
FORK: the master thread then creates a team of parallel threads.
JOIN: When the team threads complete the statements in the parallel region construct, they synchronize and terminate, leaving only the master thread.
Compiler directives statements (start with#pragma omp
) tell Compiler that here follows a parallel region
a parallel region is bounded with{ }
Runtime Library Routines can give you some information about your environment
omp_get_thread_num()
. Tells the thread id of the current thread.
omp_get_num_threads()
. Tells the total thread number. If you don't tell Compiler how many threads you want to have in your program, it will be the number of your cores by default.
... you can find more on the internet about this.
Environment Variables tell Compiler that some variables are public and some variables are private.
As OpenMP is a shared memory model, variables are shared by threads by default.
You can define private variables
usingprivate()
statement.
Notice that all variables defined in the parallel region are private variables.