필터 지우기
필터 지우기

Using parfor and system()

조회 수: 10 (최근 30일)
Oren Lee
Oren Lee 2018년 11월 21일
댓글: Walter Roberson 2018년 11월 21일
Hi All,
I have a large number of system commands that I would like to call up that each take about 80s but are comlpetely independent of one another. Originally I had this going to the system command as such:
system('someInputCmd &')
However MATLAB would always wait for the first command to finish prior to starting the next one. I then tried to write my code in a generic .bat file which is called upon. No matter what I did, MATLAB refused to run these system commands in parallel. I learned that if I make a .bat file which just passes everything to a second .bat file (which does my process), MATLAB won't wait for these processes to complete and my parfor loop will iterate (still in series though). In this way I 'trick' MATLAB into running a bunch of commands in parallel.
parfor i = 0:3 %small numbers for testing
system(['someInputCmd.bat ',num2str(i),' &']);%where i allows for dynamic input to the .bat
end
The issue is, I need to run this command 100+ times, and using the above technique had the first 12 or so use all my computer resources as expected (and desired), but afterwards seemed to run in series again yielding a very long processing time. My next idea is to only run these in .bat's in batches (no pun intented), and tracking when they finish. My most recent test iteration looks something like the following. I was wondering if there was a more elegent way of being able to do this. Ultimitely I will have to place all the below code in a larger for loop which will allow me to iterate to the >100 files I need. Your guys help is always appreciated!
parfor i = 0:3 %small numbers for testing
system(['someInputCmd.bat ',num2str(i),' &']);%where i allows for dynamic input to the .bat
end
for
notDone = 1;
doneName = 'C:\someFile.txt';%file which gets created as each .bat completes
while notDone
pause(0.1);
notDone = exist(doneName,'file')<1;
end
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 11월 21일
parfeval() or batch()
but see
https://www.mathworks.com/matlabcentral/answers/373123-start-system-command-or-run-batchfile-in-background

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by