KEMBAR78
Work-Sharing Constructs Loop Construct | PDF | Programming Paradigms | Computer Science
0% found this document useful (0 votes)
70 views9 pages

Work-Sharing Constructs Loop Construct

The document discusses loop work-sharing constructs in OpenMP. It explains that the loop construct specifies that loop iterations will be shared in parallel by all threads. It provides the syntax for the loop construct using #pragma omp parallel and #pragma omp for directives. The loop iterations can be split across threads using these pragmas. It also shows how the pragmas can be combined into a single #pragma omp parallel for directive.

Uploaded by

Variable 14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views9 pages

Work-Sharing Constructs Loop Construct

The document discusses loop work-sharing constructs in OpenMP. It explains that the loop construct specifies that loop iterations will be shared in parallel by all threads. It provides the syntax for the loop construct using #pragma omp parallel and #pragma omp for directives. The loop iterations can be split across threads using these pragmas. It also shows how the pragmas can be combined into a single #pragma omp parallel for directive.

Uploaded by

Variable 14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Work-sharing constructs:

Loop Construct

Dr M Rajasekhara Babu
Vellore Institute of Technology (VIT)
Vellore-632014, Tamil Nadu, India
Outline
Session objectives

About work-sharing construct

Loop work-sharing construct

Sample Program Demo

Summary

Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 2


Objectives
To provide knowledge on
OpenMP

To Combine serial and


parallel codes by using
various constructs

To create threaded codes


by using OpenMP
pragmas.
Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 3
 About Work-sharing constructs Work-sharing constructs
• There are three types worksharing
constructs
– loop construct
– sections construct
– single construct
• Restrictions
– Each worksharing region must be encountered
by all threads in a team or by none at all
– The sequence of worksharing regions and
barrier regions encountered must be the same
for every thread in a team.
Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 4
 About Work-sharing constructs Loop Construct
 Loop work-sharing construct
• Loop Construct
– The loop construct specifies that the iterations
of one or more associated loops will be shared
in parallel by all threads.
• FOR
– Splits loop iterations into threads
– Must be in the parallel region
– Must precede the loop

Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 5


 About Work-sharing constructs
 Loop work-sharing construct
FOR-Loop Construct
– Syntax with two pragmas
• Syntax
#pragma omp parallel
#pragma omp parallel
#pragma omp for
for(i=0; i<N; i++) #pragma omp for

{ i=0 i=3 i=6 i=9


Do_Work(i); i=1 i=4 i=7 i = 10
i=2 i=5 i=8 i = 11
}
• Example Implicit barrier

#pragma omp parallel


#pragma omp for
for(i = 0; i < 12; i++)
c[i] = a[i] + b[i]
Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 6
 About Work-sharing constructs
 Loop work-sharing construct
FOR-Loop Construct
– Syntax with two pragmas
– Combining programs into single pragma
• Combining pragmas
#pragma omp parallel
{
#pragma omp for
for (i=0; i< MAX; i++) {
res[i] = huge();
}
}

#pragma omp parallel for


for (i=0; i< MAX; i++) {
res[i] = huge();
}

Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 7


 About Work-sharing constructs
 Loop work-sharing construct
OpenMP program Demo
– Syntax with two pragmas
– Combining programs into single pragma
– Demo

Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 8


Summary
• About Work-sharing constructs
• Loop work-sharing construct
– Syntax with two pragmas
#pragma omp parallel
#pragma omp for
for()
{ }
– Combining programs into single pragma
#pragma omp parallel for
for()
{ }
• Demo
Dr M Rajasekhara Babu, Vellore Institute of Technology (VIT)-Vellore Slide.# 9

You might also like