You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/darray.md
+159Lines changed: 159 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,165 @@ across the workers in the Julia cluster in a relatively even distribution;
211
211
future operations on a `DArray` may produce a different distribution from the
212
212
one chosen by previous calls.
213
213
214
+
<!---->
215
+
216
+
### Explicit Processor Mapping of DArray Blocks
217
+
218
+
This feature allows you to control how `DArray` blocks (chunks) are assigned to specific processors or threads within the cluster. Fine-grained control over data locality can be crucial for optimizing the performance of certain distributed algorithms.
219
+
220
+
You specify the mapping using the optional `assignment` keyword argument in the `DArray` constructor functions (`DArray`, `DVector`, and `DMatrix`) and the `distribute` function.
221
+
222
+
The `assignment` argument accepts the following values:
223
+
224
+
*`:arbitrary` (Default):
225
+
226
+
* If `assignment` is not provided or is set to symbol `:arbitrary`, Dagger's scheduler assigns blocks to processors automatically. This is the default behavior.
227
+
*`:blockcyclic`:
228
+
229
+
* If `assignment` is set to `:blockcyclic`, `DArray` blocks are assigned to processors in a block-cyclic manner. Blocks are distributed cyclically across processors, iterating through the processors in increasing rank along the *last* dimension of the block distribution.
230
+
* Any other symbol used for `assignment` results in an error.
231
+
*`AbstractArray{<:Int, N}`:
232
+
233
+
* Provide an N-dimensional array of integer worker IDs. The dimension `N` must match the number of dimensions of the `DArray`.
234
+
* Dagger maps blocks to worker IDs in a block-cyclic manner. The block at index `(i, j, ...)` is assigned to the first thread of the processor with ID `assignment[i, j, ...]`. This pattern repeats in a block-cyclic fashion to assign all blocks.
235
+
*`AbstractArray{<:Processor, N}`:
236
+
237
+
* Provide an N-dimensional array of `Processor` objects. The dimension `N` must match the number of dimensions of the `DArray` blocks.
238
+
* Blocks are mapped in a block-cyclic manner according to the `Processor` objects in the `assignment` array. The block at index `(i, j, ...)` is assigned to the processor at `assignment[i, j, ...]`. This pattern repeats in a block-cyclic fashion to assign all blocks.
239
+
240
+
#### Examples and Usage
241
+
242
+
The `assignment` argument works similarly for `DArray`, `DVector`, and `DMatrix`, as well as the `distribute` function. The key difference lies in the dimensionality of the resulting distributed array:
243
+
244
+
*`DArray`: For N-dimensional distributed arrays.
245
+
246
+
*`DVector`: Specifically for 1-dimensional distributed arrays.
247
+
248
+
*`DMatrix`: Specifically for 2-dimensional distributed arrays.
249
+
250
+
*`distribute`: General function to distribute arrays.
251
+
252
+
Here are some examples using a setup with one processor and three worker processors.
253
+
254
+
First, let's create some sample arrays:
255
+
256
+
```julia
257
+
A =rand(7, 11) # 2D array
258
+
v =rand(15) # 1D array
259
+
M =rand(5, 5, 5) # 3D array
260
+
```
261
+
262
+
1.**Arbitrary Assignment:**
263
+
264
+
```julia
265
+
Ad =distribute(A, Blocks(2, 2), :arbitrary)
266
+
# DMatrix(A, Blocks(2, 2), :arbitrary)
267
+
268
+
vd =distribute(v, Blocks(3), :arbitrary)
269
+
# DVector(v, Blocks(3), :arbitrary)
270
+
271
+
Md =distribute(M, Blocks(2, 2, 2), :arbitrary)
272
+
# DArray(M, Blocks(2,2,2), :arbitrary)
273
+
```
274
+
275
+
This creates distributed arrays with the specified block sizes, and Dagger assigns the blocks to processors arbitrarily. For example, the assignment for`Ad` might look like this:
This assigns blocks cyclically along the last dimension across the available processors with increasing rank. For the 2D case (`Ad`), the assignment will look like this:
0 commit comments