Difference between revisions of "OpenMP in Small Bites/Tasking and Data Scoping"
OpenMP in Small Bites/Tasking and Data Scoping
Jump to navigation
Jump to search
m (Tweak page sporting and title) |
|||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:Tutorials]]<nowiki /> | + | [[Category:Tutorials|Tasking and Data Scoping (OpenMP)]]<nowiki /> |
+ | {{DISPLAYTITLE:Tasking and Data Scoping (OpenMP)}}<nowiki /> | ||
{{Syllabus OpenMP in Small Bites}}<nowiki /> | {{Syllabus OpenMP in Small Bites}}<nowiki /> | ||
__TOC__ | __TOC__ | ||
+ | This video deepens the knowledge of OpenMP Tasking and Data Scoping by using an example which includes typical scenarios. Furthermore, aspects of the lifetime of a variable are discussed. | ||
== Video == | == Video == | ||
<youtube width="600" height="340" right>sK11P-AfUCM</youtube> | <youtube width="600" height="340" right>sK11P-AfUCM</youtube> | ||
+ | |||
+ | |||
+ | ([[Media:hpc.nrw_06_Introduction-TaskingAndScoping.pdf | Slides as pdf]]) | ||
== Quiz == | == Quiz == | ||
Line 14: | Line 19: | ||
<code>#pragma omp parallel private(x)</code><br/> | <code>#pragma omp parallel private(x)</code><br/> | ||
<code>{</code><br/> | <code>{</code><br/> | ||
− | <code> #pragma omp task</code>< | + | <div style="margin-left: 1em;"><code> #pragma omp task</code></div> |
− | <code> {</code>< | + | <div style="margin-left: 1em;"><code> {</code></div> |
− | <code> x = 3;</code>< | + | <div style="margin-left: 2em;"><code> x = 3;</code></div> |
− | <code> }</code>< | + | <div style="margin-left: 1em;"><code> }</code></div> |
<code>}</code><br/> | <code>}</code><br/> | ||
<code>printf("x=%d\n", x);</code><br/> | <code>printf("x=%d\n", x);</code><br/> | ||
− | What is the data scope of <code>x</code> and what is printed? | + | What is the data scope of <code>x</code> in the task region and what is printed at the end? |
}} | }} | ||
<quiz display=simple> | <quiz display=simple> | ||
Line 39: | Line 44: | ||
<code>#pragma omp parallel num_threads(4)</code><br/> | <code>#pragma omp parallel num_threads(4)</code><br/> | ||
<code>{</code><br/> | <code>{</code><br/> | ||
− | <code> #pragma omp task</code>< | + | <div style="margin-left: 1em;"><code> #pragma omp task</code></div> |
− | <code> {</code>< | + | <div style="margin-left: 1em;"><code> {</code></div> |
− | <code> y += x;</code>< | + | <div style="margin-left: 2em;"><code> #pragma omp critical</code></div> |
− | <code> }</code>< | + | <div style="margin-left: 2em;"><code> {</code></div> |
+ | <div style="margin-left: 3em;"><code> y += x;</code></div> | ||
+ | <div style="margin-left: 2em;"><code> }</code></div> | ||
+ | <div style="margin-left: 1em;"><code> }</code></div> | ||
<code>}</code><br/> | <code>}</code><br/> | ||
<code>printf("y=%d\n", y);</code><br/> | <code>printf("y=%d\n", y);</code><br/> | ||
− | What is the data scope of <code>x</code> and what is printed? | + | What is the data scope of <code>x</code> in the task region and what is printed out at the end? |
}} | }} | ||
Line 65: | Line 73: | ||
<code>#pragma omp parallel num_threads(4)</code><br/> | <code>#pragma omp parallel num_threads(4)</code><br/> | ||
<code>{</code><br/> | <code>{</code><br/> | ||
− | <code> #pragma omp single</code>< | + | <div style="margin-left: 1em;"><code> #pragma omp single</code></div> |
− | <code> {</code>< | + | <div style="margin-left: 1em;"><code> {</code></div> |
− | <code> #pragma omp task</code>< | + | <div style="margin-left: 2em;"><code> #pragma omp task</code></div> |
− | <code> {</code>< | + | <div style="margin-left: 2em;"><code> {</code></div> |
− | <code> y += x;</code>< | + | <div style="margin-left: 3em;"><code> #pragma omp critical</code></div> |
− | <code> }</code>< | + | <div style="margin-left: 3em;"><code> {</code></div> |
− | <code> }</code>< | + | <div style="margin-left: 4em;"><code> y += x;</code></div> |
+ | <div style="margin-left: 3em;"><code> }</code></div> | ||
+ | <div style="margin-left: 2em;"><code> }</code></div> | ||
+ | <div style="margin-left: 1em;"><code> }</code></div> | ||
<code>}</code><br/> | <code>}</code><br/> | ||
<code>printf("y=%d\n", y);</code><br/> | <code>printf("y=%d\n", y);</code><br/> | ||
− | What is the data scope of <code>x</code> and what is printed? | + | What is the data scope of <code>x</code> in the task region and what is printed out at the end? |
}} | }} | ||
<quiz display=simple> | <quiz display=simple> |
Latest revision as of 16:40, 4 December 2020
Tutorial | |
---|---|
Title: | OpenMP in Small Bites |
Provider: | HPC.NRW
|
Contact: | tutorials@hpc.nrw |
Type: | Multi-part video |
Topic Area: | Programming Paradigms |
License: | CC-BY-SA |
Syllabus
| |
1. Overview | |
2. Worksharing | |
3. Data Scoping | |
4. False Sharing | |
5. Tasking | |
6. Tasking and Data Scoping | |
7. Tasking and Synchronization | |
8. Loops and Tasks | |
9. Tasking Example: Sudoku Solver | |
10. Task Scheduling | |
11. Non-Uniform Memory Access |
This video deepens the knowledge of OpenMP Tasking and Data Scoping by using an example which includes typical scenarios. Furthermore, aspects of the lifetime of a variable are discussed.
Video
Quiz
1. Consider the following code snippet
int x = 42;
#pragma omp parallel private(x)
{
#pragma omp task
{
x = 3;
}
}
printf("x=%d\n", x);
x
in the task region and what is printed at the end?
2. Consider the following code snippet
int x = 42;
int y = 0;
#pragma omp parallel num_threads(4)
{
#pragma omp task
{
#pragma omp critical
{
y += x;
}
}
}
printf("y=%d\n", y);
x
in the task region and what is printed out at the end?
3. Consider the following code snippet
int x = 42;
int y = 0;
#pragma omp parallel num_threads(4)
{
#pragma omp single
{
#pragma omp task
{
#pragma omp critical
{
y += x;
}
}
}
}
printf("y=%d\n", y);
x
in the task region and what is printed out at the end?