roberto.alfieri:pub:openmp
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
Entrambe le parti precedenti la revisioneRevisione precedenteProssima revisione | Revisione precedenteProssima revisioneEntrambe le parti successive la revisione | ||
roberto.alfieri:pub:openmp [09/05/2019 12:24] – roberto.alfieri | roberto.alfieri:pub:openmp [14/10/2020 18:38] – [Main clauses] roberto.alfieri | ||
---|---|---|---|
Linea 1: | Linea 1: | ||
====== OpenMP ====== | ====== OpenMP ====== | ||
- | [[http:// | + | |
+ | [[http:// | ||
[[https:// | [[https:// | ||
- | {{roberto.alfieri: | + | {{:roberto.alfieri: |
Fork--Join Model: | Fork--Join Model: | ||
- | {{: | + | {{: |
Linea 21: | Linea 23: | ||
[[https:// | [[https:// | ||
- | |||
- | ====== OpenMP ====== | ||
- | |||
- | [[http:// | ||
- | |||
- | {{: | ||
- | |||
- | |||
- | Consists of Compiler directives, runtime routines and environment variables | ||
- | |||
- | Version 4.0 (July 2013) and 4.5 (Nov 2015 ) add support for accelerators (target directives), | ||
Linea 37: | Linea 28: | ||
[[https:// | [[https:// | ||
- | - | ||
- | [[https:// | ||
- | - | ||
[[http:// | [[http:// | ||
+ | |||
+ | **[[http:// | ||
=== openMP support in the C/C++ Compilers === | === openMP support in the C/C++ Compilers === | ||
Linea 58: | Linea 49: | ||
INTEL: | INTEL: | ||
- | * Compile with -fopenmp (gcc compiler) | + | |
+ | == How to compile with openMP library == | ||
+ | |||
+ | Compile with -fopenmp (gcc compiler) | ||
===== Execution model ===== | ===== Execution model ===== | ||
Linea 214: | Linea 209: | ||
A parallel region is a block of code that will be executed by multiple threads. This is the fundamental OpenMP parallel construct. | A parallel region is a block of code that will be executed by multiple threads. This is the fundamental OpenMP parallel construct. | ||
- | Examples: ex1.c ex2.c [[http:// | + | Examples: ex1.c ex2.c parallel-single.c |
Linea 236: | Linea 231: | ||
Or use #pragma omp parallel for | Or use #pragma omp parallel for | ||
- | [[http:// | + | Examples: for.c for-schelule.c |
Linea 248: | Linea 243: | ||
All other threads on the team skip this section of code. | All other threads on the team skip this section of code. | ||
- | [[http:// | + | Examples: |
==== Sections Directive ==== | ==== Sections Directive ==== | ||
Linea 268: | Linea 263: | ||
There is an implied barrier at the end of a SECTIONS directive | There is an implied barrier at the end of a SECTIONS directive | ||
- | [[http:// | + | Examples: sections.c |
==== Critical | ==== Critical | ||
Linea 293: | Linea 288: | ||
} | } | ||
</ | </ | ||
+ | Examples: ex2.c | ||
Linea 317: | Linea 312: | ||
- | [[http:// | + | Examples: reduction.c |
== Combining FOR and reduce == | == Combining FOR and reduce == | ||
Linea 344: | Linea 339: | ||
- | [[http:// | + | Examples: |
Linea 352: | Linea 347: | ||
- | ==== Esempio LIFE ==== | ||
- | |||
- | Parallelizzazione con openMP di | ||
- | [[http:// | ||
- | | life-ser.c]] | ||
- | |||
- | == Metodo 1 == | ||
- | Parallelizzazione dei cicli for per l' | ||
- | < | ||
- | void do_step(..) { | ||
- | #pragma omp parallel for private (i,j) | ||
- | for (i=1; | ||
- | for (j=1; | ||
- | update(i, | ||
- | } | ||
- | |||
- | void grid_copy(..) { | ||
- | #pragma omp parallel for private (i) | ||
- | for (i=1; | ||
- | memcpy(..); // copia riga | ||
- | } | ||
- | </ | ||
- | |||
- | == Metodo 2 == | ||
- | |||
- | Matrice suddivisa in N righe. Ogni riga e' gestita da un thread. | ||
- | |||
- | {{ roberto.alfieri: | ||
- | |||
- | |||
- | < | ||
- | init(lattice); | ||
- | omp_set_num_threads(NUM_THREADS); | ||
- | #pragma omp parallel | ||
- | for(step=0; step< | ||
- | { | ||
- | do_step(); | ||
- | copy_row(); | ||
- | #pragma omp barrier | ||
- | #pragma omp single | ||
- | | ||
- | cp_border(); | ||
- | } | ||
- | } | ||
- | save(" | ||
- | </ | ||
roberto.alfieri/pub/openmp.txt · Ultima modifica: 18/03/2022 16:11 da roberto.alfieri