Plot a figure inside parfeval

17 次查看(过去 30 天)
Hello all,
I've built an app using the AppDesigner and I would like the app to execute different functions according to user's choise (the requests could be at different times). The execution of each function might take time.
I've noticed that if I request an execution of two functions, Matlab HALTS the execution of the first function until the second one is done.
This is probably because there is only one worker to execute everything.
A quick research pointed out I should use parfeval. However, it seems that if function F should plot a figure, it doesnt do so.
I've Managed to verify that function F did ran, I simply saved the workspace inside F.
Any ideas why parfeval won't plot? Or workaround without having to return the figure as output?
Thanks in advance!

采纳的回答

Walter Roberson
Walter Roberson 2019-7-31
There is only one graphics thread that is connected to the display, and that thread is associated with the client. You can create figures is parallel workers but they will have access to limited graphics facilities, and you would have to save them on the worker.
  2 个评论
or ohev shalom
or ohev shalom 2019-7-31
I see. So basically is it possible that my app would be able to run functions on several threads without having to control it via parpool?
Walter Roberson
Walter Roberson 2019-7-31
MATLAB is only partly thread-safe and in particular memory allocation and deallocation is not considered thread safe. There are ways that you could invoke multiple threads of external code, but the only safe ways to do multiple matlab code threads are the ways in the parallel computing toolbox, or starting a second matlab process.
There are possibilities such as saving to .fig on the worker and opening the fig on the client. There are also possibilities involving having the worker send data back and having the client plot it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Asynchronous Parallel Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by