'parfor' Memory Usage Greater Than Expected

5 views (last 30 days)
Jay on 5 Sep 2014
Commented: Jay on 12 Sep 2014
Just before the execution of a particular loop in my code the memory usage will be ~6GB.
If I use 'for' then the memory usage will increase by ~600MB during execution of a single loop and drop back down.
If I use 'parfor' with just 2 workers the memory usage will exceed my 32GB of RAM and 32GB of swap.
Here is the loop:
parfor n=1:length( loop_Unique_Handle_Object_Array )
result{n} = someFunction( shared_Data,...
loop_Unique_Handle_Object_Array(n) );
'shared_Data' is 100MB
Each instance of loop_Unique_Handle_Object_Array is 200MB
I dont understand why the amount of RAM required by 'parfor' is greater than the amount required by 'for' * numWorkers + Overhead. Is this a result of using handle objects?

Accepted Answer

Matt J
Matt J on 5 Sep 2014
Edited: Matt J on 5 Sep 2014
Is this a result of using handle objects?
Possibly. All data that a handle object points to will be cloned and transmitted to the workers. It's not clear how you would have measured the memory footprint of everything your handle object points to and concluded that it is 200MB. MATLAB doesn't have any direct tools that would let you measure this footprint (whos() will not be reliable, in particular).
An easy test would be to just do a simplified parfor which only broadcasts the handle objects
parfor n=1:length( loop_Unique_Handle_Object_Array )
result{n} = loop_Unique_Handle_Object_Array(n);
Jay on 12 Sep 2014
Excellent, that looks real handy. I just ran into a different problem involving parfor and function handles that I think this may fix.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!