Running two MATLAB scripts in parallel

조회 수: 13 (최근 30일)
Nathan Hoffman
Nathan Hoffman 2021년 4월 6일
댓글: Nathan Hoffman 2021년 4월 6일
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