mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-24 09:24:32 +01:00
Major updates in jacobi method
This commit is contained in:
@@ -1497,46 +1497,46 @@
|
||||
"function matmul_mpi_3!(C,A,B)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Assume that the input matrices `A` and `B` are given only on rank 0, the other ranks get dummy matrices with zero rows and zero columns to save memory. You need to communicate the required parts to other ranks. For simplicity you can assume that `A` and `B` are square matrices and that the number of rows is a multiple of the number of processes (on rank 0). The result `C` should be overwritten only on rank 0. You can use the following cell to implement and check your result."
|
||||
"Assume that the input matrices `A` and `B` are given only on rank 0, the other ranks get dummy matrices with zero rows and zero columns to save memory. You need to communicate the required parts to other ranks. For simplicity you can assume that `A` and `B` are square matrices and that the number of rows is a multiple of the number of processes (on rank 0). The result `C` should be overwritten only on rank 0. You can use the following cell to implement and check your result. Copy the code below to a file called `ex1.jl`. Modify the file (e.g. with vscode). Run it from the Julia REPL using the `run` function as explained in the [Getting Started tutorial](https://www.francescverdugo.com/XM_40017/dev/getting_started_with_julia/#Running-MPI-code)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "265c4593",
|
||||
"cell_type": "markdown",
|
||||
"id": "4fa53366",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"code = quote\n",
|
||||
" using MPI\n",
|
||||
" MPI.Init()\n",
|
||||
" function matmul_mpi_3!(C,A,B)\n",
|
||||
" # Implement here\n",
|
||||
" end\n",
|
||||
" function testit(load)\n",
|
||||
" comm = MPI.COMM_WORLD\n",
|
||||
" rank = MPI.Comm_rank(comm)\n",
|
||||
" if rank == 0\n",
|
||||
" P = MPI.Comm_size(comm)\n",
|
||||
" N = load*P\n",
|
||||
" else\n",
|
||||
" N = 0\n",
|
||||
" end\n",
|
||||
" A = rand(N,N)\n",
|
||||
" B = rand(N,N)\n",
|
||||
" C = similar(A)\n",
|
||||
" matmul_mpi_3!(C,A,B)\n",
|
||||
" if rank == 0\n",
|
||||
" if !(C ≈ A*B)\n",
|
||||
" println(\"Check not passed\")\n",
|
||||
" else\n",
|
||||
" println(\"Check passed!\")\n",
|
||||
" end\n",
|
||||
" end\n",
|
||||
" end\n",
|
||||
" testit(100)\n",
|
||||
"```julia\n",
|
||||
"# ex1.jl (begin)\n",
|
||||
"using MPI\n",
|
||||
"MPI.Init()\n",
|
||||
"function matmul_mpi_3!(C,A,B)\n",
|
||||
" # Implement here\n",
|
||||
"end\n",
|
||||
"run(`$(mpiexec()) -np 4 julia --project=. -e $code`);"
|
||||
"function testit(load)\n",
|
||||
" comm = MPI.COMM_WORLD\n",
|
||||
" rank = MPI.Comm_rank(comm)\n",
|
||||
" if rank == 0\n",
|
||||
" P = MPI.Comm_size(comm)\n",
|
||||
" N = load*P\n",
|
||||
" else\n",
|
||||
" N = 0\n",
|
||||
" end\n",
|
||||
" A = rand(N,N)\n",
|
||||
" B = rand(N,N)\n",
|
||||
" C = similar(A)\n",
|
||||
" matmul_mpi_3!(C,A,B)\n",
|
||||
" if rank == 0\n",
|
||||
" if !(C ≈ A*B)\n",
|
||||
" println(\"Test failed 😢\")\n",
|
||||
" else\n",
|
||||
" println(\"Test passed 🥳\")\n",
|
||||
" end\n",
|
||||
" end\n",
|
||||
"end\n",
|
||||
"testit(100)\n",
|
||||
"end\n",
|
||||
"# ex1.jl (end)\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1548,7 +1548,7 @@
|
||||
"\n",
|
||||
"Implement this \"simple\" algorithm (the telephone game):\n",
|
||||
"\n",
|
||||
"Rank 0 generates a message (an integer). Rank 0 sends the message to rank 1. Rank 1 receives the message, increments the message by 1, and sends the result to rank 2. Rank 2 receives the message, increments the message by 1, and sends the result to rank 3. Etc. The last rank sends back the message to rank 0 closing the ring. See the next figure. Implement the communications using MPI. Do not use `Distributed`.\n"
|
||||
"Rank 0 generates a message (an integer). Rank 0 sends the message to rank 1. Rank 1 receives the message, increments the message by 1, and sends the result to rank 2. Rank 2 receives the message, increments the message by 1, and sends the result to rank 3. Etc. The last rank sends back the message to rank 0 closing the ring. See the next figure. Implement the communications using MPI. Do not use `Distributed`. Use a text editor and the Julia REPL. Do not try to implement the code in a notebook.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user