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: README.md
+36-36Lines changed: 36 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,27 +145,27 @@ each process needs the immediate neighbor cells of its local chunk. The
145
145
following code accomplishes this::
146
146
147
147
```julia
148
-
functionlife_step(d::DArray)
149
-
DArray(size(d),procs(d)) do I
150
-
top =mod(first(I[1])-2,size(d,1))+1
151
-
bot =mod( last(I[1]) ,size(d,1))+1
152
-
left =mod(first(I[2])-2,size(d,2))+1
153
-
right =mod( last(I[2]) ,size(d,2))+1
154
-
155
-
old =Array{Bool}(undef, length(I[1])+2, length(I[2])+2)
156
-
old[1 , 1 ] = d[top , left] # left side
157
-
old[2:end-1, 1 ] = d[I[1], left]
158
-
old[end , 1 ] = d[bot , left]
159
-
old[1 , 2:end-1] = d[top , I[2]]
160
-
old[2:end-1, 2:end-1] = d[I[1], I[2]] # middle
161
-
old[end , 2:end-1] = d[bot , I[2]]
162
-
old[1 , end ] = d[top , right] # right side
163
-
old[2:end-1, end ] = d[I[1], right]
164
-
old[end , end ] = d[bot , right]
165
-
166
-
life_rule(old)
167
-
end
148
+
functionlife_step(d::DArray)
149
+
DArray(size(d),procs(d)) do I
150
+
top =mod(first(I[1])-2,size(d,1))+1
151
+
bot =mod( last(I[1]) ,size(d,1))+1
152
+
left =mod(first(I[2])-2,size(d,2))+1
153
+
right =mod( last(I[2]) ,size(d,2))+1
154
+
155
+
old =Array{Bool}(undef, length(I[1])+2, length(I[2])+2)
156
+
old[1 , 1 ] = d[top , left] # left side
157
+
old[2:end-1, 1 ] = d[I[1], left]
158
+
old[end , 1 ] = d[bot , left]
159
+
old[1 , 2:end-1] = d[top , I[2]]
160
+
old[2:end-1, 2:end-1] = d[I[1], I[2]] # middle
161
+
old[end , 2:end-1] = d[bot , I[2]]
162
+
old[1 , end ] = d[top , right] # right side
163
+
old[2:end-1, end ] = d[I[1], right]
164
+
old[end , end ] = d[bot , right]
165
+
166
+
life_rule(old)
168
167
end
168
+
end
169
169
```
170
170
171
171
As you can see, we use a series of indexing expressions to fetch
@@ -176,19 +176,19 @@ to the data, yielding the needed `DArray` chunk. Nothing about `life_rule`
176
176
is `DArray`\ -specific, but we list it here for completeness::
177
177
178
178
```julia
179
-
functionlife_rule(old)
180
-
m, n =size(old)
181
-
new =similar(old, m-2, n-2)
182
-
for j =2:n-1
183
-
for i =2:m-1
184
-
nc =+(old[i-1,j-1], old[i-1,j], old[i-1,j+1],
185
-
old[i ,j-1], old[i ,j+1],
186
-
old[i+1,j-1], old[i+1,j], old[i+1,j+1])
187
-
new[i-1,j-1] = (nc ==3|| nc ==2&& old[i,j])
188
-
end
179
+
functionlife_rule(old)
180
+
m, n =size(old)
181
+
new =similar(old, m-2, n-2)
182
+
for j =2:n-1
183
+
for i =2:m-1
184
+
nc =+(old[i-1,j-1], old[i-1,j], old[i-1,j+1],
185
+
old[i ,j-1], old[i ,j+1],
186
+
old[i+1,j-1], old[i+1,j], old[i+1,j+1])
187
+
new[i-1,j-1] = (nc ==3|| nc ==2&& old[i,j])
189
188
end
190
-
new
191
189
end
190
+
new
191
+
end
192
192
```
193
193
194
194
Numerical Results of Distributed Computations
@@ -268,7 +268,7 @@ SPMD, i.e., a Single Program Multiple Data mode is implemented by submodule `Dis
268
268
269
269
The same block of code is executed concurrently on all workers using the `spmd` function.
270
270
271
-
```
271
+
```julia
272
272
# define foo() on all workers
273
273
@everywherefunctionfoo(arg1, arg2)
274
274
....
@@ -314,7 +314,7 @@ Example
314
314
315
315
This toy example exchanges data with each of its neighbors `n` times.
316
316
317
-
```
317
+
```julia
318
318
using Distributed
319
319
using DistributedArrays
320
320
addprocs(8)
@@ -383,7 +383,7 @@ Nested `spmd` calls
383
383
As `spmd` executes the the specified function on all participating nodes, we need to be careful with nesting `spmd` calls.
384
384
385
385
An example of an unsafe(wrong) way:
386
-
```
386
+
```julia
387
387
functionfoo(.....)
388
388
......
389
389
spmd(bar, ......)
@@ -401,7 +401,7 @@ spmd(foo,....)
401
401
In the above example, `foo`, `bar` and `baz` are all functions wishing to leverage distributed computation. However, they themselves may be currenty part of a `spmd` call. A safe way to handle such a scenario is to only drive parallel computation from the master process.
402
402
403
403
The correct way (only have the driver process initiate `spmd` calls):
404
-
```
404
+
```julia
405
405
functionfoo()
406
406
......
407
407
myid()==1&&spmd(bar, ......)
@@ -418,7 +418,7 @@ spmd(foo,....)
418
418
```
419
419
420
420
This is also true of functions which automatically distribute computation on DArrays.
0 commit comments