More changes

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

No files matched your search

+1
View File
@@ -124,6 +124,7 @@ makedocs(;
"MPI" => "notebooks/mpi_tutorial.md",
"Matrix Multiplication"=>"notebooks/matrix_matrix.md",
"Jacobi" => "notebooks/jacobi_method.md",
"ASP" => "notebooks/asp.md",
"Solutions" => "notebooks/solutions.md"
]],
)
+16 -92
View File
@@ -22,7 +22,7 @@
"\n",
"In this notebook, we will learn\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"
]
},
@@ -33,14 +33,14 @@
"source": [
"## The all pairs of shortest paths (ASP) problem\n",
"\n",
"Let us start by presenting the all pairs of shortest path (ASP) problem and its solution with the [Floyd–Warshall 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 [Floyd–Warshall algorithm](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm).\n",
"\n",
"### Problem statement\n",
"\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",
"\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",
"execution_count": 5,
"execution_count": null,
"id": "4fe447c5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"floyd! (generic function with 1 method)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"function floyd!(C)\n",
" n = size(C,1)\n",
@@ -415,21 +404,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "09937668",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"rand_distance_table (generic function with 1 method)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"function rand_distance_table(n)\n",
" threshold = 0.4\n",
@@ -451,31 +429,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "3116096c",
"metadata": {},
"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"
}
],
"outputs": [],
"source": [
"rand_distance_table(10)"
]
@@ -500,21 +457,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "6bc0122b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MPI.ThreadLevel(2)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"using MPIClusterManagers\n",
"using Distributed\n",
@@ -536,21 +482,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "22234b2f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"floyd_dist! (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"function floyd_dist!(C)\n",
" m = size(C,1)\n",
@@ -567,7 +502,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"id": "d5a8d3a8",
"metadata": {},
"outputs": [],
@@ -603,21 +538,10 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"id": "dd77ee3d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[32m\u001b[1mTest Passed\u001b[22m\u001b[39m"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"using Test\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

+74 -2
View File
@@ -1,5 +1,77 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "533363df",
"metadata": {},
"source": [
"<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/39/VU_logo.png/800px-VU_logo.png?20161029201021\" width=\"350\">\n",
"\n",
"### Programming large-scale parallel systems\n",
"\n",
"# Traveling sales person"
]
},
{
"cell_type": "markdown",
"id": "98ebaf0c",
"metadata": {},
"source": [
"## Contents\n",
"\n",
"In this notebook, we will learn\n",
"\n",
"- How to parallelize the solution of the traveling sales person problem\n",
"- The concept of search overhead\n"
]
},
{
"cell_type": "markdown",
"id": "14864a1b",
"metadata": {},
"source": [
"## The traveling sales person (TSP) problem\n",
"\n",
"Let us start by presenting the [traveling sales person (ASP) problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem) and its solution using a [branch and bound algorithm](https://en.wikipedia.org/wiki/Branch_and_bound).\n",
"\n",
"### Problem statement\n",
"\n",
"- Given a graph $G$ with a distance table $C$ and an initial node (i.e. a city) in the graph\n",
"- Compute the shortest route that visits all cities exactly once, without returning to the initial city.\n",
"\n",
"\n",
"Note that there we consider a version of the problem in which do not return to the initial city. However, the classic version of the problem includes returning to the initial city.\n",
"\n",
"\n",
"As for the ASP problem 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 TSP problem for a simple 4-node graph. "
]
},
{
"attachments": {
"g18228.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABHAAAAGgCAYAAADCcJBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURBVHic7N13eFRl2sfx7wkpECD0DkJogrhIE8WCAiI2xMXey7rqura1UbaIrkvZ9bXXdS3rqthAEUVEUURQ6SBFeq8SOgRSz/vHk2knM5OZyZRM8vtc11zMOXPKfZIw5Z7nuW8LEREREQlXF+Air+WfgO8SFIuIiJRPGtAXuBA4FWhScrOA3cAOYAHwGTADOJaQKKXKsxIdgIiIiEgSuh54y2t5LDAiQbFUNhcDTUvu5wATExiLiFRu1YCbgceAZiHuk1Oy/ctAQYziitT5QKuS+weA9xMYS6LUBK71Wp4DLElQLCIiIiJSAVwP2F63MYkNp1L5Hs/PdUGCYxGRyqsVsBDf5/JwbiuA9nGPOrgpeOJbneBYEqUFvr+nYYkNJ7pSEx2AiIiIiIiISBydAEzFM1rFZR3wIfAjsAsowowI7AVcXrKfS2dgFmbalZLNIiIiIiIVlEbgxI5G4IhILDUGtuP7HL4PuANIKWPf64BfHfvupXQiKFE0AqeSj8Ap6w9UREREREREpDKwgP/gW+9mHzAAU9OmuIz93wZOA7Z5rasHvIOppyMSU0rgiIiIiIiISFVwHTDYa7kQU/h3YRjHWAucB+R5rTsTuL3c0YmUQTVwRERERGLvHK/7W4BVXsunAFdiimE2BQ5i6jB8CXyK+YARin54vgHeBvxScj+l5PyXYIb5N8FMAVgLfATMxgwzL0t14Ayv5dXA5hBjOx7PFAMbmO54vBmmNTtAXa/1tfH92TnNQu18RSR0DziWn8F0KQrXMszU2VFe6/5E4FE8acBZXsvrgA0hnqsdkO21/I3jHI2BriX3G3qtzyT48+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cI1DVO4l5LHs732/YbQn7PT8Dx/Ottp/4h53XAZDHzqtXwuZjoumJ/FNZhaMs0wI202YxL67xH6a5pTS8y0sb6YluLVMK+Ri4D/Yl5PXPp6XcNOYFkY56kHtKV0raIDBG55LiIiIiISM84pVCIiIqHyN4VKKhhNoRIRERERERERqeA0hUpEREQksJNJntEsv8Hz5dxezDD0qmQQZgqXiEhZzqfs4vNVTRa+U7XWY7phVXZzgNsTHUSoQu0JLyIiIlIV1QZOSnQQEahfcqtKnPUdREQCqU9yPrfHU9tEBxAn4RaiTiiNwBEREREJrB7QM9FBhOgzTMFiMO1Tn0xgLInwPZCX6CBEJCk0BU5MdBAVzKnA372WhwMLEhRLPO0FFiY6CBHxLxNohMkodwfaYyqp105kUCIiIlGgIsYiIhIpFTFOAppCJZVZNtAPOAXoCHTCZNsD2Q+sxrTBW4hpf7qUyFqrioiIiIiIiESNplBJZdMDuB64BGgThePlAFOB/wHTgaIoHFNERCQW/g6kldyfB0xIYCwiIpJcOgM3ei2/BqxJUCwiUollALdhRsvYMbxtA0ZR9YpCioiIiIiIiIhELB24F9hKbBM3ztsh4F9Ag9hfooiIiIiIiIimUEny6g+8gKlrE0wxsBhTQd1V3yYHU+jxMFAdqAk0xNTM6QR0xdTNqV7GsfdgqrO/jurkiIiIiIiIiIi41QLeJPgImaPAe8BvLine truncated
}
},
"cell_type": "markdown",
"id": "14ae7875",
"metadata": {},
"source": [
"<div>\n",
"<img src=\"attachment:g18228.png\" align=\"left\" width=\"450\"/>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "aca8b2c4",
"metadata": {},
"source": [
"### Branch and bound algorithm\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -256,7 +328,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.1",
"display_name": "Julia 1.9.0",
"language": "julia",
"name": "julia-1.9"
},
@@ -264,7 +336,7 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.1"
"version": "1.9.0"
}
},
"nbformat": 4,