Skip to content
Snippets Groups Projects
Commit 40cc7307 authored by Georgiana Mania's avatar Georgiana Mania
Browse files

use Dominik's coding icon for C++

parent e30cf802
No related branches found
No related tags found
1 merge request!72Draft: Compute devices lecture
......@@ -63,7 +63,7 @@ FIXME
* OpenMP uses something called threads
* Wait until next week for a definition
```c
```c++
#pragma omp parallel for
for (int i = 0; i < N; ++i)
a[i] = 2 * i;
......@@ -149,13 +149,13 @@ Starting with batter for $N$ pancakes and 1 pan, we can scale by using $P$ pans
# Reductions FIXME title should be more generic
## What is happening here?
```c
```c++
int a[] = {2, 4, 6};
for (int i = 0; i < N; ++i)
sum = sum + a[i];
```
## What is happening here?
```c
```c++
int a[] = {2, 4, 6};
#pragma omp parallel for
for (int i = 0; i < N; ++i)
......@@ -164,7 +164,7 @@ Starting with batter for $N$ pancakes and 1 pan, we can scale by using $P$ pans
[comment]: # (Can something go wrong?)
## Solution
```c
```c++
int a[] = {2, 4, 6};
#pragma omp parallel for reduction(+:sum)
for (int i = 0; i < N; ++i)
......@@ -173,7 +173,7 @@ Starting with batter for $N$ pancakes and 1 pan, we can scale by using $P$ pans
# Doing stuff wrong
## What is going wrong here?
```c
```c++
temp = 0;
#pragma omp parallel for
for (int i = 0; i < N; ++i) {
......@@ -182,7 +182,7 @@ Starting with batter for $N$ pancakes and 1 pan, we can scale by using $P$ pans
}
```
## Solution
```c
```c++
temp = 0;
#pragma omp parallel for private(temp)
for (int i = 0; i < N; ++i) {
......@@ -212,8 +212,16 @@ FIXME: Citation correct?!
## Precondition for parallel execution
<br>
*"Two consecutive instructions or code segments can be executed in parallel if they are **independent**."*
<br>
:::{.fragment .info .smaller}
What does **dependence** mean?
:::
## Code and data dependence {.leftalign}
......@@ -222,7 +230,7 @@ FIXME: Citation correct?!
:::
:::{.fragment .fade-in-then-semi-out fragment-index=2}
```c
```c++
a = b;
c = a + b; // flow dependence
```
......@@ -233,7 +241,7 @@ c = a + b; // flow dependence
:::
:::{.fragment .fade-in-then-semi-out fragment-index=4}
```c
```c++
for (int i = 1; i < n ; i++) {
a[i] = (a[i-1] > a[i]) ? a[i] + 1 : 1;
}
......@@ -245,7 +253,7 @@ for (int i = 1; i < n ; i++) {
:::
:::{.fragment .fade-in-then-semi-out fragment-index=6}
```c
```c++
a = b;
b = 42; // read after write: a has an old value
```
......@@ -257,7 +265,7 @@ b = 42; // read after write: a has an old value
For data dependence, use the Bernstein's conditions: *"the intersection between read-write set, write-read set and write-write set of instructions is null"*.
:::{.fragment}
```c
```c++
c = a + b; // S1
d = a - b; // S2
```
......@@ -302,7 +310,7 @@ S1 and S2 can be executed in parallel!
:::{.notes}
How about these two? replace a in S2 with c
```c
```c++
c = a + b; // S1
d = c - b; // S2
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment