parfor: why is 2x memory being used for sliced variable?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Juan Ramirez
el 9 de Mayo de 2018
Editada: Dejia Kong
el 15 de En. de 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?
0 comentarios
Respuesta aceptada
OCDER
el 9 de Mayo de 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 comentario
Dejia Kong
el 15 de En. de 2020
Editada: Dejia Kong
el 15 de En. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!