Beruflich Dokumente
Kultur Dokumente
Topics:
1. OpenMP Implementation in C
2. Directives
2.3.Parallel Construct
1. Open MP Implementation in C
Advantageous because:
a) Use structural parallel programming efficiency.
b) Compiler has control so simple to use.
c) Can be run on different domain.
Priva
te Priva
Shared memory te
T
T
T
Priva Priva
te te
Priva
te
Synchronized
processors
Communicatin
Shared memory g
parallel Shared via
programming memory shared
variable
2. Directives
Syntax-> if (expression)
If the given expression is true then the process continues otherwise
it is run by only one thread.
2. Num_threads Clause:
Syntax: num_threads(scalar_integer_expression)
It supports the number of threads used in the parallel code of
program. It always gives the integer number.
3. Copying Clause: Copy the private variables of initial thread to the
private variables of other threads copying.
4. Flush Clause: Goal is to make a thread’s a temporary view of
shared data consistent with the values in memory.
#pragma omp flush [(list)]
Section Construct
• The section constructs are included in the sections derivative.
• It is non iterative construct.
• It declares a set of constructs that are to be distributed among the
team members. Each section is executed once by a thread in the team.
• Each section preceded by a section directive and the section directive
is optional for the first section.
• The section directive must appear within the lexical extent of the
sections direfctive.
• Syntax
#pragma omp sections [clause [[,] clause]…] new line
{
[#pragma omp section new line]
structured block
[#pragma omp section new line]
structured block
-----
-----
}
• Whole program is divided into sections; each section is run by single
thread. Each section runs independently of other sections. Multiple threads
concurrently handle the multiple sections sometimes.
• If threads are more than sections, then threads become idle, they have
no section to run.
• The clause may be one of the following:
private (variable list)
first private (variable list)
last private (variable list)
reduction (operator: variable list)
nowait
• Restriction to the section directive are:
1. A ‘section’ directive must appear within the lexical extent of the
sections directive.
2. Only a single ‘nowait’ clause can appear on a sections directive.
Single construct
• Single construct is hold by the single directive. It specifies that the
associated structured block is specified by only one thread in the team.
#pragma omp sections [clause [[,] clause]…] new line
structured block
• The meaning of this directive is similar to those of both parallel and work
sharing construct.
This directive allows all the clauses of parallel directive and for
directive except the nowait clause.
Syntax:
for loop
Syntax:
structured block
structured block
-----
-----