mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-08 20:14:23 +01:00
More work in mpi notebooks
This commit is contained in:
parent
9bd350c484
commit
1f79584e48
@ -691,7 +691,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"<div class=\"alert alert-block alert-info\">\n",
|
||||
"<b>Note:</b> In Julia, send and receive buffers are usually arrays or references.\n",
|
||||
"<b>Note:</b> Note that the C interface provides additional arguments `MPI_Datatype` (type of data to send/receive) and `count` (number of items to send/receive). In Julia, send and receive buffers are usually arrays or references, from which the data type and the count can be inferred. This is true for many other MPI functions.\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
|
||||
@ -90,7 +90,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d7ba2558",
|
||||
"id": "e9e2a219",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Barrier\n",
|
||||
@ -110,7 +110,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5ae78757",
|
||||
"id": "d9753e4b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -120,25 +120,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"id": "c21ec2fb",
|
||||
"execution_count": null,
|
||||
"id": "9a66c717",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 3] I woke up\n",
|
||||
"[rank 0] I woke up\n",
|
||||
"[rank 2] I woke up\n",
|
||||
"[rank 1] I woke up\n",
|
||||
"[rank 0] Done!\n",
|
||||
"[rank 1] Done!\n",
|
||||
"[rank 2] Done!\n",
|
||||
"[rank 3] Done!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -155,7 +140,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ff3bece9",
|
||||
"id": "df0223ff",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Reduce\n",
|
||||
@ -183,7 +168,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0538ef9f",
|
||||
"id": "2fc1aa28",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -192,23 +177,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 74,
|
||||
"id": "481eaa2c",
|
||||
"execution_count": null,
|
||||
"id": "341b8438",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 0] I am contributing with [4]\n",
|
||||
"[rank 1] I am contributing with [1]\n",
|
||||
"[rank 2] I am contributing with [4]\n",
|
||||
"[rank 2] The sum is nothing\n",
|
||||
"[rank 0] The sum is [9][rank 1] The sum is nothing\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -234,7 +206,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8daac465",
|
||||
"id": "3ea77a8f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Reducing multiple values\n",
|
||||
@ -244,7 +216,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "13199da4",
|
||||
"id": "b26fd0b2",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -254,23 +226,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 75,
|
||||
"id": "52bcb006",
|
||||
"execution_count": null,
|
||||
"id": "1a145948",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 0] I am contributing with [1, 4]\n",
|
||||
"[rank 1] I am contributing with [2, 4]\n",
|
||||
"[rank 2] I am contributing with [3, 3]\n",
|
||||
"[rank 0] The sum is [6, 11]\n",
|
||||
"[rank 1] The sum is nothing\n",
|
||||
"[rank 2] The sum is nothing\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -293,7 +252,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "852e2517",
|
||||
"id": "539df34f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Allreduce\n",
|
||||
@ -303,7 +262,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fb83387b",
|
||||
"id": "be0381bb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -313,23 +272,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 79,
|
||||
"id": "c15c908a",
|
||||
"execution_count": null,
|
||||
"id": "1595f4f5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 1] I am contributing with [2, 1]\n",
|
||||
"[rank 2] I am contributing with [3, 3]\n",
|
||||
"[rank 0] I am contributing with [3, 3]\n",
|
||||
"[rank 0] The sum is [8, 7]\n",
|
||||
"[rank 1] The sum is [8, 7]\n",
|
||||
"[rank 2] The sum is [8, 7]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -370,7 +316,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f201abe7",
|
||||
"id": "3d0a1e9d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -395,23 +341,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 71,
|
||||
"execution_count": null,
|
||||
"id": "1f8a70c6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 1] I am sending [30]\n",
|
||||
"[rank 2] I am sending [40]\n",
|
||||
"[rank 0] I am sending [20]\n",
|
||||
"[rank 0] I received [20, 30, 40]\n",
|
||||
"[rank 1] I received nothing\n",
|
||||
"[rank 2] I received nothing\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -438,7 +371,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "932c815a",
|
||||
"id": "0f85f08d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Allgather\n",
|
||||
@ -448,7 +381,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8572570f",
|
||||
"id": "4bf2ef34",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example"
|
||||
@ -456,23 +389,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 78,
|
||||
"id": "5c9b98a2",
|
||||
"execution_count": null,
|
||||
"id": "070e1fc1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 0] I am sending [20]\n",
|
||||
"[rank 1] I am sending [30]\n",
|
||||
"[rank 2] I am sending [40]\n",
|
||||
"[rank 0] I received [20, 30, 40]\n",
|
||||
"[rank 1] I received [20, 30, 40]\n",
|
||||
"[rank 2] I received [20, 30, 40]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -493,7 +413,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "cf2ea30a",
|
||||
"id": "fb6a9034",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Gatherv\n",
|
||||
@ -503,7 +423,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "faf0951a",
|
||||
"id": "e0d2998c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -513,22 +433,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"id": "8e65fcd0",
|
||||
"execution_count": null,
|
||||
"id": "23814278",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 1] I am sending [10, 10]\n",
|
||||
"[rank 2] I am sending [20, 20, 20]\n",
|
||||
"[rank 3] I am sending [30, 30, 30, 30]\n",
|
||||
"[rank 0] I am sending [0]\n",
|
||||
"[rank 0] I received [0, 10, 10, 20, 20, 20, 30, 30, 30, 30]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -562,7 +470,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1fb65390",
|
||||
"id": "25c2fb1e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## How to get the amount of data to be received?\n",
|
||||
@ -572,7 +480,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "23c57c46",
|
||||
"id": "12f9e2ca",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -582,22 +490,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"id": "b89fc364",
|
||||
"execution_count": null,
|
||||
"id": "b10430a9",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 1] I am sending [1, 1]\n",
|
||||
"[rank 2] I am sending [2]\n",
|
||||
"[rank 3] I am sending [3, 3, 3, 3]\n",
|
||||
"[rank 0] I am sending [0]\n",
|
||||
"[rank 0] I received [0, 1, 1, 2, 3, 3, 3, 3]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -664,7 +560,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1df3bc76",
|
||||
"id": "e55aa353",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -689,22 +585,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"execution_count": null,
|
||||
"id": "5ea413fd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 0] I am sending: [20, 30, 40, 50]\n",
|
||||
"[rank 0] I have received: 20\n",
|
||||
"[rank 1] I have received: 30\n",
|
||||
"[rank 2] I have received: 40\n",
|
||||
"[rank 3] I have received: 50\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -751,7 +635,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "97a15ba7",
|
||||
"id": "97369713",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -776,22 +660,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 46,
|
||||
"execution_count": null,
|
||||
"id": "4de15781",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 0] I am sending: 20\n",
|
||||
"[rank 0] I have received: 20\n",
|
||||
"[rank 1] I have received: 20\n",
|
||||
"[rank 2] I have received: 20\n",
|
||||
"[rank 3] I have received: 20\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -813,7 +685,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "725d8381",
|
||||
"id": "e83be96d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Communicators\n",
|
||||
@ -837,7 +709,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "48b2b85e",
|
||||
"id": "556ca223",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Comm_dup\n",
|
||||
@ -858,7 +730,48 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4034e3eb",
|
||||
"id": "9acfb792",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
"\n",
|
||||
"Send value 2 from rank 2 to rank 3. Then send value 1 also from rank 2 to rank 3. Note that we are using 2 different communicators for each send receive pair in such a way that we first receive value 1 and then value 2, even if this not was the other in which the data was sent. Try also to define `comm2 = comm` and see how the result will change."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e50d44f6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
" MPI.Init()\n",
|
||||
" comm = MPI.COMM_WORLD\n",
|
||||
" # We create a new communicator\n",
|
||||
" comm2 = MPI.Comm_dup(comm)\n",
|
||||
" rank = MPI.Comm_rank(comm)\n",
|
||||
" if rank == 2\n",
|
||||
" sndbuf = [2]\n",
|
||||
" MPI.Send(sndbuf, comm2; dest=3, tag=0)\n",
|
||||
" sndbuf = [1]\n",
|
||||
" MPI.Send(sndbuf, comm; dest=3, tag=0)\n",
|
||||
" end\n",
|
||||
" if rank == 3\n",
|
||||
" rcvbuf = zeros(Int,1)\n",
|
||||
" MPI.Recv!(rcvbuf, comm; source=2, tag=0)\n",
|
||||
" @show rcvbuf\n",
|
||||
" MPI.Recv!(rcvbuf, comm2; source=2, tag=0)\n",
|
||||
" @show rcvbuf\n",
|
||||
" end\n",
|
||||
"end\n",
|
||||
"run(`$(mpiexec()) -np 4 julia --project=. -e $code`);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5e1b13eb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## MPI_Comm_split\n",
|
||||
@ -887,7 +800,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "947cebc7",
|
||||
"id": "2b128840",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -897,21 +810,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 87,
|
||||
"id": "19825efb",
|
||||
"execution_count": null,
|
||||
"id": "b18cb74d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hello, I am rank 0 in world and rank 0 in group 0.\n",
|
||||
"Hello, I am rank 1 in world and rank 0 in group 1.\n",
|
||||
"Hello, I am rank 2 in world and rank 1 in group 0.\n",
|
||||
"Hello, I am rank 3 in world and rank 1 in group 1.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
@ -929,7 +831,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "495775c9",
|
||||
"id": "b22e4bf4",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example\n",
|
||||
@ -939,21 +841,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 96,
|
||||
"id": "9abb132e",
|
||||
"execution_count": null,
|
||||
"id": "4c0e504b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[rank 1, newrank 0] I am contributing with [3]\n",
|
||||
"[rank 3, newrank 1] I am contributing with [3]\n",
|
||||
"[rank 1, newrank 0] The sum is [6]\n",
|
||||
"[rank 3, newrank 1] The sum is nothing\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user