Programming multiple cpu's

Started by
3 comments, last by GameDev.net 18 years, 5 months ago
There has been a lot of talk about PC's with multiple cpu's lately. I was wondering if it is possible to get access to different cpu's in a c/c++ program? (Assuming a windows platform is used) And if so, would you have to take care of critical sections and the like yourself?
Advertisement
Quote:Original post by pulpfist

There has been a lot of talk about PC's with multiple cpu's lately.

I was wondering if it is possible to get access to different cpu's in a c/c++ program?
And if so, would you have to take care of critical sections and the like yourself?
Most new age processors have multiple processors already built inside, for intel this is called "hyper threading", for AMD I think the name is "dual-core". Usually there is a "affinity" applied that tells where a process should run from.

Might want to read more on SMP :)
Quote:Original post by EmperiorRune
Quote:Original post by pulpfist

There has been a lot of talk about PC's with multiple cpu's lately.

I was wondering if it is possible to get access to different cpu's in a c/c++ program?
And if so, would you have to take care of critical sections and the like yourself?
Most new age processors have multiple processors already built inside, for intel this is called "hyper threading", I don't know what they call it for the AMD counterpart. Usually there is a "affinity" applied that tells where a process should run from.


Hyper-Threading is *not* multiple processors. It is Intel's implementation of simultaneous multithreading and happens on a single processor.

As for the OP's question, since you mentioned windows, you can use the Processes and Threads and Synchronization APIs.


jfl.
As far as I know you won't be able to specify the processor to be used with the Windows Threading API. You just call CreateThread and Windows will decide on which CPU to create the thread.

There is however an open standard for multi processing in C/C++ if your compiler supports it, OpenMP
Visual Studio .NET 2005 supports OpenMP.
Quote:Original post by pulpfist

There has been a lot of talk about PC's with multiple cpu's lately.

I was wondering if it is possible to get access to different cpu's in a c/c++ program? (Assuming a windows platform is used)
And if so, would you have to take care of critical sections and the like yourself?



One thing I saw recently (in a Book) was something about synchronizing/lock mechanisms working differently across SMP processors. There may be extra wait time for the shared memory/caches to stabalize/settle (theres a term I cant remember for this). The book talked about the 'spinwait' being more useful/efficient (a lock call sitting and waiting for a while for a memory based lock to clear instead of doing a thread switch immediately -- something that is mostly useless on a thread run uniprocessor).

From what I have heard (Im looking into using multiprocessors in future also) that threads from a multi-threaded C program will run on different CPUs and you are able to designate which one each thread if you want.

This topic is closed to new replies.

Advertisement