Quote:Headkaze 1 << 0 shifts 1 to the left zero times so your left with 1. I don't think this is what your trying to achieve here surely?
That is one of maybe five different approaches I used for passing in that argument. I could not find many examples of literal usage with this function.. the two that I did find used the said argument and another had something similar to "0x01" (in instances where I wanted to use processor #1).
Quote:Anyway. I also wonder why you are doing this?
You shouldn't be setting thread affinity for performance reasons, if anything it'll only make things slower - the OS is really good at managing threads
I thought that would be true going into this as well, but after a lot of testing (i.e. actually going into task manager and setting affinity manually) I have discovered that with this particular set of processes it is best to have one thread per core. The fact is that so far I cannot exceed more than 25% of my total CPU.. even with multi-threading completely "off" the CPU only gets to 25%. I wonder if this is a priority issue or something like that?
Here are some of my results I found with threadless, 1 thread, and 2 threads:
Threadless:
- No affinity
-- CPU Usage: 25% CPU Usage spread across 4 cores, max core usage rougly 80%.
-- Processes Completion Time: 25 seconds.
One Thread:
- No affinity
-- CPU Usage: 25% CPU Usage spread across 4 cores, max core usage rougly 50%.
-- Process Completion Time: 64 seconds.
- Affinity to 1 core
-- CPU Usage: 25% CPU Usage spread across 1 core, max core usage 100%.
-- Process Completion Time: 44 seconds.
Two Threads:
- No affinity
-- CPU Usage: 25% CPU Usage spread across 4 cores, max core usage rougly 40%.
-- Processes Completion Time: 71 seconds.
- Affinity to 1 core
-- CPU Usage: 25% CPU Usage spread across 1 core, max core usage 100%.
--Process Completion Time: 18 seconds.
Strangest thing to me is threadless vs one thread, I would have thought they would have very similar completion times, but the way they are spread across cores matters a lot. I guess 1 core doing 100% work > two cores doing 50% work. But then again, with core affinity set on the one thread run it's still much slower even with more cpu usage on the same core.
Quote:You might want to look into trying the following instead?
The Task Parallel Library (TPL)
Thanks, I'll look into this.
As kind of a by the way, I'm not really trying to perform these particular tasks on specified cores for performance reasons, I am just trying to figure out how I would do it if I needed to do it, honestly.