Azzera filtri
Azzera filtri

How can I launch a parallel function?

3 visualizzazioni (ultimi 30 giorni)
María Victoria García
María Victoria García il 31 Mag 2016
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.

Risposte (1)

Walter Roberson
Walter Roberson il 31 Mag 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 Commenti
Walter Roberson
Walter Roberson il 1 Giu 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.
María Victoria García
María Victoria García il 2 Giu 2016
I have solved the problem with the GUI and the imshow command putting both in the same script and using this like main. The imshow command is in a periodic function within the main.
But now, I have three functions I want to work simutaneously. The main function will call the second function when a condition is true, but the main function must continue running at the same time. In addition, the second function contains a while loop. I need that this while loop was running at the same time that the main function is running. The same goes when the second function call the third function.
Is possible do this with batch or parfeval?
On the other hand, could I read data from the second function with UDP or TCP altough it has not finished?
I would be very grateful if you or anybody have any idea to do this. Thanks in advance.

Accedi per commentare.

Categorie

Scopri di più su Asynchronous Parallel Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by