Skip to content

Commit f4b1e5e

Browse files
committed
Added parallel comp homework (HW09).
1 parent 6acc3c7 commit f4b1e5e

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

docs/src/lecture_10/hw.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
11
# [Homework 9: Something parallel](@id hw09)
2-
Will be published somewhere during the weekend.
2+
3+
## How to submit
4+
Put all the code of inside `hw.jl`. Zip only this file (not its parent folder) and upload it to BRUTE. You should not not import anything but `Base.Threads` or just `Threads`.
5+
6+
```@raw html
7+
<div class="admonition is-category-homework">
8+
<header class="admonition-header">Homework (2 points)</header>
9+
<div class="admonition-body">
10+
```
11+
Implement *multithreaded* discrete 1D convolution operator[^1] without padding (output will be shorter). The required function signature: `thread_conv1d(x, w)`, where `x` is the signal array and `w` the kernel. For testing correctness of the implementation you can use the following example of a step function and it's derivative realized by kernel `[-1, 1]`:
12+
```julia
13+
using Test
14+
@test all(thread_conv1d(vcat([0.0, 0.0, 1.0, 1.0, 0.0, 0.0]), [-1.0, 1.0]) .≈ [0.0, -1.0, 0.0, 1.0, 0.0])
15+
```
16+
[^1]: Discrete convolution with finite support [https://en.wikipedia.org/wiki/Convolution#Discrete\_convolution](https://en.wikipedia.org/wiki/Convolution#Discrete_convolution)
17+
18+
Your parallel implementation will be tested both in sequential and two threaded mode with the following inputs
19+
```julia
20+
using Random
21+
Random.seed!(42)
22+
x = rand(10_000_000)
23+
w = [1.0, 2.0, 4.0, 2.0, 1.0]
24+
@btime thread_conv1d($x, $w);
25+
```
26+
On your local machine you should be able to achieve `0.6x` reduction in execution time with two threads, however the automatic eval system is a noisy environment and therefore we require only `0.8x` reduction therein. This being said, please reach out to us, if you encounter any issues.
27+
28+
**HINTS**:
29+
- start with single threaded implementation
30+
- don't forget to reverse the kernel
31+
- `@threads` macro should be all you need
32+
- for testing purposes create a simple script, that you can run with `julia -t 1` and `julia -t 2`
33+
34+
```@raw html
35+
</div></div>
36+
<details class = "solution-body" hidden>
37+
<summary class = "solution-header">Solution:</summary><p>
38+
```
39+
40+
Nothing to see here
41+
42+
```@raw html
43+
</p></details>
44+
```

0 commit comments

Comments
 (0)