cis 330 c++ and unix · c++ and unix lecture 8 memory and pointers ii (with graphs and bfs) live...
TRANSCRIPT
![Page 1: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/1.jpg)
CIS 330 C++ and UnixLecture 8
Memory and Pointers II (with Graphs and BFS)
![Page 2: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/2.jpg)
Live Coding � Pointers and memory
![Page 3: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/3.jpg)
Matrix Multiplication
![Page 4: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/4.jpg)
Matrix Multiplication ci,n =∑"#$% &', ) ∗ +), ,
M
M
NN
c3,3 = a3,1 * b1,3 + a3,2 * b2,3
![Page 5: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/5.jpg)
Example
� Sparse matrix – matrix with only a small number of values that are not zeros
� SpMV – Sparse Matrix Vector Multiply� Systems of equations � Graph processing
![Page 6: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/6.jpg)
SpMV0 1 2 0 0
3 0 1 0 0
0 0 0 0 0
1 1 0 0 6
0 0 1 9 0
1
3
2
5
1
7
5
0
10
47
![Page 7: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/7.jpg)
SpMV0 1 2 0 0
3 0 1 0 0
0 0 0 0 0
1 1 0 0 6
0 0 1 9 0
1
3
2
5
1
7
5
0
10
47
![Page 8: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/8.jpg)
SpMV in COO
0 1 2 0 0
3 0 1 0 0
0 0 0 0 0
1 1 0 0 6
0 0 1 9 0
row col val
1 2 1
1 3 2
2 1 3
2 3 1
4 1 1
4 2 1
4 5 6
5 3 1
5 4 9
![Page 9: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/9.jpg)
Example Sparse Matrices
sparsity = 0.33%
![Page 10: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/10.jpg)
Compressed Sparse Row
row col val
1 2 1
1 3 2
2 1 3
2 3 1
4 1 1
4 2 1
4 5 6
5 3 1
5 4 9
2 3 1 3 1 2 5 3 4
1 2 3 1 1 1 6 1 9
col
val
1 3 5 5 8 10 row_ptr
![Page 11: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/11.jpg)
Algorithm
� Input: A ∈ℝI×J, x ∈ℝJ
� Output: Ax = y ∈ℝI
� for i = 1 to I /* number of rows */
� get begin and end index into col and val for row I
� for j = begin to end
� y[i] += val[j] * x[ col[j] ]
� end
� end
![Page 12: CIS 330 C++ and Unix · C++ and Unix Lecture 8 Memory and Pointers II (with Graphs and BFS) Live Coding Pointers and memory. Matrix Multiplication. ... 04_Debugging_Graphs_BFS Created](https://reader036.vdocuments.us/reader036/viewer/2022062607/6044c38df7a5ca2e9821ef6d/html5/thumbnails/12.jpg)
SpMV� The concept is simple when you understand it, but initially difficult
to grasp the indexing
� Questions?