Skip to content

Commit b375aeb

Browse files
committed
add broadcast view example notebook, docker-compose file
1 parent 869460a commit b375aeb

File tree

6 files changed

+3182
-1019
lines changed

6 files changed

+3182
-1019
lines changed

docs/source/examples/broadcast/Broadcast view.ipynb

Lines changed: 432 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM jupyter/scipy-notebook:4a6f5b7e5db1
2+
RUN mamba install -yq openmpi mpi4py
3+
RUN pip install --upgrade https://github.com/ipython/ipyparallel/archive/HEAD.tar.gz

docs/source/examples/MPI Broadcast.ipynb renamed to docs/source/examples/broadcast/MPI Broadcast.ipynb

Lines changed: 42 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@
1919
{
2020
"cell_type": "code",
2121
"execution_count": null,
22-
"metadata": {
23-
"collapsed": false,
24-
"jupyter": {
25-
"outputs_hidden": false
26-
}
27-
},
22+
"metadata": {},
2823
"outputs": [],
2924
"source": [
3025
"import socket\n",
@@ -40,37 +35,48 @@
4035
"metadata": {},
4136
"source": [
4237
"For this demo, I will connect to a cluster with engines started with MPI.\n",
43-
"If you have MPI and mpi4py on your machine, you can start a local cluster with MPI with:\n",
4438
"\n",
45-
" ipcluster start -n 8 --engines=MPI --profile mpi"
39+
"One way to do so would be:\n",
40+
"\n",
41+
" ipcluster start -n 64 --engines=MPI --profile mpi\n",
42+
" \n",
43+
"In this directory is a docker-compose file to simulate multiple engine sets in "
4644
]
4745
},
4846
{
4947
"cell_type": "code",
5048
"execution_count": null,
51-
"metadata": {
52-
"collapsed": false,
53-
"jupyter": {
54-
"outputs_hidden": false
55-
}
56-
},
49+
"metadata": {},
5750
"outputs": [],
5851
"source": [
59-
"mpi_profile = 'mpi'\n",
60-
"rc = ipp.Client(profile=mpi_profile)\n",
61-
"eall = rc[:]\n",
62-
"root = rc[-1]"
52+
"rc = ipp.Client(profile=\"mpi\")\n",
53+
"rc.wait_for_engines(32)\n",
54+
"eall = rc.broadcast_view(coalescing=True)\n",
55+
"root = rc[0]"
6356
]
6457
},
6558
{
6659
"cell_type": "code",
6760
"execution_count": null,
68-
"metadata": {
69-
"collapsed": false,
70-
"jupyter": {
71-
"outputs_hidden": false
72-
}
73-
},
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"rc.ids"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"root['a'] = 5"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": null,
79+
"metadata": {},
7480
"outputs": [],
7581
"source": [
7682
"%px from mpi4py.MPI import COMM_WORLD as MPI"
@@ -79,12 +85,7 @@
7985
{
8086
"cell_type": "code",
8187
"execution_count": null,
82-
"metadata": {
83-
"collapsed": false,
84-
"jupyter": {
85-
"outputs_hidden": false
86-
}
87-
},
88+
"metadata": {},
8889
"outputs": [],
8990
"source": [
9091
"mpi_ranks = eall.apply_async(lambda : MPI.Get_rank()).get_dict()\n",
@@ -95,44 +96,29 @@
9596
{
9697
"cell_type": "code",
9798
"execution_count": null,
98-
"metadata": {
99-
"collapsed": false,
100-
"jupyter": {
101-
"outputs_hidden": false
102-
}
103-
},
99+
"metadata": {},
104100
"outputs": [],
105101
"source": [
106-
"sz = 1024\n",
102+
"sz = 512\n",
107103
"data = np.random.random((sz, sz))\n",
108-
"data = data.dot(data.T)"
104+
"data.nbytes // (1024 * 1024)"
109105
]
110106
},
111107
{
112108
"cell_type": "code",
113109
"execution_count": null,
114-
"metadata": {
115-
"collapsed": false,
116-
"jupyter": {
117-
"outputs_hidden": false
118-
}
119-
},
110+
"metadata": {},
120111
"outputs": [],
121112
"source": [
122113
"%%time \n",
123114
"ar = eall.push({'data': data}, block=False)\n",
124-
"ar.wait_interactive()"
115+
"ar.wait_interactive()\n"
125116
]
126117
},
127118
{
128119
"cell_type": "code",
129120
"execution_count": null,
130-
"metadata": {
131-
"collapsed": false,
132-
"jupyter": {
133-
"outputs_hidden": false
134-
}
135-
},
121+
"metadata": {},
136122
"outputs": [],
137123
"source": [
138124
"@ipp.interactive\n",
@@ -156,12 +142,7 @@
156142
{
157143
"cell_type": "code",
158144
"execution_count": null,
159-
"metadata": {
160-
"collapsed": false,
161-
"jupyter": {
162-
"outputs_hidden": false
163-
}
164-
},
145+
"metadata": {},
165146
"outputs": [],
166147
"source": [
167148
"%%time\n",
@@ -172,23 +153,13 @@
172153
{
173154
"cell_type": "code",
174155
"execution_count": null,
175-
"metadata": {
176-
"collapsed": false,
177-
"jupyter": {
178-
"outputs_hidden": false
179-
}
180-
},
156+
"metadata": {},
181157
"outputs": [],
182158
"source": [
183-
"eall.apply_sync(np.linalg.norm, parallel.Reference('data'), 2)"
159+
"%%px\n",
160+
"import numpy as np\n",
161+
"np.linalg.norm(data, 2)\n"
184162
]
185-
},
186-
{
187-
"cell_type": "code",
188-
"execution_count": null,
189-
"metadata": {},
190-
"outputs": [],
191-
"source": []
192163
}
193164
],
194165
"metadata": {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
services:
2+
# need /ipython to be writable by the container user (1000)
3+
# can't seem to start volumes with the right permissions
4+
init-permissions:
5+
image: alpine
6+
volumes:
7+
- ipython:/ipython
8+
command: chown -Rv 1000:1000 /ipython
9+
10+
controller:
11+
depends_on:
12+
- init-permissions
13+
# condition: service_completed_successfully
14+
15+
build: .
16+
volumes:
17+
- ipython:/ipython
18+
environment:
19+
IPYTHONDIR: /ipython
20+
command: |
21+
ipcontroller --location controller --ip 0.0.0.0 --nodb --HubFactory.broadcast_scheduler_depth=2
22+
deploy:
23+
restart_policy:
24+
condition: on-failure
25+
engines:
26+
build: .
27+
depends_on:
28+
- controller
29+
volumes_from:
30+
- controller
31+
environment:
32+
IPYTHONDIR: /ipython
33+
links:
34+
- controller
35+
command: |
36+
ipcluster engines -n 16
37+
deploy:
38+
mode: replicated
39+
replicas: 4
40+
restart_policy:
41+
condition: on-failure
42+
43+
client:
44+
build: .
45+
ports:
46+
- "9999:8888"
47+
links:
48+
- controller
49+
volumes_from:
50+
- controller
51+
volumes:
52+
- .:/home/jovyan/example
53+
environment:
54+
IPYTHONDIR: /ipython
55+
JUPYTER_CONFIG_DIR: /ipython/jupyter
56+
57+
volumes:
58+
ipython: {}

0 commit comments

Comments
 (0)