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:30] – roberto.alfieri | roberto.alfieri:pub:openmp [18/03/2022 15:45] – [What is openMP] roberto.alfieri | ||
---|---|---|---|
Linea 1: | Linea 1: | ||
====== OpenMP ====== | ====== OpenMP ====== | ||
- | [[http:// | + | ====Tutorials, |
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
+ | **[[http:// | ||
+ | |||
+ | |||
+ | ==== What is openMP ==== | ||
+ | |||
+ | [[http:// | ||
- | [[https:// | ||
{{: | {{: | ||
Linea 20: | Linea 29: | ||
Version 4.0 (July 2013), 4.5 (Nov 2015 ) and 5.0 (Nov 2018) add support for accelerators (target directives), | Version 4.0 (July 2013), 4.5 (Nov 2015 ) and 5.0 (Nov 2018) add support for accelerators (target directives), | ||
- | [[https:// | ||
- | ====Tutorials, | ||
- | |||
- | [[https:// | ||
- | - | ||
- | [[https:// | ||
- | - | ||
- | [[http:// | ||
=== openMP support in the C/C++ Compilers === | === openMP support in the C/C++ Compilers === | ||
- | http:// | + | https:// |
GCC: From GCC 6.1, OpenMP 4.5 is fully supported for C and C++ | GCC: From GCC 6.1, OpenMP 4.5 is fully supported for C and C++ | ||
Linea 208: | Linea 208: | ||
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 230: | Linea 230: | ||
Or use #pragma omp parallel for | Or use #pragma omp parallel for | ||
- | [[http:// | + | Examples: for.c for-schelule.c |
Linea 242: | Linea 242: | ||
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 262: | Linea 262: | ||
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 287: | Linea 287: | ||
} | } | ||
</ | </ | ||
+ | Examples: ex2.c | ||
Linea 311: | Linea 311: | ||
- | [[http:// | + | Examples: reduction.c |
== Combining FOR and reduce == | == Combining FOR and reduce == | ||
Linea 338: | Linea 338: | ||
- | [[http:// | + | Examples: |
Linea 346: | Linea 346: | ||
- | ==== 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