How to import objects and models in parallel implementation
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Edric Ellis
le 9 Fév 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
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!