Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB PARFOR: memory management: shared memory or not?

I don't understand how parfor cicle in Matlab parallel computing toolbox works with the memory: I read it share the memory between all workers (then I think every worker (core) can access the memory location of interest without making a local copy) but others references tell me that every core makes a local copy of memory (variables etc.) where it works! what is the answer?Parfor has shared memory system and not makes copies of data or every worker has a local copy of data? Thanks

like image 391
volperossa Avatar asked Oct 23 '25 14:10

volperossa


1 Answers

Since PARFOR can operate across multiple machines if you are using an MDCS cluster, then it must be able to copy the required data to the workers. As it happens, it also copies data even if the workers are on the same host as your desktop MATLAB. Part of the reason for this is that MATLAB has no means of understanding when it is safe to share arrays. Note that this applies to 'broadcast' data, not 'sliced' data - when an array is 'sliced', only the relevant portions are sent to each worker. In the following contrived example:

broadcast = rand(400);
slicedIn  = rand(400);
parfor idx = 1:400
    slicedOut(idx) = numel(broadcast) + sum(slicedIn(:, idx));
end

then all of broadcast is copied to each worker; whereas only the required pieces of slicedIn and slicedOut are copied. More here: http://www.mathworks.co.uk/help/distcomp/advanced-topics.html#bq_of7_-1

like image 58
Edric Avatar answered Oct 26 '25 07:10

Edric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!