Any way to assign CPU affinity when executing a program?

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Let's say I have a program that I have a program that eats through CPU cycles for a long time (something like 5 hours). How would I guarantee that 8 instances are running on 8 unique cores?
 

masteryoda34

Golden Member
Dec 17, 2007
1,399
3
81
AFAIK, Windows does that automatically so well that it isn't worth worrying about.

EDIT: Sry, just realized this was in *nix.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
use taskset

you can get usage info with 'man taskset'
you could probably even combine it with 'nice' to make sure the program takes over the cpu completely, just be sure you leave one cpu core for the system to use.

so maybe something like this "sudo taskset -c N nice -n -20 myprogram' where N is the cpu core you want this instance of the program to run on. Also, you have to use sudo to use nice with higher priorities.
 

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Originally posted by: Brazen
use taskset

you can get usage info with 'man taskset'
you could probably even combine it with 'nice' to make sure the program takes over the cpu completely, just be sure you leave one cpu core for the system to use.

so maybe something like this "sudo taskset -c N nice -n -20 myprogram' where N is the cpu core you want this instance of the program to run on. Also, you have to use sudo to use nice with higher priorities.

That did the trick!

I'm running 7 threads with 1 core available for general use. I didn't use nice, but that wasn't really needed. 7 threads per node is fine for my needs (4 nodes, 32 cores). I'd say 28 3.6 ghz Xeon's at 100% load is enough throughput for now :p
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
That's generally a bad idea because the kernel is smart enough to leave long running processes on the same CPU and to balance CPU hogs across available cores but now the Linux kernel has it's hands tied in how it can manage the available CPUs.