8

I've got a dual processor machine and I would like to launch an executable via a batch file on both processors.

For example: (1) Launch Notepad.exe on Processor 1, and (2) Simultaneously, Notepad.exe on Processor 2

Currently, I'm using the following in my batch file, since my executable was "difficult" to launch and needed a return in order to run when launched: echo.|DoStuff.exe

Thus, I would like to launch it and have it run on each processor.

Thanks for any feedback provided.

P.S. I don't think "start" will work for me since I need to send in the return character to the executable as shown above with echo.

P.S.S. This is for a Windows XP solution. Thanks.

JustADude
  • 2,619
  • 7
  • 31
  • 45
  • 1
    You may want to reconsider this. In general, the CPU scheduler will make better decisions than you will. We tried this and actually saw a slight performance decrease from just launching two separate programs – Steve May 06 '09 at 02:35

3 Answers3

20

start /affinity 1 notepad.exe

start /affinity 2 notepad.exe

(Windows7 has affinity for the start command, but XP does not. PSexec works though)

Community
  • 1
  • 1
Rich.Carpenter
  • 1,056
  • 1
  • 9
  • 21
  • Unfortunately I cannot use start since I need to use echo.|DoStuff.exe, so a return statement is sent into the Executable. Is there way to set the affinity and send in a return statement? – JustADude May 06 '09 at 03:10
  • 2
    What if you started a batch file with some affinity with "echo.|DoStuff.exe" in it? Would that pass on the cmd instance's affinity? – Anonymous May 06 '09 at 04:05
  • why 0F doesn't use all 4 processors like it was supposed to? – Adrian Cumpanasu Nov 20 '14 at 08:59
6

Microsoft's Sysinternal's psexec's -a flag can set processor affinity on Windows XP:

Usage: psexec [\\computer[,computer2[,...] | @file][-u user [-p psswd]][-n s][-l][-s|-e][-x][-i
[session]][-c [-f|-v]][-w directory][-d][-][-a n,n,...] cmd [arguments]
     -a         Separate processors on which the application can run with
                commas where 1 is the lowest numbered CPU. For example,
                to run the application on CPU 2 and CPU 4, enter:
                "-a 2,4"

For example:

psexec -a 2 cmd /c "echo.|DoStuff.exe"
Anonymous
  • 49,213
  • 1
  • 25
  • 19
0
  • This page talks about a free tool called XCPU you can use to launch and set affinity. However the link within doesn't work. Maybe a bit of googling can locate it for you.

  • And there is a simmillar tools here called runfirst.

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • it can still be found using archive.org, see http://web.archive.org/web/20071012053544/http://www.appliedvisual.com/xcpu.htm Posting this here since this is one of the higher-ranked Google results, so this can probably still be useful to some. – Ludovic Aelbrecht Apr 06 '10 at 22:04