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?

 Accepted Answer

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 Comments

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

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!