Skip to content

Optimized Matrix Multiplication and Validation Logic#2

Open
BehrozKarim wants to merge 2 commits into
AA-parallel-computing:mainfrom
BehrozKarim:behroz-karim
Open

Optimized Matrix Multiplication and Validation Logic#2
BehrozKarim wants to merge 2 commits into
AA-parallel-computing:mainfrom
BehrozKarim:behroz-karim

Conversation

@BehrozKarim
Copy link
Copy Markdown

  • Implemented naive, blocked and parallel matrix multiplication
  • Updated the readme with performance results
  • Added a writeup.pdf explaining the implementation and the optimization journey

naive_matmul: This function is the naive textbook i -> j -> k triple loop with a local sum accumulator.
blocked_matmul: six-loop tile structure with block_size = 32. Inside each tile, inner loops use i -> k -> j instead of the pseudocode's i -> j -> k. This makes the innermost loop access B and C with stride 1, allowing the hardware prefetcher and the compiler's auto-vectorizer to work. std::min(...) handles non-multiple-of-block-size dimensions; C is zero-initialized because each tile accumulates into it.
parallel_matmul: #pragma omp parallel for over the outer i loop. Each thread zeros and then fills a disjoint set of rows of C (so no atomics or reductions are needed), using the same i -> k -> j inner ordering.

We came up with the i->k->j inner ordering trick because we were not achieving any speedups with the pseudocode version of the implementation.

@BehrozKarim BehrozKarim changed the title Optimized Matrix Multiplicagtion and Validation Logic Optimized Matrix Multiplication and Validation Logic May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant