To-do 18¶
What should you prepare before the session?
Practice your skills by reviewing the previous sessions¶
Topic 2: Go language¶
- many workers with Goroutines
- shared memory between workers (race conditions, mutex, rw-mutex, example: bank account with shared variables)
- message passing with Go channels (unbuffered, buffered, and unidirectional channels, multiplexing, example: bank account with channels)
- performance and scalability
- case studies with parallel algorithms (matrix-matrix multiplication, histogram)
Practice implementing math formulas/problems in Go¶
Implement the dot product of two vectors \(\mathbf{a}, \mathbf{b} \in \mathbb{R}^n\),
\[
\mathbf{a} \cdot \mathbf{b} = \sum_{i=0}^{n-1} a_i \, b_i,
\]
in three different ways using concurrency in Go:
- Use goroutines only, but no mutex and no channels (wait groups are ok to use)
- Use goroutines and mutex. Where in the code can the lock be applied and what are the performance implications?
- Use goroutines and channels. How can the closing of the channel be used to signal that the goroutine workers finished computing their contributions to the total result?