I'm working on a complicated function that calls several subfunctions (within the same file). To pass data around, the setappdata
/getappdata
mechanism is used occasionally. Moreover, some subfunctions contain persistent
variables (initialized once in order to save computations later).
I've been considering whether this function can be executed on several workers in a parallel pool, but became worried that there might be some unintended data sharing (which would otherwise be unique to each worker).
My question is - how can I tell if the data in global
and/or persistent
and/or appdata
is shared between the workers or unique to each one?
Several possibly-relevant things:
- In my case, tasks are completely parallel and their results should not affect each other in any way (parallelization is done simply to save time).
- There aren't any temporary files or folders being created, so there is no risk of one worker mistakenly reading the files that were left by another.
- All
persistent
and appdata-stored variables are created/assigned within subfunction of theparfor
.
I know that each worker corresponds to a new process with its own memory space (and presumably, global
/persistent
/appdata
workspace). Based on that and on this official comment, I'd say it's probable that such sharing does not occur... But how do we ascertain it?