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

dataparallel computingParallel Computing Toolbox

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?

Best 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.
Related Question