1. Introduction and Matrix Multiplication

MIT OpenCourseWare · 292K views · 2021 · 1:00:21

Open on YouTube

Software performance & optimizationUniversity lectures & coursesC, C++, Rust, Go & systems languageslecture

Why Stack Overflow recommends it

Stack Overflow users link it as a clear walkthrough of matrix multiplication optimization and cache behavior, and often cite its benchmark claims when asking why their own timings differ.

Recommended by 1 people across 1 different months, 2020 to 2022.

What it is

The first lecture of MIT's 6.172 Performance Engineering of Software Systems, taught by Charles Leiserson. It uses matrix multiplication as a running example, comparing Python, Java and C and showing step by step how loop order, cache use and other optimizations change speed.

What people said

Recommends Jakub Biały · 2020-08 · Stack Overflow · on “Speed up AVX large matrix multiplication even more? Avoiding stores in the inner loop?”

If anyone is interested in simple step by step matrix multiplication optimization there is a good video from MIT: [this video]

Cites javando · 2020-06 · Stack Overflow · on “Performance analysis of the same algorithm in Java and C”

Preamble : I was watching the first class of this MIT course on youtube [this video] and around the time 22:20 the teacher presents the results of a performance comparison of the same algorithm in Java and C. He said that the C implementation is 2x faster than the Java implementation, so I tried it at home to see with my own eyes, but the fact is that the Java implementation turned out to be faster than the C one, and I'm seeking for help to understand why. The problem implementations I have these two implementations of the same algorithm: C #include <stdlib.h> #include <stdio.h> #include <sys/time.h> #define n 1024 double A[n][n]; double B[n][n]; double C[n][n]; float tdiff(struct timeval *start

Cites Gabriel Gamboa Vargas · 2021-10 · Stack Overflow · on “Cache hits on matrix multiplication”

[this video] In this video he is explaining that retrieving data that is far away creates a worse cache lines utilization and then he follows with a line that I don't understand. "so the processor is going to be bringing in 64 bytes to operate on a particular datum. And then it's ignoring 7 of the 8 floating-point words on that cache line and going to the next one" What does he mean by that.

Cites Luiz Felipe Cruz Borges · 2022-06 · Stack Overflow · on “Why is the performance of this program reduced with multithreading as compared to a single thread?”

I'm trying to improve the performance of my code, but when I added new threads, my performance had dropped. First version: public int[][] calculate(int[][] matriz1, int [][] matriz2, int matrixSize) { int[][] matrix = new int[matrixSize][matrixSize]; for(int i = 0; i < matrixSize; i++){ for(int k = 0; k < matrixSize; k++){ for(int j = 0; j < matrixSize; j++){ matrix[i][j] = matrix[i][j] + matriz1[i][k] * matriz2[k][j]; } } } return matrix; } Second version: public int[][] calculate(int[][] matriz1, int[][] matriz2, int matrixSize) { final int[][] matrix = new int[matrixSize][matrixSize]; CountDownLatch latchA = new CountDownLatch((int) (Math.pow(matrixSize, 3))); List<Thread> threads = new A