How can I launch a parallel function?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 31 May 2016
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 Comments
Walter Roberson
on 1 Jun 2016
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.
See Also
Categories
Find more on Asynchronous Parallel Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!