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 parallel on outer loop to pre-fork threads

  • Use #pragma omp for on inner layers

  • Barriers and critical sections