Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7fab423

Browse files
committedApr 12, 2023
Add template notebook
1 parent db267b1 commit 7fab423

File tree

3 files changed

+220
-6
lines changed

3 files changed

+220
-6
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can also use conda to build your environment
1515
```bash
1616
conda env update --file environment.yml --name name-of-your-env
1717
```
18-
4. Create an `.ipynb` in the [notebooks](./notebooks/) folder, or modify the existing notebooks. If a new notebook has been created, add it to the appropriate section of [_toc.yml](_toc.yml).
18+
4. Create an `.ipynb` in the [notebooks](./notebooks/) folder, or modify the existing notebooks. If a new notebook has been created, add it to the appropriate section of [_toc.yml](_toc.yml). You can use the [template-notebook](./notebooks/template.ipynb) as a starting point.
1919
5. Make sure the webpage builds correctly by calling `jupyter book build -W .` from the root of the repository. You can inspect the webpage locally by opening [_build/html/index.html](_build/html/index.html) with the web-browser of your choice.
2020
6. Make a [pull-request](https://github.com/scientificcomputing/mpi-tutorial/compare) to the main branch of this repo.
2121
7. Make sure that the workflow [Build documentation](https://github.com/scientificcomputing/mpi-tutorial/actions/workflows/build_docs.yml) passes.

‎notebooks/introduction.ipynb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@
107107
"comm = MPI.COMM_WORLD\n",
108108
"size = comm.Get_size()\n",
109109
"rank = comm.Get_rank()\n",
110-
"print(\"Hello, World! I am process\", rank, \"of\", size, \"on\", MPI.Get_processor_name())\n",
110+
"print(\"Hello, World! I am process\", rank, \"of\",\n",
111+
" size, \"on\", MPI.Get_processor_name())\n",
111112
"if rank == 0:\n",
112113
" data = [(i+1)**2 for i in range(size)]\n",
113114
" print(\"\")\n",
114-
" print(\"I am the root process\", rank, \"and I will send (scatter) one number to each of the processes, then they are going to multiply it by 2 and send them back to me (gather).\")\n",
115-
" print(\"These are the numbers I will send to the other\", size, \"process(es):\", data)\n",
115+
" print(\"I am the root process\", rank,\n",
116+
" \"and I will send (scatter) one number to each of the processes, then they are going to multiply it by 2 and send them back to me (gather).\")\n",
117+
" print(\"These are the numbers I will send to the other\",\n",
118+
" size, \"process(es):\", data)\n",
116119
" print(\"\")\n",
117120
"else:\n",
118121
" data = None\n",
@@ -126,7 +129,7 @@
126129
"# Gathering data in process 0\n",
127130
"gathered_data = comm.gather(scattered_data, root=0)\n",
128131
"if rank == 0:\n",
129-
" print(\"This is the resulting list of numbers:\", gathered_data)"
132+
" print(\"This is the resulting list of numbers:\", gathered_data)\n"
130133
]
131134
},
132135
{
@@ -154,7 +157,7 @@
154157
"name": "python",
155158
"nbconvert_exporter": "python",
156159
"pygments_lexer": "ipython3",
157-
"version": "3.10.8"
160+
"version": "3.10.6"
158161
}
159162
},
160163
"nbformat": 4,

‎notebooks/template.ipynb

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"metadata": {},
7+
"source": [
8+
"# Title of section\n",
9+
"\n",
10+
"Author: Name of author\n",
11+
"\n",
12+
"Add short abstract to what this section covers here."
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 1,
18+
"metadata": {},
19+
"outputs": [
20+
{
21+
"name": "stdout",
22+
"output_type": "stream",
23+
"text": [
24+
"Starting 2 engines with <class 'ipyparallel.cluster.launcher.MPIEngineSetLauncher'>\n",
25+
"100%|██████████| 2/2 [00:05<00:00, 2.76s/engine]\n"
26+
]
27+
}
28+
],
29+
"source": [
30+
"# Start parallel cluster with two processes\n",
31+
"import ipyparallel as ipp\n",
32+
"cluster = ipp.Cluster(engines=\"mpi\", n=2)\n",
33+
"rc = cluster.start_and_connect_sync(activate=True)"
34+
]
35+
},
36+
{
37+
"attachments": {},
38+
"cell_type": "markdown",
39+
"metadata": {},
40+
"source": [
41+
"Add alternating markdown and code sections going through the example"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 2,
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"data": {
51+
"text/plain": [
52+
"[stdout:0] 0 2\n"
53+
]
54+
},
55+
"metadata": {},
56+
"output_type": "display_data"
57+
},
58+
{
59+
"data": {
60+
"text/plain": [
61+
"[stdout:1] 1 2\n"
62+
]
63+
},
64+
"metadata": {},
65+
"output_type": "display_data"
66+
}
67+
],
68+
"source": [
69+
"%%px\n",
70+
"from mpi4py import MPI\n",
71+
"print(MPI.COMM_WORLD.rank, MPI.COMM_WORLD.size)"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 3,
77+
"metadata": {},
78+
"outputs": [
79+
{
80+
"name": "stdout",
81+
"output_type": "stream",
82+
"text": [
83+
"Stopping controller\n",
84+
"Controller stopped: {'exit_code': 0, 'pid': 46009, 'identifier': 'ipcontroller-1681302529-utla-45961'}\n",
85+
"Stopping engine(s): 1681302530\n",
86+
"engine set stopped 1681302530: {'exit_code': 0, 'pid': 46062, 'identifier': 'ipengine-1681302529-utla-1681302530-45961'}\n"
87+
]
88+
}
89+
],
90+
"source": [
91+
"# Stop cluster\n",
92+
"cluster.stop_cluster_sync()"
93+
]
94+
},
95+
{
96+
"attachments": {},
97+
"cell_type": "markdown",
98+
"metadata": {},
99+
"source": [
100+
"Create a new cluster with more or less processes"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 4,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"Starting 3 engines with <class 'ipyparallel.cluster.launcher.MPIEngineSetLauncher'>\n",
113+
"100%|██████████| 3/3 [00:05<00:00, 1.86s/engine]\n"
114+
]
115+
}
116+
],
117+
"source": [
118+
"new_cluster = ipp.Cluster(engines=\"mpi\", n=3)\n",
119+
"new_rc = new_cluster.start_and_connect_sync(activate=True)"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": 6,
125+
"metadata": {},
126+
"outputs": [
127+
{
128+
"data": {
129+
"text/plain": [
130+
"[stdout:2] 2 3\n"
131+
]
132+
},
133+
"metadata": {},
134+
"output_type": "display_data"
135+
},
136+
{
137+
"data": {
138+
"text/plain": [
139+
"[stdout:0] 0 3\n"
140+
]
141+
},
142+
"metadata": {},
143+
"output_type": "display_data"
144+
},
145+
{
146+
"data": {
147+
"text/plain": [
148+
"[stdout:1] 1 3\n"
149+
]
150+
},
151+
"metadata": {},
152+
"output_type": "display_data"
153+
}
154+
],
155+
"source": [
156+
"%%px\n",
157+
"from mpi4py import MPI\n",
158+
"print(MPI.COMM_WORLD.rank, MPI.COMM_WORLD.size)"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": 7,
164+
"metadata": {},
165+
"outputs": [
166+
{
167+
"name": "stdout",
168+
"output_type": "stream",
169+
"text": [
170+
"Stopping controller\n",
171+
"Controller stopped: {'exit_code': 0, 'pid': 46191, 'identifier': 'ipcontroller-1681302539-snjl-45961'}\n",
172+
"Stopping engine(s): 1681302540\n",
173+
"engine set stopped 1681302540: {'exit_code': 0, 'pid': 46244, 'identifier': 'ipengine-1681302539-snjl-1681302540-45961'}\n"
174+
]
175+
}
176+
],
177+
"source": [
178+
"new_cluster.stop_cluster_sync()"
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": null,
184+
"metadata": {},
185+
"outputs": [],
186+
"source": []
187+
}
188+
],
189+
"metadata": {
190+
"kernelspec": {
191+
"display_name": "Python 3",
192+
"language": "python",
193+
"name": "python3"
194+
},
195+
"language_info": {
196+
"codemirror_mode": {
197+
"name": "ipython",
198+
"version": 3
199+
},
200+
"file_extension": ".py",
201+
"mimetype": "text/x-python",
202+
"name": "python",
203+
"nbconvert_exporter": "python",
204+
"pygments_lexer": "ipython3",
205+
"version": "3.10.6"
206+
},
207+
"orig_nbformat": 4
208+
},
209+
"nbformat": 4,
210+
"nbformat_minor": 2
211+
}

0 commit comments

Comments
 (0)
Please sign in to comment.