PDA

View Full Version : Multicore



NecroDOME
14-02-2008, 10:26 AM
So now we have a discussion on multi core/threaded stuff, I want to get a little more into the details.

My engine currently has support for more than one thread.

No my question is: how do I set my threads to a different core and how can I schedule everything? For multi threading I currently use critical sections.
My threads also need to switch from core at runtime. Is that possible or should I just define one thread per core?

technomage
14-02-2008, 12:36 PM
You can use the windows API.

SetAffinity
GetAffinity

to set which CPU Core a thread will run on. The following article will give you a good idea on how to do this.

http://www.delphi3000.com/articles/article_2605.asp?SK=thread

Linux and Mac OS X are difference, currently Free Pascal does not have the affinity calls defined I'm working on it for my own Engine but it's a long job as most of the required header files have not been converted.

JSoftware
14-02-2008, 01:14 PM
My understanding is that it's better to use SetThreadIdealProcessor to suggest the os which core the thread should run on. Masking the affinity might lead to the thread being locked on a processor which is active with something else. The os will try to balance the load. And as long as the process affinity mask is set to all processors then it'll automatically spread the threads across all free processors

NecroDOME
14-02-2008, 04:20 PM
Thnx JSoftware, thats what I was looking for :)