7
7
Distributed Arrays for Julia
8
8
9
9
*** NOTE***
10
- Distributed Arrays will only work on Julia v0.4.0 or later.
11
-
12
- ` DArray ` s have been removed from Julia Base library in v0.4 so it is now necessary to import the ` DistributedArrays ` package on all spawned processes.
10
+ This package will only work on Julia v0.7 or later.
13
11
14
12
``` julia
15
- @everywhere using DistributedArrays
13
+ using DistributedArrays
16
14
```
17
15
18
16
Distributed Arrays
@@ -76,12 +74,12 @@ Indexing via symbols is used for this, specifically symbols `:L`,`:LP`,`:l`,`:lp
76
74
are all equivalent. For example, ` d[:L] ` returns the localpart of ` d `
77
75
while ` d[:L]=v ` sets ` v ` as the localpart of ` d ` .
78
76
79
- * ` localindexes (a::DArray)` gives a tuple of the index ranges owned by the
77
+ * ` localindices (a::DArray)` gives a tuple of the index ranges owned by the
80
78
local process.
81
79
82
80
* ` convert(Array, a::DArray) ` brings all the data to the local process.
83
81
84
- Indexing a ` DArray ` (square brackets) with ranges of indexes always
82
+ Indexing a ` DArray ` (square brackets) with ranges of indices always
85
83
creates a ` SubArray ` , not copying any data.
86
84
87
85
@@ -154,7 +152,7 @@ following code accomplishes this::
154
152
left = mod (first (I[2 ])- 2 ,size (d,2 ))+ 1
155
153
right = mod ( last (I[2 ]) ,size (d,2 ))+ 1
156
154
157
- old = Array ( Bool, length (I[1 ])+ 2 , length (I[2 ])+ 2 )
155
+ old = Array { Bool} (undef , length (I[1 ])+ 2 , length (I[2 ])+ 2 )
158
156
old[1 , 1 ] = d[top , left] # left side
159
157
old[2 : end - 1 , 1 ] = d[I[1 ], left]
160
158
old[end , 1 ] = d[bot , left]
@@ -205,7 +203,7 @@ seen in this simple example:
205
203
``` julia
206
204
julia> addprocs (8 );
207
205
208
- julia> @everywhere using DistributedArrays
206
+ julia> using DistributedArrays
209
207
210
208
julia> A = fill (1.1 , (100 ,100 ));
211
209
@@ -227,7 +225,7 @@ Garbage Collection and DArrays
227
225
------------------------------
228
226
229
227
When a DArray is constructed (typically on the master process), the returned DArray objects stores information on how the
230
- array is distributed, which procesor holds which indexes and so on. When the DArray object
228
+ array is distributed, which procesor holds which indices and so on. When the DArray object
231
229
on the master process is garbage collected, all particpating workers are notified and
232
230
localparts of the DArray freed on each worker.
233
231
@@ -317,18 +315,19 @@ Example
317
315
This toy example exchanges data with each of its neighbors ` n ` times.
318
316
319
317
```
318
+ using Distributed
320
319
using DistributedArrays
321
320
addprocs(8)
322
- @everywhere importall DistributedArrays
323
- @everywhere importall DistributedArrays.SPMD
321
+ @everywhere using DistributedArrays
322
+ @everywhere using DistributedArrays.SPMD
324
323
325
- d_in=d=DArray(I->fill(myid(), (map(length,I)...)), (nworkers(), 2), workers(), [nworkers(),1])
326
- d_out=ddata()
324
+ d_in=d=DArray(I->fill(myid(), (map(length,I)..., )), (nworkers(), 2), workers(), [nworkers(),1])
325
+ d_out=ddata();
327
326
328
327
# define the function everywhere
329
328
@everywhere function foo_spmd(d_in, d_out, n)
330
329
pids = sort(vec(procs(d_in)))
331
- pididx = findfirst(pids, myid())
330
+ pididx = findfirst(isequal( myid()), pids )
332
331
mylp = d_in[:L]
333
332
localsum = 0
334
333
@@ -352,7 +351,7 @@ d_out=ddata()
352
351
end
353
352
354
353
# run foo_spmd on all workers
355
- spmd(foo_spmd, d_in, d_out, 10)
354
+ spmd(foo_spmd, d_in, d_out, 10, pids=workers() )
356
355
357
356
# print values of d_in and d_out after the run
358
357
println(d_in)
0 commit comments