How can I launch a parallel function?
3 次查看(过去 30 天)
显示 更早的评论
I'm creating an application which controls an Ar Drone Parrot. To do this I use a main function. In addition, I want to launch a parallel function to the main program which contains a while loop, and they will be executed at once. That is to say, the main function doesn't stop when the while loop is being executed. When the secondary function is called, the main function continues and it doesn't wait for the secondary function.
I'm using Matlab 2015b and I suppose that I must use the Parallel Computing Toolbox, but I don't know what commands I can use or how I can do this.
I have been looking for a solution and I think that I can use the batch command to launch the parallel function. I am right? Have anybody a better solution?
Thanks.
Victoria.
0 个评论
回答(1 个)
Walter Roberson
2016-5-31
If neither function uses graphics, then use spmd .
If one of the functions uses graphics, then you can use batch() or parfeval() for the other one.
It is not possible to have both functions use graphics.
If you need to update graphics with the results of the second function, then you will need to use TCP or UDP to send data back to the first function and have the first function do the graphics. This is the same method you must use if the second function needs to communicate anything back to the first function (or the first function needs to send anything to the second function.) The exception to this rule is that if you are using spmd you can use labSend() and labReceive()
7 个评论
Walter Roberson
2016-6-1
Unless it has changed in R2016a (and I see some hints it might have), MATLAB uses a single Java thread to do all graphics rendering. The data to be rendered needs to get transferred into the address space of that Java thread. Parallel workers (parfor, spmd, batch, parfeval) all operate in individual processes, not as threads so the data has to cross process boundaries.
Do not think of the parallel architecture as being multiple threads: look at it as being inherently a distributed architecture where the workers might be on different continents from each other.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Asynchronous Parallel Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!