フィルターのクリア

Run cmd faster and parallelly in background

4 ビュー (過去 30 日間)
Ash Ahamed
Ash Ahamed 2022 年 2 月 11 日
回答済み: Benjamin Thompson 2022 年 2 月 11 日
Hello!
I have this code which runs an executable going in to each folders. The executable opens a command prompt window. Executable also needs couple parameter inputs to make sure it runs.
Even though each individual run takes only few seconds total number of folders/executions could be upto 20000. So I am looking for a way to execute this faster in Matlab, and if possible in parallel and in background, - without a pop up window.
Any suggestion would be greatly appreciated.
code=['@ECHO off',newline,...
'setlocal enabledelayedexpansion',newline,...
'set dir=%1',newline,...
'SET "var=1"',newline,...
'for /D %%a in (%dir%\*) do (',newline,...
'echo processing: %%a',newline,...
'start /D "%%a" /min "Dummy" cmd.exe /c "Dummy.exe < parameters.txt"',newline,...
'IF !var!==3 (PING localhost -n 3 >NUL) & SET "var=1" ',newline,...
'SET /A "var=!var!+1")'];
dlmwrite('Dummy.bat',code,'delimiter',''); % writes out a batch file
for run=1:4 % 4 folders each containing around 5000 subfolders
name = (sprintf('Doe%i' ,run));
CmdStr=sprintf('Dummy.bat %s',name);
system(CmdStr);
end

回答 (1 件)

Benjamin Thompson
Benjamin Thompson 2022 年 2 月 11 日
Due to the overhead of launching and running CMD so many times, you may not gain much or it may run slower. After first optimizing the algorithm, the second principal of parallelization is to keep the batch size as large as possible. So maybe if you have 4 CPU cores or less, break it up into running one job per each of your folders.
Instead of running the start and cmd processes, try using the system function in MATLAB, and then maybe parfor or parfeval to parallelize it into a parallel pool on your system.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by