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

6 ビュー (過去 30 日間)
Juan Ramirez
Juan Ramirez 2018 年 5 月 9 日
編集済み: Dejia Kong 2020 年 1 月 15 日
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 Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by