Skip to content

Commit

Permalink
Add sol L8
Browse files Browse the repository at this point in the history
  • Loading branch information
luraess committed Nov 21, 2023
1 parent dcd421b commit f71856c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
4 changes: 2 additions & 2 deletions exercise-notebooks/notebooks/lecture8_ex1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
4 changes: 2 additions & 2 deletions exercise-notebooks/notebooks/lecture8_ex2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
4 changes: 2 additions & 2 deletions exercise-notebooks/notebooks/lecture9_ex1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
4 changes: 2 additions & 2 deletions exercise-notebooks/notebooks/lecture9_ex2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
37 changes: 19 additions & 18 deletions slide-notebooks/notebooks/l8_1-multi-xpu.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@
"CL[2:end-1] .= CL[2:end-1] .+ dt*D*diff(diff(CL)/dx)/dx\n",
"CR[2:end-1] .= CR[2:end-1] .+ dt*D*diff(diff(CR)/dx)/dx\n",
"# Update boundaries (MPI)\n",
"CL[end] = ...\n",
"CR[1] = ...\n",
"CL[end] = CR[2]\n",
"CR[1] = CL[end-1]\n",
"# Global picture\n",
"C .= [CL[1:end-1]; CR[2:end]]\n",
"```"
Expand Down Expand Up @@ -385,8 +385,8 @@
"\n",
"```julia\n",
"# Update boundaries (MPI)\n",
"CL[end] = ...\n",
"CR[1] = ...\n",
"CL[end] = CR[2]\n",
"CR[1] = CL[end-1]\n",
"```\n",
"\n",
"in order make the code work properly and run it again. Note what has changed in the visualisation."
Expand Down Expand Up @@ -422,7 +422,8 @@
" C[2:end-1,ip] .= C[2:end-1,ip] .+ dt*D*diff(diff(C[:,ip])/dxg)/dxg\n",
"end\n",
"for ip = 1:np-1 # update boundaries\n",
" # ...\n",
" C[end,ip ] = C[ 2,ip+1]\n",
" C[ 1,ip+1] = C[end-1,ip ]\n",
"end\n",
"for ip = 1:np # global picture\n",
" i1 = 1 + (ip-1)*(nx-2)\n",
Expand Down Expand Up @@ -472,7 +473,7 @@
"# Initial condition\n",
"for ip = 1:np\n",
" for ix = 1:nx\n",
" x[ix,ip] = ...\n",
" x[ix,ip] = ( (ip-1)*(nx-2) + (ix-0.5) )*dxg - 0.5*lx\n",
" C[ix,ip] = exp(-x[ix,ip]^2)\n",
" end\n",
" i1 = 1 + (ip-1)*(nx-2)\n",
Expand Down Expand Up @@ -596,19 +597,19 @@
"@views function update_halo!(A, neighbors_x, comm)\n",
" # Send to / receive from neighbour 1 (\"left neighbor\")\n",
" if neighbors_x[1] != MPI.PROC_NULL\n",
" sendbuf = ??\n",
" recvbuf = ??\n",
" MPI.Send(??, neighbors_x[?], 0, comm)\n",
" MPI.Recv!(??, neighbors_x[?], 1, comm)\n",
" A[1] = ??\n",
" sendbuf = A[2]\n",
" recvbuf = zeros(1)\n",
" MPI.Send(sendbuf, neighbors_x[1], 0, comm)\n",
" MPI.Recv!(recvbuf, neighbors_x[1], 1, comm)\n",
" A[1] = recvbuf[1]\n",
" end\n",
" # Send to / receive from neighbour 2 (\"right neighbor\")\n",
" if neighbors_x[2] != MPI.PROC_NULL\n",
" sendbuf = ??\n",
" recvbuf = ??\n",
" MPI.Recv!(??, neighbors_x[?], 0, comm)\n",
" MPI.Send(??, neighbors_x[?], 1, comm)\n",
" A[end] = ??\n",
" sendbuf = A[end-1]\n",
" recvbuf = zeros(1)\n",
" MPI.Recv!(recvbuf, neighbors_x[2], 0, comm)\n",
" MPI.Send(sendbuf, neighbors_x[2], 1, comm)\n",
" A[end] = recvbuf[1]\n",
" end\n",
" return\n",
"end\n",
Expand Down Expand Up @@ -1077,11 +1078,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
4 changes: 2 additions & 2 deletions slide-notebooks/notebooks/l9_1-projects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
4 changes: 2 additions & 2 deletions slide-notebooks/notebooks/l9_2-doc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
"version": "1.9.4"
},
"kernelspec": {
"name": "julia-1.9",
"display_name": "Julia 1.9.3",
"display_name": "Julia 1.9.4",
"language": "julia"
}
},
Expand Down
33 changes: 17 additions & 16 deletions website/_literate/l8_1-multi-xpu_web.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ The idea of this fake parallelisation approach is the following:
CL[2:end-1] .= CL[2:end-1] .+ dt*D*diff(diff(CL)/dx)/dx
CR[2:end-1] .= CR[2:end-1] .+ dt*D*diff(diff(CR)/dx)/dx
# Update boundaries (MPI)
CL[end] = ...
CR[1] = ...
CL[end] = CR[2]
CR[1] = CL[end-1]
# Global picture
C .= [CL[1:end-1]; CR[2:end]]
```
Expand All @@ -209,8 +209,8 @@ Then, add the required boundary update:
```julia
# Update boundaries (MPI)
CL[end] = ...
CR[1] = ...
CL[end] = CR[2]
CR[1] = CL[end-1]
```
in order make the code work properly and run it again. Note what has changed in the visualisation.
Expand All @@ -234,7 +234,8 @@ for ip = 1:np # compute physics locally
C[2:end-1,ip] .= C[2:end-1,ip] .+ dt*D*diff(diff(C[:,ip])/dxg)/dxg
end
for ip = 1:np-1 # update boundaries
# ...
C[end,ip ] = C[ 2,ip+1]
C[ 1,ip+1] = C[end-1,ip ]
end
for ip = 1:np # global picture
i1 = 1 + (ip-1)*(nx-2)
Expand Down Expand Up @@ -266,7 +267,7 @@ md"""
# Initial condition
for ip = 1:np
for ix = 1:nx
x[ix,ip] = ...
x[ix,ip] = ( (ip-1)*(nx-2) + (ix-0.5) )*dxg - 0.5*lx
C[ix,ip] = exp(-x[ix,ip]^2)
end
i1 = 1 + (ip-1)*(nx-2)
Expand Down Expand Up @@ -351,19 +352,19 @@ Then, we need to (2.) implement a boundary update routine, which can have the fo
@views function update_halo!(A, neighbors_x, comm)
# Send to / receive from neighbour 1 ("left neighbor")
if neighbors_x[1] != MPI.PROC_NULL
sendbuf = ??
recvbuf = ??
MPI.Send(??, neighbors_x[?], 0, comm)
MPI.Recv!(??, neighbors_x[?], 1, comm)
A[1] = ??
sendbuf = A[2]
recvbuf = zeros(1)
MPI.Send(sendbuf, neighbors_x[1], 0, comm)
MPI.Recv!(recvbuf, neighbors_x[1], 1, comm)
A[1] = recvbuf[1]
end
# Send to / receive from neighbour 2 ("right neighbor")
if neighbors_x[2] != MPI.PROC_NULL
sendbuf = ??
recvbuf = ??
MPI.Recv!(??, neighbors_x[?], 0, comm)
MPI.Send(??, neighbors_x[?], 1, comm)
A[end] = ??
sendbuf = A[end-1]
recvbuf = zeros(1)
MPI.Recv!(recvbuf, neighbors_x[2], 0, comm)
MPI.Send(sendbuf, neighbors_x[2], 1, comm)
A[end] = recvbuf[1]
end
return
end
Expand Down

0 comments on commit f71856c

Please sign in to comment.