Fluid Simulation Implementing gauss seidel relaxatiopn

How can I implement the Gauss-Seidel relaxation using CUDA? I want it for writing the code of diffusion step. if anyone already wrote the code, I shall be very grateful if you let me learn from it.

Thanks in advance.

By rewriting the serial implementation to a CUDA implementation?

yes. I am actually confused about neighbor value accessing.

On a GPU it would make a lot of sense to use Red-Black ordering (look it up) of grid points so you can update half of your grid in parallel each step without needing synchronisation.


As Durante says, the Red-Black ordering is probably the best method.

I’ve implemented a Gauss-Seidel kernel in CUDA for an algorithm that I made for my thesis last year. I didn’t have a lot of time left for that implementation so I simply used all the neighbour pixels of the previous iteration instead of taking two from the current iteration (like I did in the sequential version). I put the previous iteration into the texture memory and let the kernel read out all pixels from there.

It’s not the most efficient method but it was the easiest thing to do in a very tight time schedule. It did hurt the overall convergence rate of the algorithm, so it’s best to look into more precise methods.

Unless I misunderstand what you’re saying you actually implemented a Jacobi algorithm ;)

I’ve also used a Jacobi algorithm instead of Gauss-Seidel for a GPU implementation (because of ease of use), but in my case that was inside a multigrid method so the overall convergence speed wasn’t affected much.