Module 10: Open Multi-Processing
Lecture 19: What is Parallelization?
OpenMP:Terminology and Behavior
How Does It Work ?
When a thread reaches a parallel directive, it creates a team of threads and becomes the master of the team.
The master thread always have ID 0 and it is the part of team
There is an implied barrier at the end of parallel section.
Thread adjustment (if enabled) is only done before entering a parallel region
Parallel regions can be nested depends on implementation.
An ”if” clause can be used to guard the parallel region
It is illegal to branch in or out of parallel region
Only a single IF or NUM THREADS clause is permitted
Work Sharing Constructs
A work sharing construct divides the execution of enclosed code region among the members of team
They don’t launch new threads
Must be enclosed in a parallel region
No implied barrier on entry; implied barrier on exit(unless nowait is specified )
Must be encountered by all threads in team or none at all
#pragma omp for
{
....
}
$OMP DO
....
$OMP END DO
#pragma omp sections
{
....
}
$OMP SECTIONS
....
$OMP END SECTIONS
#pragma omp single
{
....
}
$OMP SINGLE
....
$OMP END SINGLE
The “omp for” Directive
The iterations of loop are distributed over the members of the team.
This assumes a parallel region has already been initiated, otherwise it executes in serial on a single processor.
Format
#pragma omp for [clause [ [ , ] clause ] ...]
for loop
There is and implied barrier at exit unless “nowait” clause is specified