You are on page 1of 1

The Execution Model

OpenMP uses a fork-join model of parallel execution. When a thread encounters a


parallel construct, the thread creates a team composed of itself and some additi
onal
(possibly zero) number of threads. The encountering thread becomes the master of
the new team. The other threads of the team are called slave threads of the team
. All
team members execute the code inside the parallel construct. When a thread finis
hes
its work within the parallel construct, it waits at the implicit barrier at the
end of the
parallel construct. When all team members have arrived at the barrier, the threa
ds
can leave the barrier. The master thread continues execution of user code beyond
the
end of the parallel construct, while the slave threads wait to be summoned to jo
in
other teams.
OpenMP parallel regions can be nested inside each other. If nested parallelism i
s
disabled, then the new team created by a thread encountering a parallel construc
t
inside a parallel region consists only of the encountering thread. If nested
parallelism is enabled, then the new team may consist of more than one thread.
The OpenMP runtime library maintains a pool of threads that can be used as slave
threads in parallel regions. When a thread encounters a parallel construct and n
eeds
to create a team of more than one thread, the thread will check the pool and gra
b
idle threads from the pool, making them slave threads of the team. The master
thread might get fewer slave threads than it needs if there is not a sufficient
number
of idle threads in the pool. When the team finishes executing the parallel regio
n, the
slave threads return to the pool.

You might also like