Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9f51799
New parallel python tutotials
Mar 10, 2025
831f572
revision, parallel python
Mar 14, 2025
8769b20
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
8c91519
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
fb36d25
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
108f6fd
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
800f693
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
ba2dd90
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
9e55860
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
7aebe27
Update docs/Documentation/Development/Languages/Python/index.md
nileshsawant Mar 18, 2025
3409c80
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
8f2b6d3
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
0e346d8
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
9f008b2
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
63bc659
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
34bb8c4
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
2d81d83
Update docs/Documentation/Development/Languages/Python/KestrelParalle…
nileshsawant Mar 18, 2025
d1d37d6
Added links to test notebooks after launching jobs. pyEnvsAndLaunchin…
nileshsawant Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a880d8b0-d919-463e-b4dc-402c23493efc",
"metadata": {},
"outputs": [],
"source": [
"numberOfNodes=2\n",
"import mpi4py\n",
"import os\n",
"import ipyparallel as ipp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "127dc93e-1745-49d8-a9e1-2351ed0092b4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting 2 engines with <class 'ipyparallel.cluster.launcher.MPIEngineSetLauncher'>\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2c038b444550464b9ae0ccf07a6307b4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/2 [00:00<?, ?engine/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cluster = ipp.Cluster(engines=\"mpi\", n=numberOfNodes,controller_ip='*')\n",
"rc = cluster.start_and_connect_sync()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5ee27e14-31e3-46ed-a083-f99ad32410da",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 1]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rc.wait_for_engines(n=numberOfNodes)\n",
"dview=rc[:]\n",
"rc.ids"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e1216bef-49eb-4c6f-8ef5-2ae3a6eb499d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[stdout:0] x3100c0s21b0n0\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[stdout:1] x3101c0s13b0n0\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%px --target 0:2\n",
"#%%px --target 0:1\n",
"import os, socket\n",
"#print(os.getpid())\n",
"print(socket.gethostname())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "3247f8c5-dea9-4bfa-8ba7-e14f920b2fa0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[stdout:0] Process 0 sent data: [[[[-0.00705688 0.1574703 ]\n",
" [-0.11614565 -1.36530107]]\n",
"\n",
" [[ 1.9377235 0.19872024]\n",
" [ 0.20897026 1.86760844]]]\n",
"\n",
"\n",
" [[[-1.19135132 1.44246809]\n",
" [-1.49924247 0.45127102]]\n",
"\n",
" [[ 1.77763836 0.49243783]\n",
" [-0.4570443 0.96459175]]]]\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"[stdout:1] Process 1 received data: [[[[-0.00705688 0.1574703 ]\n",
" [-0.11614565 -1.36530107]]\n",
"\n",
" [[ 1.9377235 0.19872024]\n",
" [ 0.20897026 1.86760844]]]\n",
"\n",
"\n",
" [[[-1.19135132 1.44246809]\n",
" [-1.49924247 0.45127102]]\n",
"\n",
" [[ 1.77763836 0.49243783]\n",
" [-0.4570443 0.96459175]]]]\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%px\n",
"from mpi4py import MPI\n",
"\n",
"useGPU=False\n",
"\n",
"if useGPU:\n",
" import cupy as cp\n",
"else:\n",
" import numpy as cp\n",
"\n",
"comm = MPI.COMM_WORLD\n",
"size = comm.Get_size()\n",
"rank = comm.Get_rank()\n",
"\n",
"if rank == 0:\n",
" N=2\n",
" data = cp.random.randn(N,N,N,N)\n",
" comm.send(data, dest=1, tag=42)\n",
" print('Process {} sent data:'.format(rank), data)\n",
" \n",
"elif rank == 1:\n",
" data = comm.recv(source=0, tag=42)\n",
" print('Process {} received data:'.format(rank), data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d47a47d6-b7f0-4e5d-a8ba-37649d805a10",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "myEnvJupyter",
"language": "python",
"name": "myenvjupyter"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b173f1c1-467b-415b-8ee4-99257830d74b",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import cupy as cp\n",
"from cupyx.profiler import benchmark"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9282ca52-03a7-41f9-8074-15fb457b6894",
"metadata": {},
"outputs": [],
"source": [
"def my_func(a, b):\n",
" return cp.pi * cp.sin(-a) * cp.exp(b)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "be231d9e-90f5-4a5a-b49c-58de8c9271c6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"my_func : CPU: 36.410 us +/- 5.270 (min: 34.873 / max: 1140.029) us GPU-0: 94.612 us +/- 4.973 (min: 91.424 / max: 1172.864) us\n"
]
}
],
"source": [
"a = cp.random.random((2560, 1024))\n",
"b = cp.random.random((2560, 1024))\n",
"print(benchmark(my_func, (a,b), n_repeat=100000))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "798d1913-b406-4629-aecf-988134d3b650",
"metadata": {},
"outputs": [],
"source": [
"np_rng = np.random.default_rng()\n",
"\n",
"A_cpu = np_rng.random((1000, 1000))\n",
"b_cpu = np_rng.random(1000)\n",
"\n",
"A_gpu = cp.array(A_cpu)\n",
"b_gpu = cp.array(b_cpu)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cad205a2-9ba1-4740-9182-57b82af9baf6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"17.6 ms ± 62.1 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"%%timeit\n",
"np.linalg.solve(A_cpu, b_cpu)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a8d96215-9b1f-4999-ab3e-cc926bb3284c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.49 ms ± 268 ns per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"%%timeit\n",
"cp.linalg.solve(A_gpu, b_gpu)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "042864d2-c29c-4be0-8779-935d25759072",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Type of CPU array is: <class 'numpy.ndarray'>\n"
]
}
],
"source": [
"x_gpu = cp.ones((1000, 1000))\n",
"x_cpu = x_gpu.get()\n",
"print(f'Type of CPU array is: {type(x_cpu)}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5beba59f-8d17-437d-a2f6-f8bbab28c6fd",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "myEnvJupyter",
"language": "python",
"name": "myenvjupyter"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading