SlideShare ist ein Scribd-Unternehmen logo
1 von 2
Downloaden Sie, um offline zu lesen
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)

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Piyush Mittal

Mehr von 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
 

Kürzlich hochgeladen

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Kürzlich hochgeladen (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

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)