Parallel communication using parfor with appdesigner

Hi!
I have an app built with appdesigner. With this app, I am communicating with two different devices on two different ports (and two different protocols).
I use a timer for the communication. As the communication is the most time-consuming part of the app, I would like to speed it up a bit. I thought to do that by running the communication with the two devices with parallel computing, something like
q = parallel.pool.DataQueue;
r = parallel.pool.DataQueue;
afterEach(q, @app.read_SASA);
afterEach(r, @app.read_CAN);
parfor i = 1:1
if i == 1
%%%%%%% read_SASA %%%%%%%%%%%
send(q,1);
else
%%%%% read_CAN %%%%%
send(r,1);
end
end
where the two functions in the form
function results = read_SASA(app,data)
"some code here"
end
function results = read_CAN(app,data)
"some other code here"
end
The functions, if used outside of the parfor, work just fine.
On the other hand, if I use the "parfor" for running a basic function like "disp", it does not work, it gets stuck.
Is there a problem with using parfor inside timers in apps which I am not aware of?
Thanks in advance
Marco

1 Kommentar

Interesting Marco. It makes sense that a for-loop would work, since the time object should be run off of the main execution thread. But when adding parfor, I'm not sure if it can run on anything other than the main execution thread. What do you mean "it gets stuck"? disp doesn't display something, MATLAB hangs, MATLAB errors out?
Another consideration is to swap parfor/DataQueue with parfeval/fetchNext and see if that works.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Produkte

Version

R2018b

Gefragt:

am 6 Nov. 2020

Kommentiert:

am 6 Nov. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by