Skip to content

Add challenge 74: N-body Gravitational Force (Medium)#196

Open
claude[bot] wants to merge 1 commit intomainfrom
add-challenge-74-n-body-force
Open

Add challenge 74: N-body Gravitational Force (Medium)#196
claude[bot] wants to merge 1 commit intomainfrom
add-challenge-74-n-body-force

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Feb 27, 2026

Summary

  • Adds challenge 74: N-body Gravitational Force (Medium difficulty)
  • Teaches the classic all-pairs O(N²) GPU computation pattern — shared-memory tiling is the key optimization to escape global-memory bandwidth bottleneck
  • Softened gravitational force formula: F_i = Σ_{j≠i} m_j (r_j - r_i) / (|r_j - r_i|² + ε²)^{3/2} with ε = 1e-3
  • Inputs: positions (N×3 float32), masses (N float32); Output: forces (N×3 float32)
  • Performance test: N = 8,192 (~67M pairwise force evaluations)

Why this challenge?

Unlike the many element-wise challenges already in the repo, this is a genuine all-pairs computation where every output depends on all N inputs. The natural optimization (shared-memory tiling to amortize global loads across a block of particles) is the same conceptual leap as GEMM tiling but applied to a completely different physics problem — making it educational without being a duplicate.

Test plan

  • pre-commit run --all-files passes (Black, isort, flake8, clang-format)
  • run_challenge.py --action run passes on NVIDIA TESLA T4 (example test)
  • All checklist items from CLAUDE.md verified:
    • challenge.html starts with <p>, uses <h2> sections, first example matches generate_example_test(), LaTeX bmatrix used consistently, performance bullet present
    • challenge.py: inherits ChallengeBase, all 6 methods, 9 functional tests (edge/pow2/non-pow2/realistic + zero inputs + negatives), performance test fits 5× in 16 GB
    • All 6 starter files present with correct parameter description comments
    • Solution file not committed

🤖 Generated with Claude Code

Teaches the all-pairs O(N²) parallel computation pattern: each output
depends on all N inputs, requiring shared-memory tiling to avoid the
global-memory bandwidth bottleneck. Force uses the softened gravity
formula with ε = 1e-3, tested on sizes up to N = 8,192.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants