Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a program that by default only runs on one CPU. I have tried using the start /affinity x notepad.exe batch command but i can't get it to run my program. it changes the title of the command line window but doesn't execute the program. this start command does work for notepad so it might just be a problem with the software. I have set the affinity manually via task manager so i know it works.

I am not the programmer of this software so changing that is not an option.

Update: I got it to run the program now. I added the exit command to the end of my batch script. Now i need to know how the /affinity flag works. I can't seem to get it to use 4 cpu'.

Update 2: so i finally figured out that the /affinity flag expects a hexadecimal number. I can now set the affinity correctly for notepad but still can't set it for the software i am using. Could it be that the software just doesn't support multi-threading?

share|improve this question

3 Answers 3

It is bitwise so convert binary to decimal. Eg. 0001 = 1 = cpu1, 1000 = 8 = cpu4, 1111 = 15 = all four cpus

share|improve this answer
    
as far as i can tell /affinity uses a bitwise operator so dec 15 = bin 1111 should turn all four processors on. this works with a program like notepad but not with the software i am using. –  Samuel Apr 27 '10 at 14:23
    
yup you are right, was thinking of a different command. edited to correct –  JamesRyan Apr 27 '10 at 14:31

If it "changes the title of the command line window but doesn't execute the program" then this looks like a command line problem. Can you post the actual command line? Does it include spaces, quotes or additional parameters?


Edit:

Good to know you got it to run. As others have said, the "affinity" parameter is a bitmask; so, you need to use "1" for "CPU 1", "2" for "CPU 2", "4" for "CPU 3", "8" for "CPU 4", and so on; you can set the affinity to multiple CPUs by adding those numbers, so, if you want your process to use CPUs 3 and 4 (but not 1 and 2) you would use "12". "15" is what you should use to mean "all the first 4 CPUs".


Edit 2:

Of course, if your program is not multithreaded, it won't benefit at all from having more available CPUs. To rule this out, set its affinity using Task Manager and see how it behaves; if you have four CPUs but the program only uses at most 25% of the total system CPU time, then it's single threaded; if it gets up to 50%, it runs at most two threads. If it manages to go up to 100%, then it can get the most out of your server (but be careful not to slow down everything else).

share|improve this answer
    
I was using quotes in the command. can i just escape them? –  Samuel Apr 27 '10 at 14:23
up vote 1 down vote accepted

My first problem was that the batch file wouldn't run my program. This ended up being a problem with spaces in the path. I couldn't figure out how to escape them so i just used short names. (e.g. c:/progra~1/ instead of c:/program files/)

second problem was setting the affinity. turns out that the affinity flag in the start command takes hexadecimal numbers. the software still didn't work but that has to do with the software. It is being fixed by the developer now. (yay!)

As far as the software not being multi-threaded i think windows does some load balancing because if you set it manually to use all processors the software does use them all and go faster.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.