Module 4: OpenMP Case Study: N-body problem¶
The problem¶
Simulate the motion of stars, planets, etc.
Math¶
Divide time to small sections. Calculate physical variables at every time stop progressively.
Serial Solution¶
Two layer of nested loops. One outer loop and multiple inner loops. Data dependency exists between loops in the inner layer.
OpenMP Optimization¶
Optimize inner layer loops
Use
#pragma omp parallelon outer loop to pre-fork threadsUse
#pragma omp foron inner layersBarriers and critical sections