OpenMP Flashcards
three primary API components
1 compiler directives
2 runtime library rountines
3 environment variables
ICV thread numbers
OMP_NUM_THREADS
num_threads(n) pragma!
sections
pragma sections, pragma section
- each sections is run by 1 thread
- implicit barrier at end of sections region
for
- no sych at beginning
- implciit barrier at end (nowait to delete it)
- must have no ata dependency
schedule
- used for the FOR loop
1. static: round robin, fixed chunks of n/t
2. dynamic: given one by one at runtime, chunks 1 (good for load balance)
3. guided: start with bigger chunks, then smaller exponentially, one by one at runtime
4. runtime: set at runtime
5. auto: compiler/runtime chooses
sharing attributes
- private
- shared
- default
- firstprivate
- lastprivate
list synchronization pragmas
barrier, masked region, single region. critical section, atomic statement, ordered contruct
barrier
pragma omp barrrier
synchs all threads
can cause load imbalance, use only when needed
masked Construct
pragma omp masked [ filter(integer-expression)
- only primary thread executed code, the others skip
- no implied barrier at either end
single Construct
pragma omp single
- implicit barrier!
- a thread executes it
- clauses like private(list) firstprivate(list)
- like initializeing data structures
ciritical construct
pragma omp critical [(name)
restricts execution of the associated structured block to a single thread at a time
- no implicit barrier?!
- can cause load imbalance, only use when really needed
atomic statement
pragma omp atomic
so a memory location is updated atomically
- like critical, but less overhead, but also only 1 operation, avoid locking
-
ordered construct
pragma omp ordered
block of code that must be executed in sequential order.
- The ordered construct sequentializes and orders the execution of ordered regions while allowing code outside the region to run in parallel.
- clauses: threads (default), simd
- for!!!
omp locks
kinda like mutex
omp_lock_t lockvar; initializes a simple lock
omp_init_lock(&lockvar);
omp_destroy_lock(&lockvar); uninitializes a simple lock
omp_set_lock(&lockvar) waits until a simple lock is available and then sets it
omp_unset_lock(&lockvar) unsets lock
omp_test_lock(&lockvar) tests, if true sets lock
nestable locks possible