Advertisement
hidde663

affinity.bat

Jan 2nd, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. @echo off
  2. :: example start notepad.exe on with core 1 & 4 from cmd:
  3. ::affinity notepad.exe 1+4
  4. ::this will start notepad with cores CPU0 & CPU3 assigned to it
  5. if '%1'=='/?' goto help
  6. if '%1'=='' exit/b
  7. if '%2'=='' exit/b
  8. for /L %%1 in (1,1,%NUMBER_OF_PROCESSORS%) do set core%%1=0
  9. set cnt=1
  10. :loop
  11. for /F "tokens=%cnt%-%NUMBER_OF_PROCESSORS% delims=+" %%a in ("%2") do set core%%a=1
  12. if '%cnt%' LSS '%NUMBER_OF_PROCESSORS%' set/a cnt+=1&goto loop
  13. :loop1
  14. set/a ans=0x%core1%*0x1+0x%core2%*0x2+0x%core3%*0x4+0x%core4%*0x8
  15. if '%ans%'=='10' set ans=A
  16. if '%ans%'=='11' set ans=B
  17. if '%ans%'=='12' set ans=C
  18. if '%ans%'=='13' set ans=D
  19. if '%ans%'=='14' set ans=E
  20. if '%ans%'=='15' set ans=F
  21. ::0000
  22. ::1+4 = 1001 = 9 = 0xA = A
  23. ::core 1(0) = 1
  24. ::core 2(1) = 2
  25. ::core 3(2) = 4
  26. ::core 4(3) = 8
  27. ::sum values to use more cores
  28. ::0xf = 1111 – a mask allowing use of only the first four processors:
  29. start /AFFINITY %ans% %1
  30. exit/b
  31. :help
  32. echo exmaple: affinity notepad 1+3
  33. echo.
  34. echo parameter 1 = file to be executed
  35. echo parameter 2 = which cores
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement