Topics: Developer Forum, User Forum
Mar 6, 2012 at 6:48 PM
Edited Mar 7, 2012 at 11:38 AM


I don't know if I have misunderstood the word multi-threading but when I run either a home-made or a default sample on the FPE and watch my cores, only the first core is working. So is the FPE supposed to work on more than one core or should I found a way to make it works?

I'm asking this because the project I'm currently working on might need to simulate a lots of objects in the same time and the FPE is quickly over-using my first core, which result in big lags.




Edit : I haven't made this topic to complain about the engine, it's one of the greatest framework I have ever use ;)

Mar 8, 2012 at 4:31 PM
Edited Mar 8, 2012 at 4:31 PM

Farseer is not multi-threaded. You'd have to implement that yourself. You can run the physics on another core and communicate somehow to the main thread running on the first core. That won't be that hard to implement (just set the thread afficinities). You can find posts on this forum from people who've done that. Still it's quite away from real parallelization of tasks which is the only thing that could significantly boost performance.  It's because you would still have a bottleneck somewhere (probably the GPU) so one thread will have to wait for the other. At the end of the day the gain will be less than the pain.

It will be interesting to see what could be done with C# 5.0 and the async framework - might be a great way to demonstrate the advantages of .NET for porting something that wasn't build with multi-threading in mind without going through synchronization hell.

Mar 8, 2012 at 7:32 PM

I can't wait to try this out ^^, the fact the FPE only use one core is limiting the maximum number of bodies simulated (without even adding any other curstom code in the physic simulation).

Mutlicore + FPE = best 2D physic engine ever :p

Mar 8, 2012 at 10:58 PM

Well you don't have to wait for C# 5 really (even more than now it's already a CTP with permission to be used in production).  You can use System.Threading.Tasks and the Task Parallel framework which are almost equivalent to the async/await in C# 5.0,  those being little more than syntactic sugar. Still someone needs to modify Farseer to take advantage of them i.e. someone who knows where stuff can be safely run in parallel. That's not at all an easy task because Box2D, on which Farseer is based, is not written with multi-threading in mind.

Also if you look at other physics engines like Bullet the hot stuff is not about multithreading in the least but rather running stuff on the GPU with CUDA/OpenCL.