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
| Line 41: | Line 41: | ||
<div style="margin-left: 1em;"><code> #pragma omp task</code></div> | <div style="margin-left: 1em;"><code> #pragma omp task</code></div> | ||
<div style="margin-left: 1em;"><code> {</code></div> | <div style="margin-left: 1em;"><code> {</code></div> | ||
| − | <div style="margin-left: 2em;"><code> y += x;</code></div> | + | <div style="margin-left: 2em;"><code> #pragma omp critical</code></div> |
| + | <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> | <div style="margin-left: 1em;"><code> }</code></div> | ||
<code>}</code><br/> | <code>}</code><br/> | ||
| Line 69: | Line 72: | ||
<div style="margin-left: 2em;"><code> #pragma omp task</code></div> | <div style="margin-left: 2em;"><code> #pragma omp task</code></div> | ||
<div style="margin-left: 2em;"><code> {</code></div> | <div style="margin-left: 2em;"><code> {</code></div> | ||
| − | <div style="margin-left: 3em;"><code> y += x;</code></div> | + | <div style="margin-left: 3em;"><code> #pragma omp critical</code></div> |
| + | <div style="margin-left: 3em;"><code> {</code></div> | ||
| + | <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: 2em;"><code> }</code></div> | ||
<div style="margin-left: 1em;"><code> }</code></div> | <div style="margin-left: 1em;"><code> }</code></div> | ||
Revision as of 18:16, 30 November 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 | |
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 and what is printed?
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 and what is printed?
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 and what is printed?