Particle Simulation: CPU & GPU

This project involved using the CPU and GPU to simulate particles. The simulation mimics a spray can spraying paint particles onto a piece of paper. One simulation runs on the CPU using Rust, and another runs on the GPU using CUDA. Both simulations output a BMP file, showing the result of the particle simulation.

CUDA Simulation

To implement the GPU-based particle simulation, I used NVIDIA's CUDA architecture. By writing kernels, I was able to utilize thousands of threads to simulate particles in parallel efficiently.

The simulation outputs a BMP image that shows the particles' interaction with the paper. Particles are assigned a starting position and a downward velocity, and if they hit the paper, the corresponding area turns red.

CUDA Simulation

You can access the GitHub repository for the CUDA particle simulation here.

Rust Simulation

In the Rust implementation, I used the producer/consumer design pattern, where producer threads create the particles, and consumer threads move them and check for collisions. I implemented thread safety with locks to ensure that multiple threads could safely access the same particle data.

The Rust simulation outputs a BMP image showing the particles sprayed from the can at random angles, simulating the behavior of a real spray can.

Rust Simulation

You can access the GitHub repository for the Rust particle simulation here.