0

I'd like to set the cpu-affinity of multiple particular threads.

All the references I've found so far deal with setting the cpu-affinity of a process(PID) but not a thread. Is there a way to accomplish this while using .Net Runspaces? Or am I trying to do something impossible?

The basic idea is: I have a 20 core box and would like to get the threads spread evenly between the cores. Otherwise they all wind up pounding on a single core.

Thanks!

Jeremy
  • 243
  • 2
  • 10

1 Answers1

1

I'm not sure about a .Net wrapper, but the Win32 api SetThreadAffinityMask does what you need - see documentation here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686247(v=vs.85).aspx.

Jason Shirk
  • 7,734
  • 2
  • 24
  • 29
  • I'm not sure how that would tie into Runspaces. I don't suppose you have any examples? – Jeremy Jun 10 '14 at 02:37
  • An example: http://khason.net/blog/parallel-programming-well-it%E2%80%99s-all-about-cpu-affinity-or-how-to-set-processor-affinity-in-wpf/ – Jason Shirk Jun 10 '14 at 17:37
  • Runspaces have a property ThreadOptions - if you use either ReuseThread (for runspace pools) or UseCurrentThread, you can be sure the runspace isn't creating new threads, so setting the thread affinity once per runspace should suffice. – Jason Shirk Jun 10 '14 at 17:38