DataQueue and batch combined
조회 수: 7 (최근 30일)
이전 댓글 표시
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
채택된 답변
Edric Ellis
2017년 7월 21일
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!