views:

102

answers:

2

I've word a bit with parallel processing in college and now I'm trying to get better at it. I can write code that can run in parallel and then start up threads, but after that I loose control over what the threads do. I would like to know how I can control the threads to things like for example bind a specific thread to a specific processor core.

I am mostly interested in c++ but I've done some coding of this in Java so those answers are also welcome.

+2  A: 

On Windows, you can use SetThreadAffinityMask to set the processor affinity for a thread.

Reed Copsey
+2  A: 

I'm answering in Java perspective: That's not possible. The best what you can control is the thread priority. To force Java to run on certain CPU/core, you have to do it in a platform specific way. In Windows for example, you can do that in the task manager by locating the process in the Processes tab, rightclicking the process in question (usually java.exe), choosing Set Affinity and tick the CPU's/cores.

alt text

As you might guess, this indeed globally sets the affinity, not on basis of threads you create in Java.

BalusC
So would the way to get around this in Java be to use multiple processes instead of threads?
In theory, yes. In practice, don't worry. The OS is doing this job better. If your sole purpose is writing for example a benchmark program, rather look for OS-native languages like C++.
BalusC