Determinism in Multithreaded Mode

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Determinism in Multithreaded Mode

Postby MeltingPlastic » Wed Aug 29, 2018 9:06 pm

Is determinism in Multithreaded mode possible? Using 4 cores I am not getting deterministic results with my save-load tests. Single threaded mode seems very deterministic. I am basically simulating large numbers of bodies falling on terrain and comparing their end result locations when they come to rest.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Determinism in Multithreaded Mode

Postby Julio Jerez » Wed Aug 29, 2018 11:38 pm

Multithreaded is not deterministic no.
The latest modification I made the solver is deterministic, but the collision system is not.

This is because the order I which contacts are proceed is based on which thread solve the a collision pair first, and to solve that It would have to add label to pairs do that the all can be sorted in the same order. That will required so much extract code that may end up being slower than single threaded.

for example say you have bodies A, B, C which collide and produce pair
AB, AC, BC
with single thread they are always solved on that order. Now say you have two threads.

one tgread takes pair AB, and the second thread takes pair AC.
the first thread finish pair AB and takes pair BC,
now the sequence is AB, AC, BC

suppose that now the first thread take pair AB, and second thread take pair AC, however a high priority thread preempt the first thread and now Is the second tread that finish first and takes pair BC.
the new sequence is AB, BC, AC

and in floating point arithmetic the laws of arithmetic are not exact.

the moral is that to guarantee lexicographic order it will required lot of labeling and sorting.

I am not sure if I can make the collision system deterministic in multithreaded mode, not at least with the alrogorim that the engine uses now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Determinism in Multithreaded Mode

Postby MeltingPlastic » Thu Aug 30, 2018 12:29 am

Makes sense - Thanks for the explanation!
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Determinism in Multithreaded Mode

Postby Sweenie » Thu Aug 30, 2018 4:29 am

I see alot on different forums people having problems with physics simulations not being completely deterministic and I'm curious in what scenarios you would want a perfectly deterministic simulation.

In real life there are loads of factors making a pair of thrown dices never end up in exactly the same spot such as wind, subsurface deformations, microscopic particles etc.

If doing research I could see why a deterministic result may be wanted but in games you would want to imitate real life physics as much as possible so a deterministic result would instead look unrealistic.

This is no criticism in any way, just something I'm curious about and been thinking about now and then. :D
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Determinism in Multithreaded Mode

Postby MeltingPlastic » Thu Aug 30, 2018 10:36 am

The only reason I would be interested in determinism is for multiplayer optimizations. If 2 clients are running the same simulation and you know the physics is deterministic you could potentially do optimization by only having to worry about syncing for client interactions with the world and do not have to worry about sending transform updates for every body in the world routinely/doing checks etc to correct for drift.

True lockstep networking is the most basic example I can think of (which who knows may be viable in the future if internet latencies improve at all)

Anyway its kind-of an idealistic expectation anyway. Not sure if single threaded mode would be deterministic across different platforms anyway.

but even without floating point level determinism, physics still behalves like physics so there are still optimizations that can be done for networking.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Determinism in Multithreaded Mode

Postby Julio Jerez » Thu Sep 20, 2018 10:54 am

Hey Sweenie I was trying to make the unity plug in use the parallel solver but I run into a problems.
when I add the option "SerializedProperty m_useParallerSolverProp;" to class NewtonWorldEditor
I get a crash with no call stack the moment I select the world.

also I added the function void SetParallelSolverOnLargeIsland(bool mode);

that is to be call when the use select the option on the property.


another thing I want to do is a way to load the specialize plugins, but that is not going to work on Unity so I will add a function to the engine like Load Plugin (the takes a path)

and remove the auto mode that is in now, that was teh can be load for anywhere, the problem I and having is how to go about presenting the available options in the editor.

for now I commited wit the paraller solver on for default SSE.

if you have some time, can you see what I did wrong in the editor class?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Determinism in Multithreaded Mode

Postby Julio Jerez » Thu Sep 20, 2018 2:12 pm

I added these two functions so that now load the plugins is on eh client side,
this was we can load from the unity plugin and have them available.
we only need an interface to select any of the available from a drop down menu.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Determinism in Multithreaded Mode

Postby Sweenie » Thu Sep 20, 2018 3:31 pm

Hi.

Regarding the serialized prop.
It seems you forgot to add the member m_useParallerSolver to NewtonWorld.cs

I can take a look at it during the weekend. :)
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Determinism in Multithreaded Mode

Postby Julio Jerez » Fri Sep 21, 2018 2:38 am

ah I see, I believe I have working now.
unfortunately it can't show teh available plugins, of at least I do no knwo hwo to do that, since teh editor can not read the world. so I added select best plugin for now.

Maybe later we can create a control to read the available plugin so that we can select from a drop down but for now this will do.

the reason I want to do that is that someone in GitHub is trying to use unity to make some kind of granular material stuff, he showed a video
https://www.youtube.com/watch?v=1eJVuaKm6Mo
if you check it out you can see what he is doing and since there are so few Unity users, this can be good.
He said he made an animation with the plugin in already but that was crashing at 32000 bodies and I was curios to see what he does.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Determinism in Multithreaded Mode

Postby Julio Jerez » Fri Sep 21, 2018 11:30 am

ok I think I have a better presentation now.
basically the editor create a word and extra info from it.
then it uses that to populate an intpopup control.
then the user can select a plugin and when the seven is launch, the start function look up that plugin.

I am not sure if all that set up work is better than to just set the preffer plug in on the start function.
but Since people like that stuff maybe we can keep it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 10 guests

cron