| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Parallel Computing Toolbox |
| Contents | Index |
| Learn more about Parallel Computing Toolbox |
| On this page… |
|---|
All built-in data types and data structures supported by MATLAB software are also supported in the MATLAB parallel computing environment. This includes arrays of any number of dimensions containing numeric, character, logical values, cells, or structures; but not function handles or user-defined objects. In addition to these basic building blocks, the MATLAB parallel computing environment also offers different types of arrays.
When you create a nondistributed array, MATLAB constructs a separate array in the workspace of each lab and assigns a common variable to them. Any operation performed on that variable affects all individual arrays assigned to it. If you display from lab 1 the value assigned to this variable, all labs respond by showing the array of that name that resides in their workspace.
The state of a nondistributed array depends on the value of that array in the workspace of each lab:
A replicated array resides in the workspaces of all labs, and its size and content are identical on all labs. When you create the array, MATLAB assigns it to the same variable on all labs. If you display in spmd the value assigned to this variable, all labs respond by showing the same array.
spmd, A = magic(3), end
LAB 1 LAB 2 LAB 3 LAB 4
| | |
8 1 6 | 8 1 6 | 8 1 6 | 8 1 6
3 5 7 | 3 5 7 | 3 5 7 | 3 5 7
4 9 2 | 4 9 2 | 4 9 2 | 4 9 2A variant array also resides in the workspaces of all labs, but its content differs on one or more labs. When you create the array, MATLAB assigns a different value to the same variable on all labs. If you display the value assigned to this variable, all labs respond by showing their version of the array.
spmd, A = magic(3) + labindex - 1, end
LAB 1 LAB 2 LAB 3 LAB 4
| | |
8 1 6 | 9 2 7 | 10 3 8 | 11 4 9
3 5 7 | 4 6 9 | 5 7 9 | 6 8 10
4 9 2 | 5 10 3 | 6 11 4 | 7 12 5A replicated array can become a variant array when its value becomes unique on each lab.
spmd
B = magic(3); %replicated on all labs
B = B + labindex; %now a variant array, different on each lab
endA private array is defined on one or more, but not all labs. You could create this array by using the lab index in a conditional statement, as shown here:
spmd
if labindex >= 3, A = magic(3) + labindex - 1, end
end
LAB 1 LAB 2 LAB 3 LAB 4
| | |
A is | A is | 10 3 8 | 11 4 9
undefined | undefined | 5 7 9 | 6 8 10
| 6 11 4 | 7 12 5With replicated and variant arrays, the full content of the array is stored in the workspace of each lab. Codistributed arrays, on the other hand, are partitioned into segments, with each segment residing in the workspace of a different lab. Each lab has its own array segment to work with. Reducing the size of the array that each lab has to store and process means a more efficient use of memory and faster processing, especially for large data sets.
This example distributes a 3-by-10 replicated array A over four labs. The resulting array D is also 3-by-10 in size, but only a segment of the full array resides on each lab.
spmd
A = [11:20; 21:30; 31:40];
D = codistributed(A);
getLocalPart(D)
end
LAB 1 LAB 2 LAB 3 LAB 4
| | |
11 12 13 | 14 15 16 | 17 18 | 19 20
21 22 23 | 24 25 26 | 27 28 | 29 30
31 32 33 | 34 35 36 | 37 38 | 39 40For more details on using codistributed arrays, see Working with Codistributed Arrays.
![]() | Math with Codistributed Arrays | Working with Codistributed Arrays | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |