{%hackmd theme-dark %}
# POSIX threads hw report
##### tags: `homework` `posix`
F74096336 陳振皓
## What I have done
* I used Condition Variable to implement my barrier
* I distribute work to n threads by having each thread do roughly total_rows/n. (remainder are distributed starting from thread 0)
* In each thread:
1. Calculate how many local_rows it should do and starting from which row.
2. barrier.
3. Smoothing.
4. Wait for each thread to complete.
5. Repeat 2~4 1000 times.
* Save output
* Record execution time
## Result Analysis
| number of threads | time NSmooth=100 | time NSmooth=500 | time NSmooth=1000 |
| ----------------- |:---------------- |:---------------- |:----------------- |
| 1 | 4s | 29s | 68s |
| 2 | 2s | 13s | 53s |
| 4 | 1s | 8s | 38s |
| 8 | 1s | 6s | 17s |
| 16 | 0s | 9s | 11s |
| 32 | 0s | 9s | 14s |