Skip to content

daniel-steward/OptimisationWorkshop

Repository files navigation

Optimization Workshop 🚀

Welcome to the Optimization Workshop!

Your goal is to take a simple, unoptimized N-Body simulation and make it run as fast as possible.

The Challenge

The core of the simulation resides in NBodySimulationOptimised.cs. The Step() method calculates the gravitational forces between all bodies and updates their positions. Currently, it's a naive $O(N^2)$ implementation with several performance bottlenecks.

Getting Started

Prerequisites

  1. .NET 10 SDK or later.
  2. SDL2 Runtime: This project uses SDL2 for visualization.
    • Windows: The required DLLs should be handled by the NuGet package, but if you encounter issues, ensure SDL2.dll is in your path.
    • macOS: brew install sdl2
    • Linux: sudo apt-get install libsdl2-2.0-0

Running the Visualization

To see the simulation in action:

dotnet run -c Release

This will open a window showing 5,000 bodies interacting gravitationally.

Running Benchmarks

To accurately measure the performance of your changes:

dotnet run -- --bench

This uses BenchmarkDotNet to provide high-precision measurements.

Your Mission

  1. Open NBodySimulationOptimised.cs.
  2. Analyze the Step() method.
  3. Apply optimization techniques to reduce the execution time.
  4. Verify that the simulation still looks correct by running it visually.
  5. Benchmark your changes to quantify the speedup.

Check out the CHEATSHEET.md for inspiration on techniques like SIMD, Multithreading, and Memory Layout optimizations.

Good luck!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages