---
tags: parallel_programming
---
# Parallel programming HW2
## Q1:
### Is speedup linear in the number of threads used? In your writeup hypothesize why this is (or is not) the case?

> - Refer to the graph above, the speedup is almost linear.
> - Since all threads doing same thing, using more thread will reduce the loading of threads, which decrease the execution time linearly.

> - Speedup is also almost linear too.
---
## Q2:
### How do your measurements explain the speedup graph you previously created?
```cpp
double start = CycleTimer::currentTime();
/*
* code of copy arguments
*/
double end = CycleTimer::currentTime();
double execTime = end - start;
```
- Adding code above to measure the copy time, copy operations take about $10^{-8}$ second.
- Since the thread amount is small, the copy time won't dominate the execution time. Therefore, the speedup should be linear.
---
## Q3:
### In your write-up, describe your approach to parallelization and report the final 4-thread speedup obtained.
- The thread would do `mandelbrotSerial` every `numThreads` rows, which starts from `threadId` row. For instance, thread0 would calculate row {`0`, `0+numThreads`, `0+numThreads*2`, ...etc}
- The speedup of 4-thread is `3.81` in view1, and `3.79` in view2.
---
## 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.)
- No, since the machine have only 4 hardware threads available, creating more software thread could not increase parallelism.