Skip to content

Commit 6cd55b0

Browse files
authored
Merge pull request #633 from Bodo-inc/sahil/mpi-eg-quickstart
Add small MPI example to quickstart
2 parents e47f179 + 429539a commit 6cd55b0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
229 KB
Loading

docs/source/index.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ with ipp.Cluster() as rc:
6060
<source src="_static/basic.mp4"/>
6161
</video>
6262

63+
You can similarly run MPI code using IPyParallel:
64+
65+
```python
66+
import ipyparallel as ipp
67+
68+
def mpi_example():
69+
from mpi4py import MPI
70+
comm = MPI.COMM_WORLD
71+
return f"Hello World from rank {comm.Get_rank()}. total ranks={comm.Get_size()}"
72+
73+
# request an MPI cluster with 4 engines
74+
with ipp.Cluster(engines='mpi', n=4) as rc:
75+
# get a broadcast_view on the cluster which is best
76+
# suited for MPI style computation
77+
view = rc.broadcast_view()
78+
# run the mpi_example function on all engines in parallel
79+
r = view.apply_sync(mpi_example)
80+
# Retrieve and print the result from the engines
81+
print("\n".join(r))
82+
# at this point, the cluster processes have been shutdown
83+
```
84+
85+
![IPyParallel-MPI-Example](./_static/IPyParallel-MPI-Example.png)
86+
6387
Follow the [tutorial][] to learn more.
6488

6589
[tutorial]: ./tutorial/index

0 commit comments

Comments
 (0)