Parallel Computing Data Transfer? (Need data edited in parfor-loop and returned)

I am using parallel computing (the Parallel Computing Toolbox) to simulate population dynamics of a population over a large area in order to not run out of memory, which occurs when working on a single node. I am trying to have each worker run the dynamics for a specific area over a day and then return the new population. When I try to send data to a parfor-loop, I get the error message that "the PARFOR loop cannot run due to the way the X (population) variable is used." How should I go about sending the initial population data to the workers in the loop and then sending the data out of the loop to the initial node?

 채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 11일
if your parfor loop is extracting 2d slices of an array, then it can only do that if it does not modify the array and the entire array is sent to every worker.
parfor can only reduce the memory transfer if the parfor index variable is used by itself, or itself plus a constant, as an entire dimension. No 2d strips of the array, no k:k+7 where k is the loop variable. Basically one row or one column or one plane at a time.
If you use parfeval instead then you can pass in whatever chunk of memory you want, but you have to do the memory slicing yourself.

댓글 수: 3

Thank you for the help! How does one use the index variable by itself to specify a dimension? For instance, I would have it such that each plane of the array represents a different area.
parfor k=1:size(M, 3)
slice = M(:, :, k) ;
%now work with slice
%if you modified slice
M(:, :, k) = slice;
end
Thank you so much for all your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 8월 11일

댓글:

2020년 8월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by