How to import objects and models in parallel implementation
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Edric Ellis
on 9 Feb 2015
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
See Also
Categories
Find more on Distributed Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!