Moh'd Abu Quttain: Implemented optimized matrix multiplication#30
Open
MohdFawaz wants to merge 5 commits into
Open
Moh'd Abu Quttain: Implemented optimized matrix multiplication#30MohdFawaz wants to merge 5 commits into
MohdFawaz wants to merge 5 commits into
Conversation
… batch of solution files)
…d batch of solution files)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For more explanation, kindly refer to the first comment section in main.cpp, and also in the readme file under tables.
I implemented three versions of the multiply:
-Naive triple‐loop for a correctness baseline.
-Cache‐blocked (B=16) to improve data locality by working on 16×16 tiles; this gave a modest ~1.05–1.10× speedup on large matrices.
-OpenMP‐parallel naive loops with #pragma omp parallel for collapse(2) and OMP_NUM_THREADS=8, yielding ~4.7–5.2× speedup on my M1 Air.
Challenges I faced included:
OpenMP support on macOS: AppleClang doesn’t ship with OpenMP, so I had to switch to Homebrew’s GCC/G++.
Block‐size tuning: too large or small blocks can regress performance; I found B=16 best for example on the triple loop 256³ in case 6 on my cache hierarchy.
Limited blocking gain: aggressive hardware prefetch and large caches on M1 reduce the benefit of tiling for medium‐sized problems.
When I scaled up to 8 threads on my M1 Air, I ran into a few limits:
Heterogeneous cores: the M1 has 4 “performance” and 4 “efficiency” cores. With OMP_NUM_THREADS=8, half my threads land on slower Icestorm cores, so I only saw ~4–5× instead of 8×.
OpenMP overhead: spawning/joining 8 threads and managing schedules adds non-trivial overhead, especially on small tiles.
To go around this, I used collapse(2) with schedule(static) to balance work evenly, and pinned the thread count to exactly 8 to avoid oversubscription and running overhead.