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

6 Ansichten (letzte 30 Tage)
Juan Ramirez
Juan Ramirez am 9 Mai 2018
Bearbeitet: Dejia Kong am 15 Jan. 2020
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?

Akzeptierte Antwort

OCDER
OCDER am 9 Mai 2018
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 Kommentar
Dejia Kong
Dejia Kong am 15 Jan. 2020
Bearbeitet: Dejia Kong am 15 Jan. 2020
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by