SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
OpenMP Reference Sheet for C/C++                                                                <A,B,C such that total iterations known at start of loop>
                                                                                                for(A=C;A<B;A++) {
                                                                                                    <your code here>

Constructs                                                                                           <force ordered execution of part of the code. A=C will be guaranteed to execute
<parallelize a for loop by breaking apart iterations into chunks>                                    before A=C+1>
#pragma omp parallel for [shared(vars), private(vars), firstprivate(vars),                           #pragma omp ordered {
lastprivate(vars), default(shared|none), reduction(op:vars), copyin(vars), if(expr),                     <your code here>
ordered, schedule(type[,chunkSize])]                                                                 }
<A,B,C such that total iterations known at start of loop>                                       }
for(A=C;A<B;A++) {
     <your code here>                                                                           <parallelized sections of code with each section operating in one thread>
                                                                                                #pragma omp sections [private(vars), firstprivate(vars), lastprivate(vars),
    <force ordered execution of part of the code. A=C will be guaranteed to execute         reduction(op:vars), nowait] {
    before A=C+1>                                                                                    #pragma omp section {
    #pragma omp ordered {                                                                                 <your code here>
        <your code here>                                                                             }
    }                                                                                                #pragma omp section {
}                                                                                                         <your code here>
                                                                                                     }
<parallelized sections of code with each section operating in one thread>                            ....
#pragma omp parallel sections [shared(vars), private(vars), firstprivate(vars),                 }
lastprivate(vars), default(shared|none), reduction(op:vars), copyin(vars), if(expr)] {
     #pragma omp section {                                                                      <only one thread will execute the following. NOT always by the master thread>
          <your code here>                                                                      #pragma omp single {
     }                                                                                              <your code here (only executed once)>
     #pragma omp section {                                                                      }
          <your code here>                                                                  }
     }
     ....
}                                                                                           Directives
                                                                                          shared(vars) <share the same variables between all the threads>
<grand parallelization region with optional work-sharing constructs defining more         private(vars) <each thread gets a private copy of variables. Note that other than the
specific splitting of work and variables amongst threads. You may use work-sharing             master thread, which uses the original, these variables are not initialized to
constructs without a grand parallelization region, but it will have no effect (sometimes       anything.>
useful if you are making OpenMP'able functions but want to leave the creation of threads firstprivate(vars) <like private, but the variables do get copies of their master thread
to the user of those functions)>                                                               values>
#pragma omp parallel [shared(vars), private(vars), firstprivate(vars), lastprivate(vars), lastprivate(vars) <copy back the last iteration (in a for loop) or the last section (in a
default(private|shared|none), reduction(op:vars), copyin(vars), if(expr)] {                    sections) variables to the master thread copy (so it will persist even after the
     <the work-sharing constructs below can appear in any order, are optional, and can         parallelization ends)>
     be used multiple times. Note that no new threads will be created by the constructs.  default(private|shared|none) <set the default behavior of variables in the parallelization
     They reuse the ones created by the above parallel construct.>                             construct. shared is the default setting, so only the private and none setting have
                                                                                               effects. none forces the user to specify the behavior of variables. Note that even with
     <your code here (will be executed by all threads)>                                        shared, the iterator variable in for loops still is private by necessity >
                                                                                          reduction(op:vars) <vars are treated as private and the specified operation(op, which
     <parallelize a for loop by breaking apart iterations into chunks>                         can be +,*,-,&,|,&,&&,||) is performed using the private copies in each thread. The
     #pragma omp for [private(vars), firstprivate(vars), lastprivate(vars),                    master thread copy (which will persist) is updated with the final value.>
reduction(op:vars), ordered, schedule(type[,chunkSize]), nowait]
copyin(vars) <used to perform the copying of threadprivate vars to the other threads.
     Similar to firstprivate for private vars.>
if(expr) <parallelization will only occur if expr evaluates to true.>
schedule(type [,chunkSize]) <thread scheduling model>
                                                                                           Function Based Locking < nest versions allow recursive locking>
     type         chunkSize                                                                void   omp_init_[nest_]lock(omp_lock_t*) <make a generic mutex lock>
     static     number of iterations per thread pre-assigned at beginning of loop          void   omp_destroy_[nest_]lock(omp_lock_t*) <destroy a generic mutex lock>
                    (typical default is number of processors)                              void   omp_set_[nest_]lock(omp_lock_t*) <block until mutex lock obtained>
                                                                                           void   omp_unset_[nest_]lock(omp_lock_t*) <unlock the mutex lock>
     dynamic    number of iterations to allocate to a thread when available (typical       int    omp_test_[nest_]lock(omp_lock_t*) <is lock currently locked by somebody>
                    default is 1)
     guided     highly dependent on specific implementation of OpenMP

nowait <remove the implicit barrier which forces all threads to finish before continuation Settings and Control
     in the construct>                                                                     int    omp_get_num_threads() <returns the number of threads used for the parallel
                                                                                                   region in which the function was called>
                                                                                           int    omp_get_thread_num() <get the unique thread number used to handle this
                                                                                                   iteration/section of a parallel construct. You may break up algorithms into parts
                                                                                                   based on this number.>
Synchronization/Locking Constructs <May be used almost anywhere, but will
                                                                                           int    omp_in_parallel() <are you in a parallel construct>
only have effects within parallelization constructs.>
                                                                                           int    omp_get_max_threads() <get number of threads OpenMP can make>
                                                                                           int    omp_get_num_procs() <get number of processors on this system>
<only the master thread will execute the following. Sometimes useful for special handling
                                                                                           int    omp_get_dynamic() <is dynamic scheduling allowed>
of variables which will persist after the parallelization.>
                                                                                           int    omp_get_nested() <is nested parallelism allowed>
#pragma omp master {
                                                                                           double omp_get_wtime() <returns time (in seconds) of the system clock>
     <your code here (only executed once and by the master thread).
                                                                                           double omp_get_wtick() <number of seconds between ticks on the system clock>
}
                                                                                           void omp_set_num_threads(int) <set number of threads OpenMP can make>
                                                                                           void omp_set_dynamic(int) <allow dynamic scheduling (note this does not make
<mutex lock the region. name allows the creation of unique mutex locks.>
                                                                                                   dynamic scheduling the default)>
#pragma omp critical [(name)] {
                                                                                           void omp_set_nested(int) <allow nested parallelism; Parallel constructs within other
     <your code here (only one thread allowed in at a time)>
                                                                                                   parallel constructs can make new threads (note this tends to be unimplemented
}
                                                                                                   in many OpenMP implementations)>
<force all threads to complete their operations before continuing>
                                                                                           <env vars- implementation dependent, but here are some common ones>
#pragma omp barrier
                                                                                           OMP_NUM_THREADS "number" <maximum number of threads to use>
                                                                                           OMP_SCHEDULE "type,chunkSize" <default #pragma omp schedule settings>
<like critical, but only works for simple operations and structures contained in one line of
code>
#pragma omp atomic
     <simple code operation, ex. a += 3; Typical supported operations are ++,--,+,*,-
,/,&,^,<<,>>,| on primitive data types>                                                      Legend
                                                                                             vars is a comma separated list of variables
<force a register flush of the variables so all threads see the same memory>                 [optional parameters and directives]
#pragma omp flush[(vars)]                                                                    <descriptions, comments, suggestions>
                                                                                             .... above directive can be used multiple times
<applies the private clause to the vars of any future parallelize constructs encountered (a For mistakes, suggestions, and comments please email e_berta@plutospin.com
convenience routine)>
#pragma omp threadprivate(vars)

Más contenido relacionado

La actualidad más candente

PyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsPyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsGraham Dumpleton
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojureJuan-Manuel Gimeno
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 
EventMachine for RubyFuZa 2012
EventMachine for RubyFuZa   2012EventMachine for RubyFuZa   2012
EventMachine for RubyFuZa 2012Christopher Spring
 
Clojure Interoperability
Clojure InteroperabilityClojure Interoperability
Clojure Interoperabilityrik0
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torqueboxrockyjaiswal
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread poolsmaksym220889
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxbobmcwhirter
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyBruno Oliveira
 
Simple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time JavaSimple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time JavaUniversidad Carlos III de Madrid
 

La actualidad más candente (20)

PyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating DecoratorsPyCon NZ 2013 - Advanced Methods For Creating Decorators
PyCon NZ 2013 - Advanced Methods For Creating Decorators
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
 
85ec7 session2 c++
85ec7 session2 c++85ec7 session2 c++
85ec7 session2 c++
 
Tp Result
Tp ResultTp Result
Tp Result
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
EventMachine for RubyFuZa 2012
EventMachine for RubyFuZa   2012EventMachine for RubyFuZa   2012
EventMachine for RubyFuZa 2012
 
Clojure Interoperability
Clojure InteroperabilityClojure Interoperability
Clojure Interoperability
 
Enhancing the region model of RTSJ
Enhancing the region model of RTSJEnhancing the region model of RTSJ
Enhancing the region model of RTSJ
 
Steady with ruby
Steady with rubySteady with ruby
Steady with ruby
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread pools
 
S emb t13-freertos
S emb t13-freertosS emb t13-freertos
S emb t13-freertos
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets Ruby
 
Simple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time JavaSimple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time Java
 
Erlang session2
Erlang session2Erlang session2
Erlang session2
 

Destacado

Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionCherryBerry2
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open MpAnshul Sharma
 
Presentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel ProgrammingPresentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel ProgrammingVengada Karthik Rangaraju
 
Intro to OpenMP
Intro to OpenMPIntro to OpenMP
Intro to OpenMPjbp4444
 
OpenMP Tutorial for Beginners
OpenMP Tutorial for BeginnersOpenMP Tutorial for Beginners
OpenMP Tutorial for BeginnersDhanashree Prasad
 

Destacado (11)

Nbvtalkataitamimageprocessingconf
NbvtalkataitamimageprocessingconfNbvtalkataitamimageprocessingconf
Nbvtalkataitamimageprocessingconf
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System Discussion
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open Mp
 
MPI n OpenMP
MPI n OpenMPMPI n OpenMP
MPI n OpenMP
 
Open mp
Open mpOpen mp
Open mp
 
Openmp combined
Openmp combinedOpenmp combined
Openmp combined
 
Open mp intro_01
Open mp intro_01Open mp intro_01
Open mp intro_01
 
Presentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel ProgrammingPresentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel Programming
 
Intro to OpenMP
Intro to OpenMPIntro to OpenMP
Intro to OpenMP
 
OpenMP Tutorial for Beginners
OpenMP Tutorial for BeginnersOpenMP Tutorial for Beginners
OpenMP Tutorial for Beginners
 
Deep C
Deep CDeep C
Deep C
 

Similar a Open MP cheet sheet

Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5AbdullahMunir32
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick reviewCe.Se.N.A. Security
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Akhila Prabhakaran
 
Medical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUsMedical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUsDaniel Blezek
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011David Troy
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsAjin Abraham
 
Open mp library functions and environment variables
Open mp library functions and environment variablesOpen mp library functions and environment variables
Open mp library functions and environment variablesSuveeksha
 
Supporting Arrays and Allocatables in LFortran
Supporting Arrays and Allocatables in LFortranSupporting Arrays and Allocatables in LFortran
Supporting Arrays and Allocatables in LFortranGagandeep Singh
 

Similar a Open MP cheet sheet (20)

Lecture8
Lecture8Lecture8
Lecture8
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
OpenMP
OpenMPOpenMP
OpenMP
 
Egearmand: an Erlang Gearman daemon
Egearmand: an Erlang Gearman daemonEgearmand: an Erlang Gearman daemon
Egearmand: an Erlang Gearman daemon
 
Parllelizaion
ParllelizaionParllelizaion
Parllelizaion
 
Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick review
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)
 
Medical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUsMedical Image Processing Strategies for multi-core CPUs
Medical Image Processing Strategies for multi-core CPUs
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
 
Open mp library functions and environment variables
Open mp library functions and environment variablesOpen mp library functions and environment variables
Open mp library functions and environment variables
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
 
Supporting Arrays and Allocatables in LFortran
Supporting Arrays and Allocatables in LFortranSupporting Arrays and Allocatables in LFortran
Supporting Arrays and Allocatables in LFortran
 
Lecture7
Lecture7Lecture7
Lecture7
 
Threads
ThreadsThreads
Threads
 

Más de Piyush Mittal

Más de Piyush Mittal (20)

Power mock
Power mockPower mock
Power mock
 
Design pattern tutorial
Design pattern tutorialDesign pattern tutorial
Design pattern tutorial
 
Reflection
ReflectionReflection
Reflection
 
Gpu archi
Gpu archiGpu archi
Gpu archi
 
Cuda Architecture
Cuda ArchitectureCuda Architecture
Cuda Architecture
 
Intel open mp
Intel open mpIntel open mp
Intel open mp
 
Intro to parallel computing
Intro to parallel computingIntro to parallel computing
Intro to parallel computing
 
Cuda toolkit reference manual
Cuda toolkit reference manualCuda toolkit reference manual
Cuda toolkit reference manual
 
Matrix multiplication using CUDA
Matrix multiplication using CUDAMatrix multiplication using CUDA
Matrix multiplication using CUDA
 
Channel coding
Channel codingChannel coding
Channel coding
 
Basics of Coding Theory
Basics of Coding TheoryBasics of Coding Theory
Basics of Coding Theory
 
Java cheat sheet
Java cheat sheetJava cheat sheet
Java cheat sheet
 
Google app engine cheat sheet
Google app engine cheat sheetGoogle app engine cheat sheet
Google app engine cheat sheet
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheet
 
Vi cheat sheet
Vi cheat sheetVi cheat sheet
Vi cheat sheet
 
Css cheat sheet
Css cheat sheetCss cheat sheet
Css cheat sheet
 
Cpp cheat sheet
Cpp cheat sheetCpp cheat sheet
Cpp cheat sheet
 
Ubuntu cheat sheet
Ubuntu cheat sheetUbuntu cheat sheet
Ubuntu cheat sheet
 
Php cheat sheet
Php cheat sheetPhp cheat sheet
Php cheat sheet
 
oracle 9i cheat sheet
oracle 9i cheat sheetoracle 9i cheat sheet
oracle 9i cheat sheet
 

Último

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 

Último (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

Open MP cheet sheet

  • 1. OpenMP Reference Sheet for C/C++ <A,B,C such that total iterations known at start of loop> for(A=C;A<B;A++) { <your code here> Constructs <force ordered execution of part of the code. A=C will be guaranteed to execute <parallelize a for loop by breaking apart iterations into chunks> before A=C+1> #pragma omp parallel for [shared(vars), private(vars), firstprivate(vars), #pragma omp ordered { lastprivate(vars), default(shared|none), reduction(op:vars), copyin(vars), if(expr), <your code here> ordered, schedule(type[,chunkSize])] } <A,B,C such that total iterations known at start of loop> } for(A=C;A<B;A++) { <your code here> <parallelized sections of code with each section operating in one thread> #pragma omp sections [private(vars), firstprivate(vars), lastprivate(vars), <force ordered execution of part of the code. A=C will be guaranteed to execute reduction(op:vars), nowait] { before A=C+1> #pragma omp section { #pragma omp ordered { <your code here> <your code here> } } #pragma omp section { } <your code here> } <parallelized sections of code with each section operating in one thread> .... #pragma omp parallel sections [shared(vars), private(vars), firstprivate(vars), } lastprivate(vars), default(shared|none), reduction(op:vars), copyin(vars), if(expr)] { #pragma omp section { <only one thread will execute the following. NOT always by the master thread> <your code here> #pragma omp single { } <your code here (only executed once)> #pragma omp section { } <your code here> } } .... } Directives shared(vars) <share the same variables between all the threads> <grand parallelization region with optional work-sharing constructs defining more private(vars) <each thread gets a private copy of variables. Note that other than the specific splitting of work and variables amongst threads. You may use work-sharing master thread, which uses the original, these variables are not initialized to constructs without a grand parallelization region, but it will have no effect (sometimes anything.> useful if you are making OpenMP'able functions but want to leave the creation of threads firstprivate(vars) <like private, but the variables do get copies of their master thread to the user of those functions)> values> #pragma omp parallel [shared(vars), private(vars), firstprivate(vars), lastprivate(vars), lastprivate(vars) <copy back the last iteration (in a for loop) or the last section (in a default(private|shared|none), reduction(op:vars), copyin(vars), if(expr)] { sections) variables to the master thread copy (so it will persist even after the <the work-sharing constructs below can appear in any order, are optional, and can parallelization ends)> be used multiple times. Note that no new threads will be created by the constructs. default(private|shared|none) <set the default behavior of variables in the parallelization They reuse the ones created by the above parallel construct.> construct. shared is the default setting, so only the private and none setting have effects. none forces the user to specify the behavior of variables. Note that even with <your code here (will be executed by all threads)> shared, the iterator variable in for loops still is private by necessity > reduction(op:vars) <vars are treated as private and the specified operation(op, which <parallelize a for loop by breaking apart iterations into chunks> can be +,*,-,&,|,&,&&,||) is performed using the private copies in each thread. The #pragma omp for [private(vars), firstprivate(vars), lastprivate(vars), master thread copy (which will persist) is updated with the final value.> reduction(op:vars), ordered, schedule(type[,chunkSize]), nowait]
  • 2. copyin(vars) <used to perform the copying of threadprivate vars to the other threads. Similar to firstprivate for private vars.> if(expr) <parallelization will only occur if expr evaluates to true.> schedule(type [,chunkSize]) <thread scheduling model> Function Based Locking < nest versions allow recursive locking> type chunkSize void omp_init_[nest_]lock(omp_lock_t*) <make a generic mutex lock> static number of iterations per thread pre-assigned at beginning of loop void omp_destroy_[nest_]lock(omp_lock_t*) <destroy a generic mutex lock> (typical default is number of processors) void omp_set_[nest_]lock(omp_lock_t*) <block until mutex lock obtained> void omp_unset_[nest_]lock(omp_lock_t*) <unlock the mutex lock> dynamic number of iterations to allocate to a thread when available (typical int omp_test_[nest_]lock(omp_lock_t*) <is lock currently locked by somebody> default is 1) guided highly dependent on specific implementation of OpenMP nowait <remove the implicit barrier which forces all threads to finish before continuation Settings and Control in the construct> int omp_get_num_threads() <returns the number of threads used for the parallel region in which the function was called> int omp_get_thread_num() <get the unique thread number used to handle this iteration/section of a parallel construct. You may break up algorithms into parts based on this number.> Synchronization/Locking Constructs <May be used almost anywhere, but will int omp_in_parallel() <are you in a parallel construct> only have effects within parallelization constructs.> int omp_get_max_threads() <get number of threads OpenMP can make> int omp_get_num_procs() <get number of processors on this system> <only the master thread will execute the following. Sometimes useful for special handling int omp_get_dynamic() <is dynamic scheduling allowed> of variables which will persist after the parallelization.> int omp_get_nested() <is nested parallelism allowed> #pragma omp master { double omp_get_wtime() <returns time (in seconds) of the system clock> <your code here (only executed once and by the master thread). double omp_get_wtick() <number of seconds between ticks on the system clock> } void omp_set_num_threads(int) <set number of threads OpenMP can make> void omp_set_dynamic(int) <allow dynamic scheduling (note this does not make <mutex lock the region. name allows the creation of unique mutex locks.> dynamic scheduling the default)> #pragma omp critical [(name)] { void omp_set_nested(int) <allow nested parallelism; Parallel constructs within other <your code here (only one thread allowed in at a time)> parallel constructs can make new threads (note this tends to be unimplemented } in many OpenMP implementations)> <force all threads to complete their operations before continuing> <env vars- implementation dependent, but here are some common ones> #pragma omp barrier OMP_NUM_THREADS "number" <maximum number of threads to use> OMP_SCHEDULE "type,chunkSize" <default #pragma omp schedule settings> <like critical, but only works for simple operations and structures contained in one line of code> #pragma omp atomic <simple code operation, ex. a += 3; Typical supported operations are ++,--,+,*,- ,/,&,^,<<,>>,| on primitive data types> Legend vars is a comma separated list of variables <force a register flush of the variables so all threads see the same memory> [optional parameters and directives] #pragma omp flush[(vars)] <descriptions, comments, suggestions> .... above directive can be used multiple times <applies the private clause to the vars of any future parallelize constructs encountered (a For mistakes, suggestions, and comments please email e_berta@plutospin.com convenience routine)> #pragma omp threadprivate(vars)