How to pass data between parallel tasks that don't terminate?

5 次查看(过去 30 天)
I have a data logging & monitoring tool that I've written using the App Designer. It creates a timer object in the background to retrieve data, saves it to a file, and updates the display. Since it's a single-threaded application, I can't save data any faster than I can update the display (which is rather slow). Because of this, my timer can't run faster than about 1x per second. Ideally, I'd like to save data to the file at 10-100x per second, even if the display updates more slowly.
I have the parallel computing toolbox, so I've been looking at running the data collection and plotting as parallel tasks. The app display would refresh using a timer as it does today, but the data collection would run as a background parallel task continuously sampling data (while(1)) as fast as possible.
It appears that the branch and parpool functions both require you to wait until a task is complete before accessing its data. Since the data collection task never ends, I'm not sure what to do.
In summary, here's what I'm looking for:
  • Data collection task - Runs continuously, appends readings to DATA matrix, writes to output file
  • Screen update task - Runs 1/sec, only displays the latest value from DATA matrix

回答(1 个)

Sid Jhaveri
Sid Jhaveri 2016-12-6
If waiting till task is completed is the only issue while using Parallel Computing Toolbox, then you can try using " parfeval " or " parfevalOnAll " functions of Parallel Computing Toolbox.
To learn more about asynchronous parallel programming in MATLAB, refer to the link given below: https://www.mathworks.com/help/distcomp/asynchronous-parallel-programming.html
  1 个评论
Scott Waun
Scott Waun 2016-12-6
Is it possible to access the function's internal variables before it's completed execution? In my case, the function will never end (endlessly collecting data). The parallel thread needs to be able to access its data however. The examples only show a for loop that waits for outputs to become available on completion.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by