TutorialsTutorials HomeOpenMPIndexIntroduction PARALLEL DO PARALLEL DO SECTIONS SINGLE MASTER CRITICAL BARRIER FLUSH ATOMIC ORDERED
FullDocument
Related InfoOpenMP Home Page
|
IntroductionThis tutorial will take you through the OpenMP directives, starting with the most basic and useful directives. Execution ModelA program that is written using OpenMP directives begins execution as a single process, called the master thread of execution. The master thread executes sequentially until the first parallel construct is encountered. The PARALLEL / END PARALLEL directive pair constitutes the parallel construct. When a parallel construct is encountered, the master thread creates a team of threads, and the master becomes the master of the team. The program statements that are enclosed in a parallel construct, including routines called from within the construct, are executed in parallel by each thread in the team. Upon completion of the parallel construct, the threads in the team synchronize and only the master thread continues execution. Any number of parallel constructs can be specified in a single program. As a result, a program may fork and join many times during execution. The degree of parallelism an OpenMP code is dependent on the code, the platform, the hardware configuration, the compiler, and the operating system. In no case are you guaranteed to have each thread running on a separate processor. The Cray XT4 will only allow you to specify a number of threads less than or equal to the number of processor cores on a node. The franklin compute nodes all have four cores, so you can execute 1, 2, 3, or 4 threads on them. You are only allowed to run OpenMP codes on franklin on compute nodes with a pbs script. ExamplesExamples using OpenMP can be copied to your $HOME/openmp_examples directory on franklin by using: % cd $HOME % mkdir openmp_examples % module load training % cp $EXAMPLES/OpenMP/tutorial/* openmp_examples OpenMP Directive SyntaxOpenMP directives are inserted directly into source code. Free-form Fortran source code directives begin with the sentinel !$OMP. Fixed-form Fortran source code directives begin with the sentinels !$OMP, C$OMP, or *$OMP. Sentinels must start in column one. Continuation lines are permitted using the same format as the Fortran source code format you are using (free or fixed). Following are descriptions of the basic use of OpenMP directives with examples. |
![]() |
Page last modified: Mon, 11 Jan 2010 21:29:39 GMT Page URL: http://www.nersc.gov/nusers/help/tutorials/openmp/intro.php Web contact: webmaster@nersc.gov Computing questions: consult@nersc.gov Privacy and Security Notice |
![]() |