How could I process a global variable in parfor
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dingqiao Zhu
am 19 Jan. 2016
Kommentiert: Walter Roberson
am 22 Jan. 2016
I'm using Robotic Toolbox System in Matlab to process real-time data which are caught from a robot(which is using ROS too).
The situation is, if I caught data from a robot, I have to use a global variable to keep the real-time data. However, parfor can't process a global variable because this method are designed forbidding dependency between different loop. Can I convert global variable to local variable?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Jan. 2016
No. You cannot communicate between the workers of a parfor in order to update a variable.
As well, parfor requires that the results be order-independent, that you can run the loops in any order and get the same result (to within roundoff.) If you have a variable that might update part-way through the run then that breaks order independence, as the iterations run first would have used the previous value but the later loops would have used the new values.
If you need to update a variable while parallel processing is happening, you need to use SPMD and labsend() / labreceive()
2 Kommentare
Walter Roberson
am 22 Jan. 2016
Except that instead of the initial parfor shown there, you should use parfevalOnAll to execute the setup function once on each worker.
Note that this will not work if the global variable is mentioned directly in the body of the parfor. If you are doing that then change the name of the variable in the direct text and above the parfor assign that new name the value from the global variable.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!