Skip to content

kakkapriyesh/CUDA-Implementation-of-PIC-Algorithm

Repository files navigation

CUDA-Implementation-of-PIC-Algorithm

This is a learning exercise to use GPU for scientific computing. The code is written in CUDA and C++ to simulate two electron beams passing through each other in opposite directions. This interesting phenomenon is called the two-stream instability.

Significant speed up is obtained with GPUs as compared to CPUs

Details

The code is direct implemntation of blog which is written in python.

Extensive discription of the files and the results are given in the documentation.pdf attached with this repository.

The code gives out the last time step plot as output with y axis as velocity and x axis as position:

Time step = 50 sec

Building

The dependencies are- CUDA , GCC and Python 3.0

Go to the directory and run the shell script

./run.sh

The shell script executes following commands:

a) Compiles all the files

nvcc *.cu main.cpp -std=c++11

b) Runs the output file

./a.out

c) Plots the data from the text file of outputs (PICresult.txt) using a python code in (plot.py)

python plot.py

To run the simulation on CPU:

Just change the input.h to define (device_CPU) and run the shell script run.sh (./run.sh)

About

This project is a learning exercise in GPU-based scientific computing. It uses CUDA and C++ to simulate two electron beams traveling in opposite directions—a classic example of two-stream instability. Each GPU thread tracks a particle, resulting in significant speedup over CPU-based execution.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors