Strumenti Utente

Strumenti Sito


roberto.alfieri:pub:openmp

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Entrambe le parti precedenti la revisioneRevisione precedente
Prossima revisione
Revisione precedente
Prossima revisioneEntrambe le parti successive la revisione
roberto.alfieri:pub:openmp [14/06/2017 11:59] – [OpenMP timing] roberto.alfieriroberto.alfieri:pub:openmp [14/10/2020 18:38] – [Main clauses] roberto.alfieri
Linea 1: Linea 1:
 ====== OpenMP ====== ====== OpenMP ======
 +
  
 [[http://openmp.org/ | OpenMP]] adds constructs for shared-memory threading to C, C++ and Fortran [[http://openmp.org/ | OpenMP]] adds constructs for shared-memory threading to C, C++ and Fortran
 +
 +
 +[[https://computing.llnl.gov/tutorials/openMP/#ProgrammingModel | Memory Model:]]
  
 {{:roberto.alfieri:pub:shared_mem.png?200|}} {{:roberto.alfieri:pub:shared_mem.png?200|}}
 +
 +
 +Fork--Join Model:
 +
 +{{:roberto.alfieri:pub:fork_join2.gif?400|}}
  
  
 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), [[ https://doc.itc.rwth-aachen.de/download/attachments/28344675/SIMD%20Vectorization%20with%20OpenMP.PDF?version=1&modificationDate=1480523704000&api=v2 | vectorization (SIMD directives) ]], [[ https://computing.llnl.gov/tutorials/openMP/ProcessThreadAffinity.pdf thread affinity ]].+ 
 + 
 + 
 +Version 4.0 (July 2013)4.5 (Nov 2015 ) and 5.0 (Nov 2018)  add support for accelerators (target directives), vectorization (SIMD directives), thread affinity and cancellation. 
 +[[https://developers.redhat.com/blog/2019/03/19/whats-new-in-openmp-5-0/ | What's new in OpenMP 5.0 ]] 
  
  
Linea 14: Linea 28:
  
 [[https://computing.llnl.gov/tutorials/openMP/ | LLNL]] [[https://computing.llnl.gov/tutorials/openMP/ | LLNL]]
-- 
-[[https://docs.loni.org/wiki/Introduction_to_OpenMP | LONI]] 
 - -
 [[http://bisqwit.iki.fi/story/howto/openmp/ | Guide into OpenMP: Easy multithreading programming for C++]] [[http://bisqwit.iki.fi/story/howto/openmp/ | Guide into OpenMP: Easy multithreading programming for C++]]
 +
 +**[[http://didattica-linux.unipr.it/~alfieri/matdid/HPC/openmp/base/ | Exercises repository ]]**
  
 === openMP support in the C/C++ Compilers === === openMP support in the C/C++ Compilers ===
Linea 35: Linea 49:
  
 INTEL:  OpenMP 4.5 C/C++/Fortran supported in version 17.0 compilers INTEL:  OpenMP 4.5 C/C++/Fortran supported in version 17.0 compilers
-  * Compile with -fopenmp (gcc compiler)  or -qopenmp (intel compiler) on Linux + 
 +== How to compile with openMP library == 
 + 
 +Compile with -fopenmp (gcc compiler)  or -qopenmp (intel compiler) on Linux  
 ===== Execution model ===== ===== Execution model =====
  
Linea 126: Linea 144:
   gcc -O2 -fopenmp ex2.c    gcc -O2 -fopenmp ex2.c 
  
 +  ./a.out
 +  
 It is the programmer's responsibility to ensure that multiple threads properly access SHARED variables (such as via CRITICAL sections)  It is the programmer's responsibility to ensure that multiple threads properly access SHARED variables (such as via CRITICAL sections) 
  
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://www.fis.unipr.it/home/roberto.alfieri/didattica/matdid/prog/omp/esempi/parallel2.c | parallel2.c ]]+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://www.fis.unipr.it/home/roberto.alfieri/didattica/matdid/prog/omp/esempi/Examples]]: for.c for2.c+ 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://www.fis.unipr.it/home/roberto.alfieri/didattica/matdid/prog/omp/esempi/Examples]]: single.c+Examples: parallel-single.c
  
 ==== 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://www.fis.unipr.it/home/roberto.alfieri/didattica/matdid/prog/omp/esempi/Examples]]: sections.c sections2.c+ Examples: sections.c
  
 ==== Critical  Directive ==== ==== Critical  Directive ====
Linea 268: Linea 288:
 } }
 </code> </code>
 +Examples: ex2.c
  
  
Linea 292: Linea 312:
  
  
-[[http://www.fis.unipr.it/home/roberto.alfieri/didattica/matdid/prog/omp/esempi/Examples]]: reduction.c+ Examples: reduction.c
  
 == Combining FOR and reduce == == Combining FOR and reduce ==
Linea 319: Linea 339:
  
  
-[[http://www.fis.unipr.it/home/roberto.alfieri/didattica/matdid/prog/omp/esempi/Examples]]for2.c+ Examples: for-schedule.c
  
  
Linea 327: Linea 347:
  
  
-==== Esempio LIFE ==== 
- 
-Parallelizzazione con openMP di 
-[[http://www.fis.unipr.it/dokuwiki/doku.php?id=roberto.alfieri:user:prog_seq#simulazioni_di_sistemi_dinamici_discreti 
-| life-ser.c]] 
- 
-== Metodo 1 == 
-Parallelizzazione dei cicli for per l'aggiornamento delle funzioni do_step() e grid_copy() 
-<code> 
-void do_step(..) { 
-#pragma omp parallel for private (i,j) 
-for (i=1;i<=nrows;i++)  
-  for (j=1;j<=nrows;j++)  
-      update(i,j); 
-} 
- 
-void grid_copy(..) { 
-#pragma omp parallel for private (i) 
-for (i=1;i<=nrows;i++)  
-  memcpy(..); // copia riga 
-} 
-</code> 
- 
-== Metodo 2 == 
- 
-Matrice suddivisa in N righe. Ogni riga e' gestita da un thread. 
- 
-{{  roberto.alfieri:pub:life-omp.png?100|}} 
- 
- 
-<code> 
-init(lattice); 
-omp_set_num_threads(NUM_THREADS); 
-#pragma omp parallel 
-for(step=0; step<max; step++) 
- { 
-  do_step(); 
-  copy_row(); 
-  #pragma omp barrier 
-  #pragma omp single 
-    
-    cp_border();   
-   } 
- } 
-save("lattice.dat"); 
-</code> 
  
roberto.alfieri/pub/openmp.txt · Ultima modifica: 18/03/2022 16:11 da roberto.alfieri

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki