---
# System prepended metadata

title: Assignment 2 Report
tags: [Parallel Programming]

---

###### tags: `Parallel Programming`
# Assignment 2 Report
`0811510 許承壹`
> Q1: In your write-up, produce a graph of speedup compared to the reference sequential implementation as a function of the number of threads used FOR VIEW 1. Is speedup linear in the number of threads used? In your writeup hypothesize why this is (or is not) the case? (You may also wish to produce a graph for VIEW 2 to help you come up with a good answer. Hint: take a careful look at the three-thread data-point.)

* Graph of speedup for VIEW1
![](https://i.imgur.com/PUmfnQh.png)



* Graph of speed up for VIEW2
![](https://i.imgur.com/Jv838LS.png)


* From the above results, we see that the speedup is almost linear when the number of threads increases, since we distribute the loading the drawing graph evenly. However, the efficiency gets worse when you have more threads, meaning that your OS gets more burdens on scheduling the threads, so the speedup cannot be totally linear.

:::danger
view1不會是linear,
你似乎沒有用先用照作業說明的2.2requirement,先用區塊做分工
by TA
:::



> Q2: How do your measurements explain the speedup graph you previously created?
 

1. Only one thread, Repeat the experiment 5 times:
![](https://i.imgur.com/O0bYrVZ.png)
2. Two threads, Repeat the experiment 5 times::
![](https://i.imgur.com/VnAgPK6.png)
3. Three threads, Repeat the experiment 5 times::
![](https://i.imgur.com/a16F90z.png)
4. Four threads, Repeat the experiment 5 times::
![](https://i.imgur.com/BvcMBAD.png)

* From the above results, we can see that the threads share the loading evenly, so the speed up is almost linear.
 > Q3: In your write-up, describe your approach to parallelization and report the final 4-thread speedup obtained.

```cpp=
int step = args->numThreads;
    for(int i = args->threadId; i < args->height; i+=step)
    {
        mandelbrotSerial(args->x0, args->y0, args->x1, args->y1, args->width, args->height, i, 1, args->maxIterations, args->output);
    }
```
* I distribute the loading to the threads cyclically, and finally achieve 3.94x speedup with respect to 4-thread.

> Q4: Now run your improved code with eight threads. Is performance noticeably greater than when running with four threads? Why or why not? (Notice that the workstation server provides 4 cores 4 threads.)

* The speedup for 8 threads is 3.74, which is even worse than using 4 threads. Since the workstation server provides 4 cores 4 threads, and if we use 8 threads, then the OS would have more burdens on scheduling, and hence the performance is not better.