Passing output from afterEach to variable
이전 댓글 표시
Hello,
I`m trying to use parfeval that is running in the background to get images from multiple cameras and process them.
I tried using parallel.pool.DataQueue and parallel.pool.PollableDataQueue to get data from parfeval, but data being sent is too big, slowing down FPS and quickly filling up available ram.
My questions are:
- Is there a way to fetch data on request instead of creating queue (I need only newest data - not sending data from worker after each iteration to queue)? The data can be inside worker untill it is needed.
- Can queue be limited to size 1?
- How to use afterEach to save data to variable? I can only find examples with disp and replacing data on figures, not saving to workspace.
- Alternativly, is there a way to use timers in different threads instead of parfeval?
Thank you for your time,
Matt
댓글 수: 10
Walter Roberson
2024년 12월 29일
3.
afterEach(queue,@foo)
function foo(data)
assignin('base', 'data', data)
end
Matt Tejer
2024년 12월 29일
Walter Roberson
2024년 12월 29일
I think it would depend on which kind of camera it was, and which interface you are using. usb webcam support? ip camera support? Image Acquisition Toolbox support? GigE camera?
Matt Tejer
2024년 12월 30일
Walter Roberson
2024년 12월 30일
Are you using usb webcam support package or Image Acquisition toolbox?
Matt Tejer
2024년 12월 30일
Walter Roberson
2024년 12월 30일
편집: Walter Roberson
2024년 12월 30일
It is not clear to me that it would be beneficial to use that interface inside timer callbacks.
Matt Tejer
2024년 12월 31일
Walter Roberson
2024년 12월 31일
The documentation for timer has no section for extended capabilities, so there is no support for timers in thread pools.
I am not sure at the moment if there is support for timers in process pools. If there is, you would still have the same problem about returning the data to another process.
Walter Roberson
2024년 12월 31일
There is a faint chance that calling the external routines is compatible with thread pools, but I think it is unlikely.
채택된 답변
추가 답변 (1개)
Thomas Falch
2025년 5월 15일
편집: Thomas Falch
2025년 5월 15일
Starting in R2025a you can use the new "any-destination" parallel.pool.PollableDataQueue to more easily send data from the client to workers (or from workers to workers). It is documented here: PollableDataQueue - Send and poll data between client and workers - MATLAB
You can either use it as a replacement for the queue created on the worker the second step in Walter's answer. An alternative solution could (particularily if you want to use more workers) could look like this:
% Runs on worker, creates data on client's request and sends it back
function createDataOnDemand(toClientQueue, toWorkerQueue)
while true
% Wait for next request from client, or exit if client closes queue
[dataParams, didReceive] = toWorkerQueue.poll(Inf);
if ~didReceive
break
end
% Generate next piece of data, and send back to client
data = createData(dataParams);
toClientQueue.send(data);
end
end
pool = parpool()
toClientQueue = parallel.pool.PollableDataQueue(Destination="any");
toWorkerQueue = parallel.pool.PollableDataQueue(Destination="any");
f = parfeval(@createDataOnDemand, toClientQueue, toWorkerQueue)
% Drive work from the client, send requests for data, then receive and
% process it
for i = 1:n
dataParams = getDataParams(n);
toWorkerQueue.send(dataParams);
data = toClientQueue.poll(Inf);
processData(data)
end
toWorkerQueue.close();
카테고리
도움말 센터 및 File Exchange에서 Background and Parallel Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!