Running two MATLAB scripts in parallel

24 次查看(过去 30 天)
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?

回答(1 个)

Hiro Yoshino
Hiro Yoshino 2021-4-6
It sound that "batch" function would suit your case.
  2 个评论
Raymond Norris
Raymond Norris 2021-4-6
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 2021-4-6
Appreciate you both! This will work. Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by