Lect11 Openmp1
Lect11 Openmp1
OpenMP
Various methods to program shared memory systems
Introduction to OpenMP
Programming shared memory systems
Due to its overhead, although processes can be used for shared memory
programming, they are rarely used in practice.
Use threads
Format:
#progma omp directive-name [clause,..] newline
(use ‘\’ for multiple lines)
Example:
#pragma omp parallel default(shared) private(beta,pi)
o private(list): everything private and local (no relation with variables outside the
block).
o shared(list): data accessed by all threads
o default (none| shared)
The reduction clause (see
lect11/reduction.cpp)
Sum = 0.0;
#pragma parallel for default(none) shared (n, x) private (I) reduction(+ : sum)
{
For(I=0; I<n; I++) sum = sum + x(I);
}
OMP_NUM_THREADS
OMP_SCHEDULE
OpenMP runtime environment
omp_get_num_threads()
omp_get_thread_num()
omp_in_parallel()
Routines related to locks
……
OpenMP examples
lect11/piomp.c
Sequential Matrix Multiply