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 [14/06/2017 11:59] – [OpenMP timing] roberto.alfieri | roberto.alfieri:pub:openmp [14/10/2020 18:27] – [Sections Directive] roberto.alfieri | ||
---|---|---|---|
Linea 1: | Linea 1: | ||
====== OpenMP ====== | ====== OpenMP ====== | ||
+ | |||
[[http:// | [[http:// | ||
+ | |||
+ | |||
+ | [[https:// | ||
{{: | {{: | ||
+ | |||
+ | |||
+ | Fork--Join Model: | ||
+ | |||
+ | {{: | ||
Consists of Compiler directives, runtime routines and environment variables | 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), | + | |
+ | |||
+ | |||
+ | Version 4.0 (July 2013), 4.5 (Nov 2015 ) and 5.0 (Nov 2018) | ||
+ | [[https://developers.redhat.com/blog/2019/ | ||
Linea 14: | Linea 28: | ||
[[https:// | [[https:// | ||
- | - | ||
- | [[https:// | ||
- | - | ||
[[http:// | [[http:// | ||
+ | |||
+ | **[[http:// | ||
=== openMP support in the C/C++ Compilers === | === openMP support in the C/C++ Compilers === | ||
Linea 35: | 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 126: | Linea 144: | ||
gcc -O2 -fopenmp ex2.c | gcc -O2 -fopenmp ex2.c | ||
+ | ./a.out | ||
+ | | ||
It is the programmer' | It is the programmer' | ||
Linea 189: | 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 211: | Linea 231: | ||
Or use #pragma omp parallel for | Or use #pragma omp parallel for | ||
- | [[http:// | + | Examples: for.c for-schelule.c |
Linea 223: | 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 243: | 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 292: | Linea 312: | ||
- | [[http:// | + | Examples: reduction.c |
== Combining FOR and reduce == | == Combining FOR and reduce == | ||
Linea 319: | Linea 339: | ||
- | [[http:// | + | Examples: for2.c |
Linea 327: | 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