I have four bat files and a four core machine. Is it possible to assign each run to each core i.e. 1 job for 1 core. Is there any way to control this with commands?
-
What could you be doing in a batch file that is not IO bound? If the processes you are trying to run are IO bound, then trying to balance them via processor affinity is not going to accomplish very much. Try providing more specifics about the process and what it does and you might get some much more appropriate comments for your situation.– dmariettaDec 6, 2013 at 16:08
2 Answers
On Windows 7 and above, you can use START /AFFINITY
to launch a process and restrict it to a one or more specific processors.
For earlier versions of Windows (XP and beyond), you can download the free Microsoft utility PsExec v2.0 that not only allows you to assign a process to specific processor(s), it also allows you to run a process on a remote machine.
In your comment to Chopper3's answer, you say you have a queue of many jobs, and you want to fire off one job for each processor, and then have the remaining jobs wait until a processor is free. At Parallel execution of shell processes on StackOverflow I posted a sample batch file that does pretty much what you want. As written, it sets up a queue of jobs and then limits the number of concurrent processes. It assumes the OS will handle load balancing accross the available processors. Even better, the script is designed to also support PsExec, so you should be able to assign each process to a remote machine and/or specific processor(s). However, I have not tested the PsExec functionality.
If you use the start /b whatever.bat
it will start the batch file in the background, if you do this at once then the kernel will schedule the jobs accordingly - you can't, and wouldn't want to, assign a core per batch file - you just want them running asynchronously and for the OS to manage the workload.
-
I have huge runs. Say I have 6 jobs. I would want to assign 4 of them at once to the four cores and remaining ones to be fired once the earlier four are finished. Is there no way at all to specify the core for each job? Aug 6, 2013 at 10:10
-
1You can't specify this as part of the process start no, as per my answer. But you can do this after the process is running by opening Task Manager and right clicking on the process then choose Set Affinity and pick a logical core. Oh and just use the CALL function at the end of each process to start the next one sequentially.– Chopper3Aug 6, 2013 at 10:16
-
-