<PREV>
<INDEX> <NEXT>
OpenMP
Multi-threading layer on
top of compilers:
- hides threading details
- best use for programs where most time is spent in
iterations
- implementation depends
on the compiler
- compatible with
compilers that are not OpenMP aware
- paralelizes loops (e.g.
for) -> find suitable algorithms
- complete documentation: openmp.org and compilers
Restrictions:
- The loop variable must
be of type signed integer
- The comparison
operation must be in the form
loop_variable <, <=,
>, or >= loop_invariant_integer
- The third expression or
increment portion of the for loop must be either integer
addition or integer subtraction and by a loop invariant
value.
- If the comparison
operation is < or <=, the loop variable must
increment, if the comparison operation is > or >=, the
loop variable must decrement.
- The loop must be a
basic block.
Implementation:
#pragma omp description
clause
Ex: #pragma omp parallel for private(x)
Scheduling:
All iterations take the same time -> uniformly distributed
Compromise: performance vs memory conflicts
Clause: schedule(kind, chunk size)
kind = static, dynamic, guided, runtime
Issues:
- Data dependencies and
race conditions -> independent iterations
- Managing shared and
private data:
- Declare variable
inside the loop
- Use private clause
- Reductions (e.g. +=):
use the reduction
clause
OpenMP in gcc:
- documentation -> http://gcc.gnu.org/onlinedocs/libgomp/
- environment variables
-> customize behavior prior to start
OMP_DYNAMIC, OMP_NUM_THREADS,
...
- runtime routines ->
adjust behavior while running
opm_get_*, omp_set_*
<PREV> <INDEX>
<NEXT>