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
SPMD, i.e., a Single Program Multiple Data mode is implemented by submodule `DistributedArrays.SPMD`. In this mode the same function is executed in parallel on all participating nodes. This is a typical style of MPI programs where the same program is executed on all processors. A basic subset of MPI-like primitives are currently supported. As a programming model it should be familiar to folks with an MPI background.
258
288
259
289
The same block of code is executed concurrently on all workers using the `spmd` function.
260
290
261
-
```
291
+
```julia
262
292
# define foo() on all workers
263
293
@everywherefunctionfoo(arg1, arg2)
264
294
....
@@ -299,12 +329,14 @@ consecutive `bcast` calls.
299
329
import it explcitly, or prefix functions that can can only be used in spmd mode with `SPMD.`, for example,
300
330
`SPMD.sendto`.
301
331
332
+
333
+
302
334
Example
303
335
-------
304
336
305
337
This toy example exchanges data with each of its neighbors `n` times.
306
338
307
-
```
339
+
```julia
308
340
using Distributed
309
341
using DistributedArrays
310
342
addprocs(8)
@@ -348,6 +380,8 @@ println(d_in)
348
380
println(d_out)
349
381
```
350
382
383
+
384
+
351
385
SPMD Context
352
386
------------
353
387
@@ -368,12 +402,13 @@ on all participating `pids`. Else they will be released when the context object
368
402
on the node that created it.
369
403
370
404
405
+
371
406
Nested `spmd` calls
372
407
-------------------
373
408
As `spmd` executes the the specified function on all participating nodes, we need to be careful with nesting `spmd` calls.
374
409
375
410
An example of an unsafe(wrong) way:
376
-
```
411
+
```julia
377
412
functionfoo(.....)
378
413
......
379
414
spmd(bar, ......)
@@ -391,7 +426,7 @@ spmd(foo,....)
391
426
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.
392
427
393
428
The correct way (only have the driver process initiate `spmd` calls):
394
-
```
429
+
```julia
395
430
functionfoo()
396
431
......
397
432
myid()==1&&spmd(bar, ......)
@@ -408,7 +443,7 @@ spmd(foo,....)
408
443
```
409
444
410
445
This is also true of functions which automatically distribute computation on DArrays.
0 commit comments