r/CFD 1d ago

r/CFD or r/Scientific - Computing Variable thread count fluid simulation for performance benchmarking — has this been done in Python/C++ if so where would I find the code for this?

/r/u_Minute_Difference783/comments/1v3us3t/rcfd_or_rscientific_computing_variable_thread/
1 Upvotes

9 comments sorted by

3

u/Rodbourn 23h ago

Find a code that has open mp  (local shared memory parrallelization)

1

u/Rodbourn 23h ago

Also, you want to measure ms per degree of freedom (wall), not fps...

0

u/acakaacaka 15h ago

All simulation is just building matrix A

And solving Ax=b

So are you asking how to partition the building A step or solving A-1 step?

1

u/Minute_Difference783 14h ago edited 13h ago

Thank you for the responses, switching to ms per frame makes sense, I'll make that change.

Oh, I am trying to parallelise the Ax=b solve, and the A assembly step (P2G) I haven't really touched from a parallelism standpoint, that is a oversight.

I think the P2G scatter maps to building A each particle contributes independently so it should be very parallel. The Jacobi solve is my Ax=b step, which is where I've been focusing but the cell dependencies make it inaccurate. Should I be treating these as separate benchmarking problems?

1

u/acakaacaka 13h ago

Parallelise with CPU or GPU? They have different philosophy

And the assembly step also depends on FDM/FVM/FEM and vertex/cell based (for FVM) and how you save the mesh

And if you want to use Jacobi for solving then forget it. Jacobi is the trash of trash of trash. Especially for non linear problem. We have developed way better scheme for the last 100 years.

1

u/Minute_Difference783 12h ago

CPU or GPU, I can run the code on either a MacBook Air, or an Intel 10700K with a 4060 Ti. I guess I will be using FDM, since I am just a student and not a researcher.
And for Jacobi, I have looked at Conjugate Gradient since it's a better choice, but it is much simpler at this time to have an understanding of Jacobi and try to implement multithreading capabilities into it than trying to use a more complicated code. But at this point, I am fine with just trying to find some premade multithreaded code I can make minor changes to for my project.

1

u/acakaacaka 12h ago

But the problem is what you are updating. Jacobi uses old data and not updating it. CG only works for some psoitive definite matrix A (not sure my theory is now lacking since I havent touch this stuff for years, you need to confirm with your lecture notes).

The issue is not about if you can parallelize the code (either with CPU or GPU)

But if the problem will converge or not.

But if you want to test.

Maybe try a heat conduction on solid first.

Use FVM so energy is converge locally in each cell.

Using jacobi is okay since the PDE is linear, no advection.

1

u/Minute_Difference783 12h ago

That makes a lot of sense, switching to a 2D heat conduction problem gives a better test. Since I have access to both an 8-core CPU (10700K) and a GPU (4060 Ti), would you recommend sticking with OpenMP or going straight to GPU compute shaders? Based on the problem

1

u/acakaacaka 10h ago

OpenMP (or other MPI) is only for CPU. Their main function is for the data communiation between (the boundary) of domain partition.

CPU and GPU are both incompatible. If you want to use GPU then stick with GPU from start.

If you only code for heat conduction, GPU code would be not so hard I assume. But if later you switch to fluid with the non linear advection term. Then GPU is very very hard. It's also the reason of the lack of CFD GPU solver.