Skip to content

Commit a47be19

Browse files
authored
Update README.md
Cleaning up syntax highlighting
1 parent 85243f0 commit a47be19

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,27 @@ each process needs the immediate neighbor cells of its local chunk. The
145145
following code accomplishes this::
146146

147147
```julia
148-
function life_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+
function life_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)
168167
end
168+
end
169169
```
170170

171171
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`
176176
is `DArray`\ -specific, but we list it here for completeness::
177177

178178
```julia
179-
function life_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+
function life_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])
189188
end
190-
new
191189
end
190+
new
191+
end
192192
```
193193

194194
Numerical Results of Distributed Computations
@@ -268,7 +268,7 @@ SPMD, i.e., a Single Program Multiple Data mode is implemented by submodule `Dis
268268

269269
The same block of code is executed concurrently on all workers using the `spmd` function.
270270

271-
```
271+
```julia
272272
# define foo() on all workers
273273
@everywhere function foo(arg1, arg2)
274274
....
@@ -314,7 +314,7 @@ Example
314314

315315
This toy example exchanges data with each of its neighbors `n` times.
316316

317-
```
317+
```julia
318318
using Distributed
319319
using DistributedArrays
320320
addprocs(8)
@@ -383,7 +383,7 @@ Nested `spmd` calls
383383
As `spmd` executes the the specified function on all participating nodes, we need to be careful with nesting `spmd` calls.
384384

385385
An example of an unsafe(wrong) way:
386-
```
386+
```julia
387387
function foo(.....)
388388
......
389389
spmd(bar, ......)
@@ -401,7 +401,7 @@ spmd(foo,....)
401401
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.
402402

403403
The correct way (only have the driver process initiate `spmd` calls):
404-
```
404+
```julia
405405
function foo()
406406
......
407407
myid()==1 && spmd(bar, ......)
@@ -418,7 +418,7 @@ spmd(foo,....)
418418
```
419419

420420
This is also true of functions which automatically distribute computation on DArrays.
421-
```
421+
```julia
422422
function foo(d::DArray)
423423
......
424424
myid()==1 && map!(bar, d)

0 commit comments

Comments
 (0)