More changes in ASP and LEQ

This commit is contained in:
Francesc Verdugo committed 2024-09-19 10:37:09 +02:00
1 parent d7b9ff635a
commit 70f7004cc3
3 files changed
+3607 -288

No files matched your search

+80 -277
View File
@@ -22,7 +22,7 @@
"In this notebook, we will learn\n",
"\n",
"- How to parallelize Gaussian elimination\n",
"- How to fix static load imbalance"
"- What is load imbalance, and how to fix it in this algorithm"
]
},
{
@@ -37,26 +37,15 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "7e93809a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ge_lb_answer (generic function with 1 method)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"using Printf\n",
"function answer_checker(answer,solution)\n",
" if answer == solution\n",
" \"🥳 Well done! \"\n",
" \"🥳 Well done!\"\n",
" else\n",
" \"It's not correct. Keep trying! 💪\"\n",
" end |> println\n",
@@ -70,7 +59,8 @@
"function ge_lb_answer()\n",
" msg = \"It is a form of static load balancing. We know in advance the load distribution and the partition strategy does not depend on the actual values of the input matrix\"\n",
" println(msg)\n",
"end"
"end\n",
"println(\"🥳 Well done!\")"
]
},
{
@@ -105,14 +95,14 @@
"1 \\\\\n",
"35 \\\\\n",
"\\end{matrix}\n",
"\\right]\n",
"\\right].\n",
"$$\n",
"\n",
"This is just a small example with three unknowns, but practical applications need to solve linear equations with large number of unknowns. Parallel processing is needed in these cases.\n",
"\n",
"### Problem statement\n",
"\n",
"Let us consider a system of linear equations written in matrix form $Ax=b$, where A is a nonsingular square matrix, and x and b are vectors. The goal of Gaussian elimination is to transform the system $Ax=b$, into a new system $Ux=c$ such that\n",
"Let us consider a system of linear equations written in matrix form $Ax=b$, where $A$ is a nonsingular square matrix, and $x$ and $b$ are vectors. $A$ and $b$ are given, and $x$ is unknown. The goal of Gaussian elimination is to transform the system $Ax=b$, into a new system $Ux=c$ such that\n",
"- both system have the same solution vector $x$,\n",
"- the matrix $U$ of the new system is *upper triangular* with unit diagonal, namely $U_{ii} = 1$ and $U_{ij} = 0$ for $i>j$.\n",
"\n",
@@ -167,7 +157,7 @@
"\\right]\n",
"$$\n",
"\n",
"The most challenging part of solving a system of linear equations is to transform it to upper triangular form. Afterwards, the solution vector can be obtained easily with a backward substitution."
"The most challenging part of solving a system of linear equations is to transform it to upper triangular form. Afterwards, the solution vector can be obtained easily with a backward substitution. For this reason, we will study here the triangulation step only."
]
},
{
@@ -179,7 +169,7 @@
"\n",
"### Augmented system matrix\n",
"\n",
"In practice, vector $b$ is added as an additional column to A forming the so-called *augmented* matrix $A^* = [A | b]$.\n",
"In practice, vector $b$ is added as an additional column to A forming the so-called *augmented* matrix $A^* = [A b]$. The augmented matrix in the example above is\n",
"\n",
"$$\n",
"\\left[\n",
@@ -211,10 +201,10 @@
"1 & 2 & -1 & 1 \\\\\n",
"3 & 11 & 5 & 35\\\\\n",
"\\end{matrix}\n",
"\\right]\n",
"\\right].\n",
"$$\n",
"\n",
"With this new notation, the goal of Gaussian elimination is to find the augmented matrix containing $U$ and $c$, namely $U^*= [U | c]$, given the augmented matrix $A^* = [A | b]$.\n",
"With this new notation, the goal of Gaussian elimination is to find the augmented matrix containing $U$ and $c$, namely $U^*= [U c]$, given the augmented matrix $A^* = [A b]$. These are $A^*$ and $U^*$ in our example:\n",
"\n",
"$$\n",
"A^*=\n",
@@ -232,7 +222,7 @@
"0 & 1 & 2 & 8\\\\\n",
"0 & 0 & 1 & 4\\\\\n",
"\\end{matrix}\n",
"\\right]\n",
"\\right].\n",
"$$\n",
"\n"
]
@@ -245,41 +235,32 @@
"### Serial implementation\n",
"\n",
"\n",
"The following algorithm computes the Gaussian elimination on a given augmented matrix `B`, representing a system of linear equations.\n",
"The following algorithm computes the Gaussian elimination on a given augmented matrix `B`, representing a system of linear equations. The result is given by overwriting `B`, avoiding the allocation of an additional matrix.\n",
"\n",
"- The outer loop is a loop over rows.\n",
"- The first inner loop in line 4 divides the current row by the value of the diagonal entry, thus transforming the diagonal to contain only ones. Note that we skip the first entries in the row, as we know that these values are zero at this point. The cells updated in this loop at iteration $k$ are depicted in red in the figure below.\n",
"- The second inner loop beginning in line 8 substracts the rows from one another such that all entries below the diagonal become zero. The entries updated in this loop are depicted in blue in the figure below."
"- The second inner loop beginning in line 8 subtracts the rows from one another such that all entries below the diagonal become zero. The entries updated in this loop are depicted in blue in the figure below."
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"id": "e4070214",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"gaussian_elimination! (generic function with 1 method)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"function gaussian_elimination!(B)\n",
" n,m = size(B)\n",
" @inbounds for k in 1:n\n",
" for t in k:m\n",
" for t in (k+1):m\n",
" B[k,t] = B[k,t]/B[k,k]\n",
" end\n",
" B[k,k] = 1\n",
" for i in (k+1):n \n",
" for j in k:m\n",
" for j in (k+1):m\n",
" B[i,j] = B[i,j] - B[i,k]*B[k,j]\n",
" end\n",
" B[i,k] = 0\n",
" end\n",
" end\n",
" B\n",
@@ -288,17 +269,17 @@
},
{
"attachments": {
"g30822.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAzAAAAJsCAYAAAAiM0YjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURBVHic7N15nBx1nf/xV/X0zOS+LxJOEw4JEORGEMEFFEXwRF1wFQWPXd0VcfHADU0WVERWRV1XQMRjXcFdEfH4KaCcchiCAoKAAiEhCQFykWuurt8fNQM9ne6eqU73VNXM6/l49CNd1d/v1LtnJj396W/V9xsgSRru8sDZJdt/Aa7rvd8OnAy8G9gD2AkoAo8DvwIuBZ6u8nX3A84AXg3sBowCVgP3AN8Hrm3kk5AkSZI0MowGwpLbj3r37wM8XPZY+W0D8LayrzcK+E+gZ4C+PwfGNOk5SZIk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53",
"id": "cc6ce65e",
"metadata": {},
"source": [
"<div>\n",
"<img src=\"attachment:g30822.png\" align=\"left\" width=\"300\"/>\n",
"</div>\n"
"<img src=\"attachment:g27851.png\" align=\"left\" width=\"300\"/>\n",
"</div>"
]
},
{
@@ -307,7 +288,7 @@
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\">\n",
"<b>Note:</b> This algorithm is not correct for all matrices: if any diagonal element <code>B[k,k]</code> is zero, the computation in the first inner loop fails. To get around this problem, another step can be added to the algorithm that swaps the rows until the diagonal entry of the current row is not zero. This process of finding a nonzero value is called <b>pivoting</b>. We are not going to consider pivoting here for simplicity. \n",
"<b>Note:</b> This algorithm is not correct for all nonsingular matrices: if any diagonal element <code>B[k,k]</code> is zero, the computation in the first inner loop fails. To get around this problem, another step can be added to the algorithm that swaps the rows until the diagonal entry of the current row is not zero. This process of finding a nonzero value is called <b>pivoting</b>. We are not going to consider pivoting here for simplicity. \n",
"</div>"
]
},
@@ -321,24 +302,10 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"id": "eb30df0d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×4 Matrix{Float64}:\n",
" 1.0 3.0 1.0 9.0\n",
" 0.0 1.0 -1.0 1.0\n",
" 0.0 0.0 1.0 35.0"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"A = Float64[1 3 1; 1 2 -1; 3 11 5]\n",
"b = Float64[9,1,35]\n",
@@ -373,15 +340,15 @@
"\n",
"```julia\n",
"n,m = size(B)\n",
"for k in 1:n\n",
" for t in k:m\n",
" B[k,t] = B[k,t]/B[k,k]\n",
" end\n",
" for i in (k+1):n \n",
" for j in k:m\n",
" B[i,j] = B[i,j] - B[i,k]*B[k,j]\n",
" end\n",
"for t in (k+1):m\n",
" B[k,t] = B[k,t]/B[k,k]\n",
"end\n",
"B[k,k] = 1\n",
"for i in (k+1):n \n",
" for j in (k+1):m\n",
" B[i,j] = B[i,j] - B[i,k]*B[k,j]\n",
" end\n",
" B[i,k] = 0\n",
"end\n",
"```"
]
@@ -403,37 +370,21 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "078e974e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"🥳 Well done! \n"
]
}
],
"outputs": [],
"source": [
"answer = \"a\" # replace x with a, b, c, or d \n",
"answer = \"x\" # replace x with a, b, c, or d \n",
"ge_par_check(answer)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"id": "1169c86e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The outer loop of the algorithm is not parallelizable, since the iterations depend on the results of the previous iterations. However, we can extract parallelism from the inner loops.\n"
]
}
],
"outputs": [],
"source": [
"ge_par_why()"
]
@@ -445,7 +396,7 @@
"source": [
"### Data partition\n",
"\n",
"Let start considering a row-wise block partition, as we did for the previous algorithms.\n",
"Let start considering a row-wise block partition, as we did in previous algorithms.\n",
"\n",
"In the figure below, we use different colors to illustrate which entries are assigned to a CPU. All entries with the same color are assigned to the same CPU."
]
@@ -501,7 +452,7 @@
"<b>Definition:</b> *Load imbalance*: is the problem when work is not equally distributed over all processes and consequently some processes do more work than others.\n",
"</div>\n",
"\n",
"Having processors waiting for others is a wast of computational resources and affects negatively parallel speedups. The optimal speedup (speedup equal to the number of processors) assumes that the work is perfectly parallel and that it is evenly distributed. If there is load imbalance, the last assumption is not true anymore and the speedup will be suboptimal.\n"
"Having processors waiting for others is a waist of computational resources and affects negatively parallel speedups. The optimal speedup (speedup equal to the number of processors) assumes that the work is perfectly parallel and that it is evenly distributed. If there is load imbalance, the last assumption is not true anymore and the speedup will be suboptimal.\n"
]
},
{
@@ -511,9 +462,9 @@
"source": [
"### Fixing load imbalance\n",
"\n",
"In this application is relatively easy to fix the load imbalance problem. We know in advance which data is going to be processes at each CPU and we can design a more clever data partition.\n",
"In this application, is relatively easy to fix the load imbalance problem. We know in advance which data is going to be processes at each CPU and we can design a more clever data partition.\n",
"\n",
"We can consider row-wise cyclic partition to fix the problem. See figure below. In this case, the CPUs will have less work as the value of $k$ increases, but amount of work will be better distributed than with the block partition."
"We can consider row-wise cyclic partition to fix the problem. See figure below. In this case, the CPUs will have less work as the value of $k$ increases, but amount of work will be better distributed than with the previous row block partition."
]
},
{
@@ -555,18 +506,10 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"id": "a6741a25",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It is a form of static load balancing. We know in advance the load distribution and the partition strategy does not depend on the actual values of the input matrix\n"
]
}
],
"outputs": [],
"source": [
"ge_lb_answer()"
]
@@ -578,46 +521,46 @@
"source": [
"### Data dependencies\n",
"\n",
"Using a cyclic partition, we managed to distribute the work uniformly. But we still need to study the data dependencies in order to implement it efficiently.\n",
"Using a cyclic partition, we managed to distribute the work uniformly. But we still need to study the data dependencies in order to implement this algorithm in parallel efficiently.\n",
"\n",
"Look again to the algorithm\n",
"\n",
"```julia\n",
"n,m = size(B)\n",
"for k in 1:n\n",
" for t in k:m\n",
" B[k,t] = B[k,t]/B[k,k]\n",
" end\n",
" for i in (k+1):n \n",
" for j in k:m\n",
" B[i,j] = B[i,j] - B[i,k]*B[k,j]\n",
" end\n",
"for t in (k+1):m\n",
" B[k,t] = B[k,t]/B[k,k]\n",
"end\n",
"B[k,k] = 1\n",
"for i in (k+1):n \n",
" for j in (k+1):m\n",
" B[i,j] = B[i,j] - B[i,k]*B[k,j]\n",
" end\n",
" B[i,k] = 0\n",
"end\n",
"```\n",
"\n",
"Note that all updates on the loop over i and j we do the following update \n",
"Note that all updates on the loop over i and j we do the following: \n",
"\n",
"```julia\n",
"B[i,j] = B[i,j] - B[i,k]*B[k,j]\n",
"```\n",
"\n",
"As we are using a row-wise partitions, the CPU that updates `B[i,j]` will also have entry `B[i,k]` in memory (both are in the same row). However, `B[k,j]` is in another row and it might be located on another processor. We might need to communicate `B[k,j]` for `j=k:m`. This corresponds to the cells marked in red in the figure below. These red entries are the data dependencies of this algorithm. The owner of these entries will send them to the other processors. This is very similar to the communications seen in previous notebook for Floyd's algorithm. There is a key difference however, in the current case we do not need to send the full row, only the entries beyond column $k$ (the red cells in the figure).\n"
"As we are using row-wise partitions, the CPU that updates `B[i,j]` will also have entry `B[i,k]` in memory (both are in the same row). However, `B[k,j]` is in another row and it might be located on another processor. We might need to communicate `B[k,j]` for `j=(k+1):m`. This corresponds to the cells marked in red in the figure below. These red entries are the data dependencies of this algorithm. The owner of these entries has to send them to the other processors. This is very similar to the communication pattern seen in previous notebook for Floyd's algorithm. There is a key difference however. In the current case, we do not need to send the full row, only the entries beyond column $k$ (the red cells in the figure).\n"
]
},
{
"attachments": {
"g30822.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAzAAAAJsCAYAAAAiM0YjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURBVHic7N15nBx1nf/xV/X0zOS+LxJOEw4JEORGEMEFFEXwRF1wFQWPXd0VcfHADU0WVERWRV1XQMRjXcFdEfH4KaCcchiCAoKAAiEhCQFykWuurt8fNQM9ne6eqU73VNXM6/l49CNd1d/v1LtnJj396W/V9xsgSRru8sDZJdt/Aa7rvd8OnAy8G9gD2AkoAo8DvwIuBZ6u8nX3A84AXg3sBowCVgP3AN8Hrm3kk5AkSZI0MowGwpLbj3r37wM8XPZY+W0D8LayrzcK+E+gZ4C+PwfGNOk5SZIkSRqmKhUwBwGbqF2A9N26geN7v9Yo4KZB9guBXwJBk5+fJEmSpGGkvID5DfBE7/2twOVEoyyHA8cAnwZWlfVZ2vt1vl2y7z6iU9OOBQ4FTiE6Na28iDmt+U9RkiRJ0nBRXsD03R4Fdq/SZ2bv46Xtf9D7bxH4VyBXpe8ny/rd14gnIUmSJGlkqFTArCG6YL+WEyr0C4FFA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5Z8kxorSDpAmVVEb+YOApYnnEU1hZcCJz69fdM2OGx1YnGq2wXYBKxPOkgVs4j+cD+cdJAq2oH5wIqkg9SwK7Aa6E46SBXzgT5gbdJBqpg6cHso6SA1LAIeTDhDLQuBLmBj0kGqmAu0AY8kHaSKcUQZ0/x7ZhHRe5S+hHNUs4Dod+DjSQcZakYOnlhYtvM0CL6TSBypSVYBIXBg0kE0nPBSCMOS27VJJ6riXuDMpEPUcAFwfdIhalgCbE46xDA2AgckHaKGq4ALkw5Rw+nAA0mHGEZv0gGG8RBwStIhargIuDzpEDUcTlQAptlWoiIhrW4Czk86xPbCaWXvFUIIT006lbLPa2AkSZIkZYYFjCRJkqTMsICRJEmSlBkWMJIkSZIyw2mUpeHtDOzB0wX/DUQzm0mSJKnFLGCk7b2UaD79g4mm9J5X9vgBwK2tDiVJkiQLGKmS/yVal0CSJEkp4zUwUnVbiU4X+xouJSxJkpQKjsBI23sX8DfgLp5edflyYPfEEkmSJAmwgJEq+WHSASRJklSZp5BJkiRJygwLGEmSJEmZYQEjSZIkKTMsYCRJkiRlhgWMJEmSpMywgJEkSZKUGRYwkiRJkjLDAkaSJElSZljASJIkScoMCxhJkiRJmWEBI0mSJCkzLGAkSZIkZYYFjCRJkqTMsICRJEmSlBn5pANIKbQUeG/Zvkkl968B+ku2Q2Bms0NJkiTJAkaqZDwwvcbjU8q2wyZmkSRJUgkLGGl7VzJ0hGU4FjCSJEktYgEjbe+3AzdJkiSljBfxS5IkScoMCxhJkiRJmWEBI0mSJCkzLGAkSZIkZYYFLine truncated
}
},
"cell_type": "markdown",
"id": "44639340",
"id": "0050b6c4",
"metadata": {},
"source": [
"<div>\n",
"<img src=\"attachment:g30822.png\" align=\"left\" width=\"300\"/>\n",
"</div>\n"
"<img src=\"attachment:g27851.png\" align=\"left\" width=\"300\"/>\n",
"</div>"
]
},
{
@@ -625,113 +568,26 @@
"id": "cf189776",
"metadata": {},
"source": [
"### Implementation\n",
"### Parallel implementation\n",
"\n",
"The parallel implementation of this method is closely related to the Floyd's algorithm. But there are some differences.\n",
"\n",
"At iteration $k$,\n",
"\n",
"1. The CPU owning row $k$ does the loop over $t$ to update row $k$\n",
"2. This CPU sends the "
]
},
{
"cell_type": "markdown",
"id": "9c553ada",
"metadata": {},
"source": [
"The computation of the complexity of computation and communication is left as an exercise.\n"
]
},
{
"cell_type": "markdown",
"id": "6b17aee4",
"metadata": {},
"source": [
"1. **Block-wise row partitioning**: Each processor gets a block of subsequent rows. \n",
"2. **Cyclic row partitioning**: The rows are alternately assigned to different processors."
]
},
{
"attachments": {
"fig-asp-1d-partition.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABL4AAAI0CAYAAAATGeCIAAAACXBIWXMAAB7CAAAewgFu0HU+AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAIABJREFUeJzs3XmcXFWZ//HvU1XdnU5nIyEhCYRVGBYBWRwQERFk2JRVUBxEXAYXXEcUB3QE11FREcF12BQFQWRRGJBNVFBQdhAwkIXsezq9d1Xd5/fHrfzsVN1Oeq17cvN5v155Kae2p+69ffv09557jrm7AGy+zOxsSVdXNX/N3S+oYw3Nkjqrmue4+y71qmFzYmbtklr6NLW5+4S06gEAAEA2mdmnJX2jqvk8d/9WGvUAaSikXQC2XGZ2uqRJfZpud/elI/Teh2tgx3e7pF5JayV1S+p097UjUQMAAACyzcxOkbR1n6Y73X3hCL33oZLGDOCpHZJ6FPdnexT3Z9eMRA3YcpnZREn/lfDQbe7+53rXAwwHwRdSYWY5SVdpw1Evz0kakeBL0i3aMFQbMDNbJ+kFSX+X9Lyk+yQ97gyPBAAAwIZ+KGlqn/8+RtKIBF+SfiFp1lBeaGZtkl7UP/uz90v6K/1ZDMJ4SecntC+URPCFzQrBF9JyqDYMvUIyQdK/Vv6tt8DMbpf0fXf/ezplAQAAIBRmtr82DL1CMl7SgZV/6y02s99I+oG7P5VOWQBQf7m0C8CWx8yaJH0t7ToGaZakcyU9Y2a/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S8u29y4lQAAIBNSOrPJo3WGXGVAOmzCQ9dU+lXDYq7r3T3t0t6u6Sakf+V1SqrVy8vSDpnkB/1DtWOULtzYxduzaxF0mcSHrrS3ZPugNgod1/u7m+T9E5JQ16ZchRcnND2R8UjvTY691k1d+9090+o/4v0wCYRfAHDtyyhbVLdq9jQX4ayLLO7363kWzTfNvySEp2j2tDpN+7+0GDfyN1/pfi2zr4mKp7PLJGZTVLcKar2CXdfO9ga+tTyYqWeYancQvlL1c491i7pOHevy+0HAAAg85L6s0m34o2GU1UbIK1VvFrhkLn7je6eFOhJyaOy3l+54DhQH05o21R4dZpqt+tqxbctDpm7Xz+QOyXqobKy/L5VzesvbA951Ja7P+jufxpWcdhiEXwBw5c08eKmRhmFLGmlygNG6bOS5tW6bhjvl/TajU1yf7hqV8BZovi2wlSZWV7StZJOqnqoQ/FE9n+of1UAACCjkuakqld/9tiEtp8P5PbGYbhRtWHfdEmnDOTFlXDnwKrmf2jT84QlfdefDeT2xs1I9WT/knSPu/+j7pUAFQRfwPAlrYi4OS8ckbQy4Egss7yByrxV+1U1u+JVeYbqjoS2QzayRHX1nFmS9Et3r14psq4qK2leI+mMqofaJB3D7Y0AAGCEJfV96tWfPSyh7YbR/MDKvGZXJjyUNO1HkqTnXTaA2/jq/l1TkPQdr697FUAfBF/A8FWvgCNJm/NVmxcS2qZVliQeSa+R1FTVNreyYMBQzVEcDvU1TfGkmEkOTWh7dBifP2yVkO4nks6seqhN0rEM8QYAAKMglf5sZXXv7aqaS4pX9httP1LtBezDzKx6lfMNmNlUSadXNa+T9NNNvG5XxaPK+uqV9MSmS908VKbpODjhoerpSIC6IvgChi9p/oPRHJo9qipDrVckPDTS8zzMTGhLCt0GrHKVLWmVzW37eUl1R0uSnhpODcNRCb2uUO0S2+sUj/Qa9NxnAAAAA5BWfzapLine truncated
}
},
"cell_type": "markdown",
"id": "c518f863",
"metadata": {},
"source": [
"<div>\n",
"<img src=\"attachment:fig-asp-1d-partition.png\" align=\"left\" width=\"400\"/>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "746e37f6",
"metadata": {},
"source": [
"### Block-wise partition"
]
},
{
"cell_type": "markdown",
"id": "102d6fa2",
"metadata": {},
"source": [
"To evaluate the efficiency of both partitioning schemes, consider how much work the processors do in the following example. \n",
"In any iteration k, which part of the matrix is updated in the inner loops? \n",
"1. The CPU owning row $k$ does the loop over $t$ to update row $k$.\n",
"2. The CPU owning row $k$ sets $B_{kk} = 1$.\n",
"2. This CPU sends the red cells in figure above to the other processors.\n",
"3. All processors receive the updated values in row $k$ and do the loop over i and j locally (blue cells).\n",
"\n",
"### Block-wise partition"
]
},
{
"cell_type": "markdown",
"id": "d9d29899",
"metadata": {},
"source": [
"It is clear from the code that at any given iteration `k`, the matrix is updated from row `k` to `n` and from column `k` to `m`. If we look at how that reflects the distribution of work over the processes, we can see that CPU 1 does not have any work, whereas CPU 2 does a little work and CPU 3 and 4 do a lot of work. "
]
},
{
"cell_type": "markdown",
"id": "6409890d",
"metadata": {},
"source": [
"### Load imbalance\n",
"\n",
"The block-wise partitioning scheme leads to load imbalance across the processes: CPUs with rows $<k$ are idle during any iteration $k$. The bad load balance leads to bad speedups, as some CPUs are waiting instead of doing useful work. \n",
" \n",
"### Data dependencies\n",
" \n",
"\n"
]
},
{
"attachments": {
"fig-asp-data-updated.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAtcAAAJNCAYAAAD6c1l4AAAACXBIWXMAAB7CAAAewgFu0HU+AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAIABJREFUeJzs3XeYJFXVx/Hv6ZnZvLC7LGFZwrLkDIpECRJEEMVXl/waEQyor6IoBhAFEwZEBUFUVEREEQwgIkEyIkGQKJkl7i5h8+ykPu8ft4btrqmeTtVTNTO/z/P0A32n6tbZ6urqU7du3Wvujohkx8w6gXHR2053n5BlPKOFmc0GHi8pusvdd8ggjo2B24GpJcW3APu6+4qhjkdkuDCz04AvlhQd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ihHNrTefIKvGcF6t30GfXRttrNPa5hnAwxodBWzPlbfwx9r7ayB1Z+lPs/awsghgCX3D3R2tc9mSgdAirmYQRCpLEn96+0GscHWEIxY/HWS3e3pGUjzjyNXd/vJYVPQzF98OSImPgjIT9Toi9P83d7685yqGzBmGYun7VunXlhpmtShhZp9/9wBl1VHEu5f2A491jBnMV4U7cOd76Cb/yfh78WOz9d732EXW+QOg+0m8PM9u2jm3v7zWMoexhxJrLY8WVRpMZEmZ2FCER7D9HO6HF+tzsomrIaoQuXqVOob7nTCB0Qb3JzAYdEagG8XPYpk3WN6KMuj7XLine truncated
}
},
"cell_type": "markdown",
"id": "a67e0aad",
"metadata": {},
"source": [
"<div>\n",
"<img src=\"attachment:fig-asp-data-updated.png\" align=\"left\" width=\"250\"/>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0565e92",
"metadata": {},
"outputs": [],
"source": [
"answer = \"x\" # replace x with a, b, c, or d \n",
"ge_dep_check(answer)"
"As you probably see, the parallel implementation of this method is closely related to Floyd's algorithm. But there are some differences. \n",
"\n",
"1. The process that owns row $k$ updates its values before sending them.\n",
"2. We do not send the full row $k$, only the entries beyond column $k$.\n",
"3. We need a cyclic partition to balance the load properly.\n",
"\n",
"A key similarity between the two algorithms, however, is that they both suffer from synchronization problems. We need to make sure that the rows arrive in the right order. The strategies discussed for Floyd's algorithm also apply in this current case.\n",
"\n",
"The actual implementation of the parallel algorithm is left as an open exercise."
]
},
{
@@ -740,54 +596,9 @@
"metadata": {},
"source": [
"## Conclusion\n",
"Cyclic partitioning tends to work well in problems with predictable load imbalance. It is a form of **static load balancing** which means using a pre-defined load schedule based on prior information about the algorithm (as opposed to **dynamic load balancing** which can schedule loads flexibly during runtime). The data dependencies are the same as for the 1d block partitioning.\n",
"\n",
"At the same time, cyclic partitioning is not suitable for all communication patterns. For example, it can lead to a large communication overhead in the parallel Jacobi method, since the computation of each value depends on its neighbouring elements."
]
},
{
"cell_type": "markdown",
"id": "20982b04",
"metadata": {},
"source": [
"## Exercise\n",
"The actual implementation of the parallel algorithm is left as an exercise. Implement both 1d block and 1d cyclic partitioning and compare their performance. The implementation is closely related to that of Floyd's algorithm. To test your algorithms, generate input matrices with the function below (a random matrix is not enough, we need a non singular matrix that does not require pivoting). "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a65cf8e6",
"metadata": {},
"outputs": [],
"source": [
"function tridiagonal_matrix(n)\n",
" C = zeros(n,n)\n",
" stencil = [(-1,2,-1),(-1,0,1)]\n",
" for i in 1:n\n",
" for (coeff,o) in zip((-1,2,-1),(-1,0,1))\n",
" j = i+o\n",
" if j in 1:n\n",
" C[i,j] = coeff\n",
" end\n",
" end\n",
" end\n",
" C\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "31d8586a",
"metadata": {},
"outputs": [],
"source": [
"n = 12\n",
"C = tridiagonal_matrix(n)\n",
"b = ones(n)\n",
"B = [C b]\n",
"gaussian_elimination!(B)"
"\n",
"We studied the parallelization of an algorithm that leads to load imbalance. We fixed the problem using a cyclic partition. This is a form of static load balancing since we were able to distribute the load in advance without using runtime values. This is opposed to dynamic load balancing which can schedule loads flexibly during runtime. Note however that cyclic partitioning is not suitable for all communication patterns. For example, it can lead to a large communication overhead in the parallel Jacobi method, since the computation of each value depends on its neighboring elements.\n"
]
},
{
@@ -801,14 +612,6 @@
"\n",
"This notebook is part of the course [Programming Large Scale Parallel Systems](https://www.francescverdugo.com/XM_40017) at Vrije Universiteit Amsterdam and may be used under a [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) license."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ab22f67",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
+5 -5
View File
@@ -647,7 +647,7 @@
"- On the receive side $O(N)/O(N^2/P) = O(P/N)$\n",
"\n",
"\n",
"In summary, the send/computation ratio is $O(P^2/N)$ and the receive/computation ratio is $O(P/N)$. The algorithm is potentially scalable if $P^2<<N$. Note that this is worse than for matrix-matrix multiplication, which is scalable for $P<<N$."
"In summary, the send/computation ratio is $O(P^2/N)$ and the receive/computation ratio is $O(P/N)$. The algorithm is potentially scalable if $P^2<<N$. Note that this is worse than for matrix-matrix multiplication, which is scalable for $P<<N$. I.e., you need a larger problem size in the current algorithm than in matrix-matrix multiplication."
]
},
{
@@ -755,7 +755,7 @@
"### Distributing the input matrix\n",
"\n",
"Since only rank 0 receives the input matrix C, this rank needs to split it row-wise and\n",
"send the pieces to all other ranks. This is done in the function below. We start by communicating the problem size N to all ranks (at the start only rank 0 knows the problem size). This is trivially done with an `MPI.Bcast!`. Once all ranks know the problem size, they can allocate space for their local part of `C` , called `myC` in the code. After this, rank 0 sends the pieces to all other ranks. We do it here with `MPI.Send` and `MPI.Recv!`. This can also be done with `MPI.Scatter!`, but it is more challenging since we are using a row partition and Julia stores the matrices in column major order. Note that this algorithm can also be implemented using a column-wise matrix partition. In this case, using `MPI.Scatter!` would provably be the best option.\n"
"send the pieces to all other ranks. This is done in the function below. We start by communicating the problem size N to all ranks (at the start only rank 0 knows the problem size). This is trivially done with an `MPI.Bcast!`. Once all ranks know the problem size, they can allocate space for their local part of `C` , called `myC` in the code. After this, rank 0 sends the pieces to all other ranks. We do it here with `MPI.Send` and `MPI.Recv!`. This can also be done with `MPI.Scatter!`, but it is more challenging since we are using a row partition and Julia stores the matrices in column major order. Note that this algorithm can also be implemented using a column partition. In this case, using `MPI.Scatter!` would probably be the best option.\n"
]
},
{
@@ -894,7 +894,7 @@
"source": [
"### Collecting back the results\n",
"\n",
"At this point, we have solved the ASP problem, but the solution is cut in different pieces, each one stored on a different MPI rank. It is often useful to gather the solution into a single matrix, e.g., to compare it against the sequential algorithm.The following function collects all pieces and stores them in $C$ on rank 0. Again, we implement this with `MPI.Send` and `MPI.Recv!` as it is easier as we are working with a row-partition. However, we could do it also with `MPI.Gather!`."
"At this point, we have solved the ASP problem, but the solution is cut in different pieces, each one stored on a different MPI rank. It is often useful to gather the solution into a single matrix, e.g., to compare it against the sequential algorithm.The following function collects all pieces and stores them in $C$ on rank 0. Again, we implement this with `MPI.Send` and `MPI.Recv!` as it is easier as we are working with a row partition. However, we could do it also with `MPI.Gather!`."
]
},
{
@@ -1024,7 +1024,7 @@
"source": [
"## Is this implementation correct?\n",
"\n",
"In the cell above, the result of the parallel code was provably the same as for the sequential code. However, is this sufficient to assert that the code is correct? Unfortunately no. In fact, the parallel code we implemented is not correct. There is no guarantee that this code computes the correct result. This is why:\n",
"In the cell above, the result of the parallel code was probably the same as for the sequential code. However, is this sufficient to assert that the code is correct? Unfortunately, it is not. In fact, **the parallel code we implemented is not correct!** There is no guarantee that this code computes the correct result. This is why:\n",
"\n",
"In MPI, point-to-point messages are *non-overtaking* between a given sender and receiver. Say that process 1 sends several messages to process 3. All these will arrive in FIFO order. This is according to section 3.5 of the MPI standard 4.0.\n",
"Unfortunately, this is not enough in our case. The messages could arrive in the wrong order *from different senders*. If process 1 sends messages to process 3, and then process 2 sends other messages to process 3, it is not granted that process 3 will receive first the messages from process 1 and then from process 2 (see figure below)."
@@ -1113,7 +1113,7 @@
"\n",
"### Exercise 1\n",
"\n",
"Modify the `floyd_iterations!` function so that it is guaranteed that the result is computed correctly. Use `MPI.Bcast!` to solve the synchronization problem. Note: only use `MPI.Bcast!`in `floyd_iterations!`, do not use other MPI directives. "
"Modify the `floyd_iterations!` function so that it is guaranteed that the result is computed correctly. Use `MPI.Bcast!` to solve the synchronization problem. Note: only use `MPI.Bcast!`in `floyd_iterations!`, do not use other MPI directives. You can assume that the number of rows is a multiple of the number of processes."
]
},
{
File diff suppressed because it is too large. Load diff

Before

Width:  |  Height:  |  Size: 6.7 MiB

After

Width:  |  Height:  |  Size: 6.8 MiB