Passing output from afterEach to variable
83 次查看(过去 30 天)
显示 更早的评论
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-31,8:42
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,8:44
There is a faint chance that calling the external routines is compatible with thread pools, but I think it is unlikely.
采纳的回答
Walter Roberson
2024-12-29,21:11
This method is fairly clumsy, but in theory it would work.
Use a parpool size of 1.
Use parfeval() to create a parallel.pool.PollableDataQueue object and return it to the caller.
Create a parallel.pool.DataQueue object in the workspace.
parfeval() passing in the DataQueue object
afterEach() on the DataQueue
Now, when the client is ready to accept data, send() a signal (any value) from the client to the PollableDataQueue
Meanwhile, the worker is looping around fetching frames, and checking the QueueLength property of the PollableDataQueue. When the queue becomes non-empty, poll() the PollableDataQueue to "eat" the signal; then have the worker write the most recent frame to the DataQueue object. If the queue is empty, just loop back to accepting the next frame.
The afterEach function on the DataQueue receives the frame and stores it (and does whatever with it.) Oh, and the afterEach probably does the next send() to the PollableDataQueue to signal that the client is ready for more data.
0 个评论
更多回答(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!