distributed

Create distributed array from data in client workspace

Syntax

D = distributed(X)

Description

D = distributed(X) creates a distributed array from X. X is an array stored on the MATLAB client workspace, and D is a distributed array stored in parts on the workers of the open parallel pool.

Constructing a distributed array from local data this way is appropriate only if the MATLAB client can store the entirety of X in its memory. To construct large distributed arrays, use one of the constructor methods such as ones(___,'distributed'), zeros(___,'distributed'), etc.

If the input argument is already a distributed array, the result is the same as the input.

Use gather to retrieve the distributed array elements from the pool back to an array in the MATLAB workspace.

Tips

  • A distributed array is created on the workers of the existing parallel pool. If no pool exists, distributed will start a new parallel pool, unless the automatic starting of pools is disabled in your parallel preferences. If there is no parallel pool and distributed cannot start one, the result is the full array in the client workspace.

Examples

Create a small array and distribute it:

Nsmall = 50;
D1 = distributed(magic(Nsmall));

Create a large distributed array directly, using a build method:

Nlarge = 1000;
D2 = rand(Nlarge,'distributed');

Retrieve elements of a distributed array, and note where the arrays are located by their Class:

D3 = gather(D2);
whos
  Name           Size           Bytes  Class

  D1            50x50             733  distributed
  D2          1000x1000           733  distributed
  D3          1000x1000       8000000  double
  Nlarge         1x1                8  double
  Nsmall         1x1                8  double
Was this topic helpful?