DataQueue and batch combined
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tomasz Wyrowinski
le 20 Juil 2017
Commenté : Tomasz Wyrowinski
le 21 Juil 2017
Hi, I'd like to run a scipt in background and return some values during its execution. I am currently trying use MessageQueue object to communicate 'caller' and worker thread which works fine while using it together with parfeval. However, my code is a script so I am starting it by using batch function which produces following error when background code tries to send data to MessageQueue:
Error: Struct contents reference from a non-struct array object.
Error Stack: AbstractDataQueue>AbstractDataQueue.send (line 135)
DataQueue>DataQueue.send (line 83)
LoopScript (line 7)
Warnings: While loading an object of class 'parallel.pool.DataQueue':
To send and receive messages there must be a pool.
Here's how I start my script together with MessageQueue communication:
% Calling background script
queue = parallel.pool.DataQueue;
queue.afterEach(@handle_message);
ws = struct('queue', queue);
job = batch('LoopScript', 'Workspace', ws);
LoopScript
% Code run in backgorund
while true
randVal = floor(rand * 4);
switch randVal
case 0
queue.send(true);
case 1
queue.send(1);
case 2
queue.send('32we');
case 3
queue.send(string([2 9 0]));
end
pause(1);
end
Is it possible to use MessageQueue along with batch function and pass data from background to foreground thread?
Regards
0 commentaires
Réponse acceptée
Edric Ellis
le 21 Juil 2017
It's not possible to use DataQueue with a batch job in this way - DataQueue can only be used to communicate between client and workers in a parallel pool. So, what you could do is this:
parpool(1); % Only 1 worker required
queue = parallel.pool.DataQueue;
queue.afterEach(@handle_message);
future = parfeval(@LoopFunction, 0, queue);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Asynchronous Parallel Programming 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!