Using parfor and system()

22 vues (au cours des 30 derniers jours)
Oren Lee
Oren Lee le 21 Nov 2018
Commenté : Walter Roberson le 21 Nov 2018
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 commentaire
Walter Roberson
Walter Roberson le 21 Nov 2018
parfeval() or batch()
but see
https://www.mathworks.com/matlabcentral/answers/373123-start-system-command-or-run-batchfile-in-background

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by