parfor: why is 2x memory being used for sliced variable?

6 次查看(过去 30 天)
I would like to use parfor to register a series of 2D images, which are stored in a 3D matrix called cube. In order to do this with parfor I'm storing the image cube as a cell array cube_cell where each element cube_cell{i} is a 2D array. I perform the loop as follows:
fixed = cube_cell{1};
[optimizer, metric] = imregconfig('monomodal');
parfor i=2:nframes
cube_cell{i} = imregister(cube_cell{i},fixed,'translation');
end
I thought cube_cell would be a slice variable, so that the entire cell array would be broken into pieces, but I found that the memory consumption jumps by a factor of 2 once the parfor loop gets started. I have many images, so this is a lot of memory. I guess 2x is better than 8x since I have 8 cores, but am I doing something wrong?

采纳的回答

OCDER
OCDER 2018-5-9
Seems good to me.
The memory consumption may not always be due to copying the entire cube_cell to all worker. Initializing a parpool via parfor will increase memory consumption as your computer opens up another MATLAB worker to do the parallel processing. Once the other worker is ready, THEN a slice of cube_cell is sent to the worker to do the math.
If numel(cube_cell) == 9 and you use 8 cores, then you could have 2 copies of cube_cell in your computer (1 full copy + 8 slices in 8 workers) until the computation is finished. The trade-off for parallel processing is time vs memory.
To save memory, see if you can process images in uint32 matrices instead of double matrices.
  1 个评论
Dejia Kong
Dejia Kong 2020-1-15
编辑:Dejia Kong 2020-1-15
I thought the sliced variables can do some things like passing pointers so that we can avoid using 2x memory. Seems I was wrong?
It is exactly the same as my slicing the data mannually, right? Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by