mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-09 12:14:24 +01:00
commit
e4eea0da0a
@ -395,5 +395,42 @@ function jacobi_mpi(n,niters,tol,comm) # new tol arg
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## All pairs of shortest paths
|
||||||
|
|
||||||
|
### Exercise 1
|
||||||
|
|
||||||
|
```julia
|
||||||
|
function floyd_iterations!(myC,comm)
|
||||||
|
L = size(myC,1)
|
||||||
|
N = size(myC,2)
|
||||||
|
rank = MPI.Comm_rank(comm)
|
||||||
|
P = MPI.Comm_size(comm)
|
||||||
|
lb = L*rank+1
|
||||||
|
ub = L*(rank+1)
|
||||||
|
C_k = similar(myC,N)
|
||||||
|
for k in 1:N
|
||||||
|
if (lb<=k) && (k<=ub)
|
||||||
|
# If I have the row, fill in the buffer
|
||||||
|
myk = (k-lb)+1
|
||||||
|
C_k[:] = view(myC,myk,:)
|
||||||
|
end
|
||||||
|
# We need to find out the owner of row k.
|
||||||
|
# Easy since N is a multiple of P
|
||||||
|
root = div(k-1,L)
|
||||||
|
MPI.Bcast!(C_k,comm;root)
|
||||||
|
# Now, we have the data dependencies and
|
||||||
|
# we can do the updates locally
|
||||||
|
for j in 1:N
|
||||||
|
for i in 1:L
|
||||||
|
myC[i,j] = min(myC[i,j],myC[i,k]+C_k[j])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
myC
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@
|
|||||||
"function q1_answer(bool)\n",
|
"function q1_answer(bool)\n",
|
||||||
" bool || return\n",
|
" bool || return\n",
|
||||||
" msg = \"\"\"\n",
|
" msg = \"\"\"\n",
|
||||||
" The we can change the loop order over i and j without changing the result. Rememebr:\n",
|
" The we can change the loop order over i and j without changing the result. Rememeber:\n",
|
||||||
" \n",
|
" \n",
|
||||||
" C[i,j] = min(C[i,j],C[i,k]+C[k,j])\n",
|
" C[i,j] = min(C[i,j],C[i,k]+C[k,j])\n",
|
||||||
" \n",
|
" \n",
|
||||||
@ -858,7 +858,7 @@
|
|||||||
" P = MPI.Comm_size(comm)\n",
|
" P = MPI.Comm_size(comm)\n",
|
||||||
" lb = L*rank+1\n",
|
" lb = L*rank+1\n",
|
||||||
" ub = L*(rank+1)\n",
|
" ub = L*(rank+1)\n",
|
||||||
" C_k = similar(C,N)\n",
|
" C_k = similar(myC,N)\n",
|
||||||
" for k in 1:N\n",
|
" for k in 1:N\n",
|
||||||
" if (lb<=k) && (k<=ub)\n",
|
" if (lb<=k) && (k<=ub)\n",
|
||||||
" # Send row k to other workers if I have it\n",
|
" # Send row k to other workers if I have it\n",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user