How to import objects and models in parallel implementation
조회 수: 3 (최근 30일)
이전 댓글 표시
I am using parallel computation toolbox to run two functions simultaneously like this:
funList = {@f1,@f2};
parpool(2);
spmd
labBarrier
funList{labindex}()
end
function [] = f1()
for k=1:10
labSend(rand(1,3),2,k);
end
end
function [] = f2()
for k=1:10
labReceive(1,k)
end
end
The problem is I can't call any objects from my workspace using evalin function in neither f1 nor f2 nor I can send variables to my base workspace using assignin function.
I need to call serial port object from base workspace and get output from f2() in base workspace in real time. Is there any way to do it except creating a new object inside these functions.
댓글 수: 0
답변 (1개)
Edric Ellis
2015년 2월 9일
The parallel pool workers are separate MATLAB processes, so you might well need to create new serial port objects on the workers. I'm not too familiar with the serial port object in MATLAB, but it sounds like you can't have multiple objects referring to the same underlying port, so you probably need to ensure you only build the object on one worker, something like this:
% build the serial port object
spmd
if labindex == 1
s = serial('COM1');
else
s = [];
end
end
% Use the serial port object on lab 1
spmd
if labindex == 1
f1(s);
else
f2();
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!