dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.77k stars 235 forks source link

How do I properly enable parallel in rapier3d? #618

Closed Insopitus closed 2 months ago

Insopitus commented 2 months ago

I have a app that do physics simulation of around 10,000 to 1,000,000 balls in a scene. Parallelism seems like a good way to boost performance. I add rapier in Cargo.toml like this: rapier3d = {version = "0.18.0", features = ["simd-stable","parallel"]}. But when I run the simulation with physics_pipeline.step(...) , the CPU usage of the app is only around 20%. My CPU is a Intel i5-10200H.

Am I not enabling parallelism properly?

sebcrozet commented 2 months ago

You are enabling parallelism properly.

Not all of the physics pipeline is parallelized at the moment. In particular the broad-phase and the island calculation are not parallel. The force calculation is parallel but only if you have multiple islands (i.e. if not all your balls are interacting in a single big pile).

Insopitus commented 2 months ago

Got it. Thank you.