spmdCat - Concatenate arrays on spmd workers - MATLAB (original) (raw)
Concatenate arrays on spmd
workers
Since R2022b
Syntax
Description
[B](#mw%5F020886fa-5d2f-4711-83a7-cce2c8ca7995) = spmdCat([A](#mw%5F44520e69-4bd5-4b75-865d-6d0b5e9f70b7))
horizontally concatenates the array A
defined on each worker running anspmd block or communicating job.
When you use parfor, parfeval, orparfevalOnAll to run code on a parallel pool, the workers are independent and do not communicate with each other. If you usespmdCat
on these workers, the result is the same as usingspmdCat
on a client.
You can use spmdCat
only if A
can be concatenated along the second dimension.
This function concatenates the arrays along the second dimension, then stores the result on all the workers. The function takes the value of A
from each worker and concatenates the results in order of the worker index. To get the index of a worker, use the spmdIndex function. For example, spmdCat(spmdIndex)
returns1:spmdSize
, where spmdSize is the number of workers running the current spmd
block or communicating job.
If one worker is running the current spmd
block,B
is equal to A
.
[B](#mw%5F020886fa-5d2f-4711-83a7-cce2c8ca7995) = spmdCat([A](#mw%5F44520e69-4bd5-4b75-865d-6d0b5e9f70b7),[dim](#mw%5F2a55e0b5-4a01-4379-9611-9f7c4f4b3336))
concatenates A
along the dimension dim
.
You can use spmdCat
only if A
concatenates along the dimension dim
when all the arrays have compatible sizes. The arrays have compatible sizes when the lengths of the dimensions match except for the operating dimension dim
).
[B](#mw%5F020886fa-5d2f-4711-83a7-cce2c8ca7995) = spmdCat([A](#mw%5F44520e69-4bd5-4b75-865d-6d0b5e9f70b7),[dim](#mw%5F2a55e0b5-4a01-4379-9611-9f7c4f4b3336),[destination](#mw%5F91400794-73ff-4996-a902-537720157ae5))
concatenates A
and stores the result on only one worker.
Examples
This example shows how to use spmdCat
to concatenate a scalar held on each worker in an spmd
block.
Create a parallel pool with four workers.
Create an spmd
block. By default, each worker in the pool runs the spmd
block. Store the value returned byspmdIndex
on each worker as A
, then usespmdCat
to concatenate the values of A
defined on each worker.
Unless you specify a destination, the spmdCat
function stores the result of concatenation on every worker. On the client, the result is a Composite object. To get the result, index into theComposite
object.
spmd B = spmdCat(spmdIndex); end B{1}
Input Arguments
Input array, specified as a scalar, vector, matrix, multidimensional array, table, timetable, or any MATLAB variable that supports concatenation.
Example: A = magic(3)
Dimension, specified as a positive integer. For example, if A is a 2-by-2 matrix on all workers, then spmdCat(A,1)
concatenates A vertically and returns a 2_N_-by-2 matrix, where N is the number of workers running the current spmd block. Calling spmdCat(A,2)
concatenates horizontally and returns a 2-by-2_N_ matrix.
dim
must be either 1
or 2
for table or timetable input.
Index of destination worker, specified as a positive integer. The value of this input must be less than or equal to the output of the spmdSize
function in the current spmd
block or communicating job.
When you specify this input, the function stores the value of B
only on the worker with this index. The B
output is still defined on all the workers that run spmdCat
. On the worker whose index is equal to destination
, B is the result of the concatenation. On all the other workers, B
is[]
.
Output Arguments
Output array, returned as any MATLAB variable of the same type as A.
If you specify destination, B
is the result of the concatenation on the worker whose index is equal todestination
. On all the other workers, B
is[]
.
Algorithms
This figure shows how the spmdCat
function concatenatesA
with the value on other workers when you callspmdCat(A)
.
Extended Capabilities
Version History
Introduced in R2022b