MATLAB: Is MATLAB memory utilized inefficiently when distributing an array to workers using Parallel Computing Toolbox 4.3 (R2010a)

Parallel Computing Toolbox

I am using the following code to distribute an array to local workers on my machine:
A = ones(10000);
spmd
D = codistributed(A);
end
However, as soon as the SPMD block starts execution, I find that the memory utilization of my client MATLAB process rises to several times the size of the matrix 'A', during which time data is distributed to the worker processes. Eventually, the memory utilization settles to reasonable values, i.e. the previously occupied memory is released. I would like MATLAB to use my client process' memory more efficiently.

Best Answer

When distributing data to workers, the client process is required to perform serialization of the data. This initially occupies a large amount of memory until the data distribution is complete.
In order to avoid this memory from being allocated on the client, use distributed arrays as follows:
A = distributed.ones(10000);
or
spmd
A = codistributed.ones(10000);
end