Running two MATLAB scripts in parallel

30 Ansichten (letzte 30 Tage)
Nathan Hoffman
Nathan Hoffman am 6 Apr. 2021
Kommentiert: Nathan Hoffman am 6 Apr. 2021
We're trying to run 2 similar MATLAB scripts in Labview and realized that MATLAB will only run one instance so they will only run in series. If we would like to run the scripts in parallel so they execute at the same time, would we need parallel computing toolbox? Will this provide the multithreading that we need?

Antworten (1)

Hiro Yoshino
Hiro Yoshino am 6 Apr. 2021
It sound that "batch" function would suit your case.
  2 Kommentare
Raymond Norris
Raymond Norris am 6 Apr. 2021
To add onto Hiro's Answer, to clarify, from within Labview, you want to run N number (2 in this case) MATLAB scripts in parallel. And, you can only run one MATLAB instance at a time. That is, Labview can't connect to two concurrent MATLAB instances.
In that case, you're probably going to have to write some wrapper script that systematically launches each script. I'm not a Labview user, but I'm imagining rather than calling
script_1
script_2
you might just call
wrapper
where wrapper looks like
j1 = batch('script_1');
j2 = batch('script_2');
If N is larger than 2, you might put it in a for-loop
fcn = {'script_1','script_2', .. };
for idx = 1:numel(fcns)
j(idx) = batch(fcns{idx});
end
% Will need to extra data from job object, j
Be mindful that batch is asynchoronous. Therefore, unless you have a barrier, once the batch jobs are submitted, execution would return immediately to Labview. Perhaps you want to ensure they've all finished running first. If you knew they were all going to take about the same amount of time, you could wait for the last job to finish.
j(end).wait
Conversely, parfor would block for you, as such
parfor idx = 1:numel(fcns)
result(idx) = feval(@fcns(idx), .. );
end
Then to answer you question, Parallel Computing Toolbox would be required to run these separate processes (not threads).
Nathan Hoffman
Nathan Hoffman am 6 Apr. 2021
Appreciate you both! This will work. Thanks!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by