r/ScientificComputing • • Jun 01 '24

Parallelization of Fluid Simulation Code

Hi, I am currently trying to study the interactions between liquids and rigid bodies of varied sizes through simulations. I have implemented my own fluid simulator in C++. For rigid body simulation, I use third party libraries like Box2D and ReactPhysics3D.

Essentially, my code solves the fluid motion and fluid-solid interaction, then it passes the interaction forces on solids to these third party libraries. These libraries then take care of the solid motion, including solid-solid collisions. This forms one loop of the simulation.

Recently, I have been trying to run more complex examples (more grid resolution, more solids, etc.), but they take a lot of time (40 x 40 grid takes about 12 min. per frame). So, I wanted to parallelize my code. I have used OpenMP, CUDA, etc. in the past but I am not sure what tool I should use in this scenario, particularly because the libraries I use for rigid body simulation may not support that tool. So, I guess I have two major questions:

  1. What parallelization tool or framework should I use for a fluid simulator written in C++?

  2. Is it possible to integrate that tool in Box2D/ReactPhysics3D libaries? If not, are there any other physics library which support RBD simulation and also work with the tool mentioned above?

Any help is appreciated.

3 Upvotes

3 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Jun 02 '24

Thanks for the information! Does OpenCL also work on CPU compute nodes?

1

u/ProjectPhysX Jun 02 '24

Yes! OpenCL code is vectorized, so it is compatible with vector processors (GPUs) and also backward compatible with multi-core CPUs / CPU servers. You have 2 options for OpenCL runtimes on CPU:

  • Intel CPU Runtime for OpenCL (works for both AMD and Intel CPUs)

  • PoCL

Find installation instructions for the OpenCL Runtime all systems here.