More changes

This commit is contained in:
Francesc Verdugo 2023-08-18 10:07:25 +02:00
parent 6c681ef324
commit 9372448ef5
4 changed files with 1088 additions and 99 deletions

View File

@ -124,6 +124,7 @@ makedocs(;
"MPI" => "notebooks/mpi_tutorial.md", "MPI" => "notebooks/mpi_tutorial.md",
"Matrix Multiplication"=>"notebooks/matrix_matrix.md", "Matrix Multiplication"=>"notebooks/matrix_matrix.md",
"Jacobi" => "notebooks/jacobi_method.md", "Jacobi" => "notebooks/jacobi_method.md",
"ASP" => "notebooks/asp.md",
"Solutions" => "notebooks/solutions.md" "Solutions" => "notebooks/solutions.md"
]], ]],
) )

View File

@ -22,7 +22,7 @@
"\n", "\n",
"In this notebook, we will learn\n", "In this notebook, we will learn\n",
"\n", "\n",
"- How to parallelize the Floyd's algorithm\n", "- How to parallelize Floyd's algorithm\n",
"- How communication can affect the correctness of a distributed algorithm\n" "- How communication can affect the correctness of a distributed algorithm\n"
] ]
}, },
@ -33,14 +33,14 @@
"source": [ "source": [
"## The all pairs of shortest paths (ASP) problem\n", "## The all pairs of shortest paths (ASP) problem\n",
"\n", "\n",
"Let us start by presenting the all pairs of shortest path (ASP) problem and its solution with the [FloydWarshall algorithm](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm).\n", "Let us start by presenting the all pairs of shortest paths (ASP) problem and its solution with the [FloydWarshall algorithm](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm).\n",
"\n", "\n",
"### Problem statement\n", "### Problem statement\n",
"\n", "\n",
"- Given a graph $G$ with a distance table $C$\n", "- Given a graph $G$ with a distance table $C$\n",
"- Compute the length of the shortest path between any two nodes in $G$\n", "- Compute the length of the shortest path between any two nodes in $G$\n",
"\n", "\n",
"We represent the distance table as a matrix, where $C_{ij}$ is the distance from node $i$ to node $j$. Next figure shows the input and solution (output) of the ASP problem for a simple 4-node directed graph. For example, the solution of the problem contains the minimum distance from node 2 to node 3, which is $C_{23}=8$ as highlighted in the figure.\n" "We represent the distance table as a matrix, where $C_{ij}$ is the distance from node $i$ to node $j$. Next figure shows the input and solution (output) of the ASP problem for a simple 4-node directed graph. Note that the minimum distance from node 2 to node 3, which is $C_{23}=8$ as highlighted in the figure.\n"
] ]
}, },
{ {
@ -70,21 +70,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"id": "4fe447c5", "id": "4fe447c5",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"floyd! (generic function with 1 method)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function floyd!(C)\n", "function floyd!(C)\n",
" n = size(C,1)\n", " n = size(C,1)\n",
@ -415,21 +404,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"id": "09937668", "id": "09937668",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"rand_distance_table (generic function with 1 method)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function rand_distance_table(n)\n", "function rand_distance_table(n)\n",
" threshold = 0.4\n", " threshold = 0.4\n",
@ -451,31 +429,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"id": "3116096c", "id": "3116096c",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"10×10 Matrix{Int64}:\n",
" 0 3 100000 100000 100000 … 3 100000 7 100000\n",
" 8 0 3 10 5 9 9 10 10\n",
" 100000 7 0 100000 8 100000 100000 7 7\n",
" 3 100000 6 0 7 9 5 10 10\n",
" 10 5 100000 7 0 100000 100000 8 100000\n",
" 5 10 100000 3 9 … 4 10 7 100000\n",
" 100000 9 8 10 100000 0 4 100000 4\n",
" 5 10 9 100000 6 100000 0 5 100000\n",
" 3 10 7 10 3 4 100000 0 100000\n",
" 10 100000 9 4 6 3 100000 7 0"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"rand_distance_table(10)" "rand_distance_table(10)"
] ]
@ -500,21 +457,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"id": "6bc0122b", "id": "6bc0122b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"MPI.ThreadLevel(2)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"using MPIClusterManagers\n", "using MPIClusterManagers\n",
"using Distributed\n", "using Distributed\n",
@ -536,21 +482,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"id": "22234b2f", "id": "22234b2f",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"floyd_dist! (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function floyd_dist!(C)\n", "function floyd_dist!(C)\n",
" m = size(C,1)\n", " m = size(C,1)\n",
@ -567,7 +502,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"id": "d5a8d3a8", "id": "d5a8d3a8",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -603,21 +538,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": null,
"id": "dd77ee3d", "id": "dd77ee3d",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"\u001b[32m\u001b[1mTest Passed\u001b[22m\u001b[39m"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"using Test\n", "using Test\n",
"load = 10\n", "load = 10\n",

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 2.9 MiB

After

Width:  |  Height:  |  Size: 3.0 MiB

File diff suppressed because one or more lines are too long