MATLAB: How could I process a global variable in parfor

Parallel Computing Toolboxrobotic toolbox system

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?

Best Answer

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()
Related Question