What is vector addition in mathematical terms?
c = a + b where c_i = a_i + b_i for i = 1 to n
What is the serial implementation of vector addition?
for(i=0; i<n; i++) c[i] = a[i] + b[i];
How does OpenMP parallelize vector addition?
Add #pragma omp parallel for before the loop
What is the fork-join construct in OpenMP?
Main thread spawns worker threads (fork), threads execute loop in parallel, then join back to main thread
What are the limitations of #pragma omp parallel for?
Requires known loop trip count at start, constant start/end/stride, no break statements, no while/do-while loops
What is a data parallel problem?
Problems where the same operation is applied to multiple data elements independently
What is an embarrassingly parallel problem?
A data parallel problem that is straightforward to parallelize with minimal overhead
What is the Mandelbrot set used for benchmarking?
Computational intensity and visualization - each pixel calculated independently
What is the problem with parallelizing the outer loop in Mandelbrot?
Shared variable i gets updated by multiple threads, causing skipped pixels and distorted images
What are the solutions for the Mandelbrot parallelization problem?
1) Declare i inside the loop (private to each thread), 2) Use OpenMP’s private(i) clause
What is the collapse clause in OpenMP?
Combines nested loops into a single loop for better load balancing: #pragma omp parallel for collapse(2)
What is non-determinism in parallel programs?
Results that differ between program runs due to thread scheduling and interleaving
What causes non-determinism in the incorrect Mandelbrot implementation?
Thread scheduler determines order of i increments, causing different pixel calculation orders
Why might non-determinism sometimes be acceptable?
Some algorithms tolerate small non-deterministic errors (e.g. in science/engineering) if results are still valid
What is the trade-off with enforcing determinism?
Additional synchronization overhead may reduce performance
What are the three main types of loop dependencies?
Flow dependencies (read after write), anti-dependencies (write after read), output dependencies (write after write)
What is the solution for flow dependencies in loops?
Use temporary arrays or change algorithm to remove dependency
What is red-black Gauss-Seidel?
Modified Gauss-Seidel where even elements are updated first, then odd elements, removing dependencies within each phase
What is the key insight of red-black Gauss-Seidel?
Dependencies only exist between even and odd elements, not within the same parity group