codistributed - Access elements of arrays distributed among workers in parallel pool - MATLAB (original) (raw)

Access elements of arrays distributed among workers in parallel pool

Description

Arrays partitioned among the workers in a parallel pool are accessible from the workers as codistributed array objects. Codistributed array objects on workers that you create inside spmd statements or from within task functions of communicating jobs are accessed as distributed arrays on the client.

Creation

Use either the codistributed function, or the codistributed.build function to create a codistributed object.

Syntax

Description

[C](#mw%5F4d261fd2-cd09-4866-97bd-4db57d6ae163) = codistributed([X](#mw%5Fa86d67d7-6bcb-451b-a9cb-58bcfb6a1bbf)) distributes a replicated array X using the default distribution scheme and returns a codistributed array C. X must be a replicated array, that is, it must have the same value on all workers. The size of array C is the same as the size of X.

example

[C](#mw%5F4d261fd2-cd09-4866-97bd-4db57d6ae163) = codistributed([X](#mw%5Fa86d67d7-6bcb-451b-a9cb-58bcfb6a1bbf),[workerIndex](#mw%5F45faf75a-eafb-43a2-853b-c395fb3da15d)) distributes a local array X that resides on the worker identified byworkerIndex, using the default codistributor. The local arrayX must be defined on all workers, but the function uses only theWorkerIndex to construct C.size(C) is the same as the size of X.

[C](#mw%5F4d261fd2-cd09-4866-97bd-4db57d6ae163) = codistributed([X](#mw%5Fa86d67d7-6bcb-451b-a9cb-58bcfb6a1bbf),[codist](#mw%5F01a18da1-f827-47f2-981c-a3b612ef1480)) distributes a replicated array X using the distribution scheme defined by codistributor codist. X must be a replicated array, that is, it must have the same value on all workers. The size ofC is the same as the size of X. For information on constructing codistributor objects, see codistributor1d and codistributor2dbc.

example

[C](#mw%5F4d261fd2-cd09-4866-97bd-4db57d6ae163) = codistributed([X](#mw%5Fa86d67d7-6bcb-451b-a9cb-58bcfb6a1bbf),[workerIndex](#mw%5F45faf75a-eafb-43a2-853b-c395fb3da15d),[codist](#mw%5F01a18da1-f827-47f2-981c-a3b612ef1480)) distributes a local array X that resides on the worker identified byworkerIndex, using the codistributor codist. The local array X must be defined on all workers, but the function uses only the WorkerIndex to construct C.size(C) is the same as the size of X.

[C](#mw%5F4d261fd2-cd09-4866-97bd-4db57d6ae163) = codistributed([C1](#mw%5Fe7ba16b8-0ffb-4eeb-8b78-169b0180a328),[codist](#mw%5F01a18da1-f827-47f2-981c-a3b612ef1480)) accepts an array C1 that is already codistributed, and redistributes it into C according to the distribution scheme defined by the codistributor codist. This syntax is equivalent to C = redistribute(C1,codist). If the existing distribution scheme forC1 is the same as that specified in codist, then the result C is the same as the input C1.

Input Arguments

expand all

X — Array to distribute

array

Array to distribute, specified as an array.

codist — Codistributor

codistributor1d object | codistributor2dbc object

Codistributor, specified as a codistributor1d orcodistributor2dbc object. For information on creating codistributors, see codistributor1d and codistributor2dbc. To use the default distribution scheme, you can specify a codistributor constructor without arguments.

workerIndex — Index of worker

positive integer scalar

Index of the worker where the local array is stored, specified as a positive integer scalar.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

C1 — Codistributed array to redistribute

codistributed array

Codistributed array to redistribute, specified as a codistributed array.

Output Arguments

expand all

C — Codistributed array

codistributed array

Codistributed array stored on parts of workers in a parallel pool.

Object Functions

gather Transfer distributed array, Composite object, orgpuArray object to local workspace
getCodistributor Codistributor object for existing codistributed array
getLocalPart Local portion of codistributed array
globalIndices Global indices for local part of codistributed array
Inf Create codistributed array of all Inf values
iscodistributed True for codistributed array
redistribute Redistribute codistributed array with another distribution scheme

The object functions for codistributed arrays are too numerous to list here. Most resemble and behave the same as built-in MATLAB® functions. For a complete list of object functions, see Run MATLAB Functions with Distributed Arrays.

Among the object functions there are several for examining the characteristics of the array itself. Most behave like the MATLAB functions of the same name.

Examples

collapse all

Create Codistributed Arrays

Create a 1000-by-1000 codistributed array C1 using the default distribution scheme.

parpool('Processes',4) spmd N = 1000; X = magic(N);
C1 = codistributed(X); end

Array X is replicated on every worker, and arrayC1 is partitioned among the workers.

Create Codistributed Arrays with Distribution Scheme

Create a 1000-by-1000 codistributed array C2, distributed by rows (over the first dimension) with the codistributor1d distribution scheme.

spmd N = 1000; X = magic(N); C2 = codistributed(X,codistributor1d(1)); end

Tips

The gather function performs the inverse ofcodistributed. Use the gather function to retrieve codistributed arrays into the client work space.

Version History

Introduced in R2008b