Question about MultiThreading

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Question about MultiThreading

Postby tenseiken » Fri Jul 02, 2010 6:44 am

Hi,
I just found out that Newton has the command NewtonSetThreadsCount, so I wondered how it works, since I am not a grand master in threads handling :?
Does Newton handles the different threads alone if I just use this command, or does it also need some manual coding ?
Thanks
tenseiken
 
Posts: 5
Joined: Mon Apr 12, 2010 2:26 am

Re: Question about MultiThreading

Postby Julio Jerez » Fri Jul 02, 2010 7:39 am

you just use that command and if you have a multicore cpu the engine will use microtreads to resoltve different part of the engine in paralallel:
Collison, Contact force calculation, Braphase pair finding, Raycastin, enverythong that is a take the is execute with and array of objects.

The only part you should take car is if the callback is you are changing local data in a body.
for example is you are placing bodies in a global list, and thow call back are readin the list at the same time, there will be a race condition.
for that the engine has a function call Critical section, basically you wriet you callback like this
Code: Select all
callback()
{
  ...
   ...

  // code tah write fo shared memory
   NewtonCriticalSectrionLock
   // do you writing here
   ...
  // newton critical sectionUnlok

  ...
  ...
}


That is all there is to it. you can write you cod eliek that even if it does not us multiple thread. because Critical sections has not effect on single thread.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Question about MultiThreading

Postby tenseiken » Fri Jul 02, 2010 8:13 am

Thank you for the reply :)

I think I might not have any troubles with shared ressources, so I just added the command NewtonSetThreadsCount(World, 2) after creating my world.
Then I tried to drop a lot of convex objects in my scene, but I didn't see any difference, there is always one of my two cores running at 100 % while the other does almost nothing.
Could it be a problem in my implementation ? I am using the Pascal version of Newton.
tenseiken
 
Posts: 5
Joined: Mon Apr 12, 2010 2:26 am

Re: Question about MultiThreading

Postby Julio Jerez » Fri Jul 02, 2010 1:58 pm

I do no know hwo to interpre the cpu usage in window, In my option it means nothing.

the way you can see if setting tow threa is better is by chekin teh time spend in a puhsics update,
depending on your scene and you CPU tow core is beteeen 60% and 80% faster.
the window performce thing is not reliable because it measure everything window is running and the OS usually runs 40 to 50 threads in the background.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Question about MultiThreading

Postby tenseiken » Sun Jul 04, 2010 7:12 am

Ok, I will check it with a time spent comparison. Thank you !
tenseiken
 
Posts: 5
Joined: Mon Apr 12, 2010 2:26 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron