I have a MATLAB program that I want to run in parallel so that it runs faster. However, when I do that parallel workers seem not to be able to access global variables created beforehand. Here is what my code looks like:
createData % a .m file that creates a global variable (Var)
parfor i:j
processData() % a function that is dependent on some global variables
end
However, I get an error message undefined function or variable Var
. I've already included a call for global
variables global Var
inside the function processData()
but this is not working either. Is there any way of making global
variables visible within the parallel loop?
This is not the same question as here as I declared global variables outside of the parfor
loop and want to access them within the loop with out the need to modify or update the its value across workers of the parallel loop.