A C programming project about matrix multiplication, Strassen’s algorithm, and parallel thinking.
ENGS110: Introduction to Programming
Professor: Narine Hovhannisyan
Students: Gor Hakobyan and Ani Petrossian
Date: 22nd May 2026
This project explores matrix multiplication in C. We compare a regular matrix multiplication algorithm with a monk-based version that uses Strassen’s method for 2x2 block multiplication.
The main idea is simple: instead of one worker doing everything alone, we divide the work between several “monks.” Each monk is responsible for one part of the task, such as generating matrices, splitting matrices, calculating result blocks, or combining the final result.
The program randomly generates 4x4 matrices, multiplies them repeatedly based on user input, and measures the total running time.
Matrix multiplication is used in many areas of computing, including graphics, engineering, data analysis, and machine learning. However, multiplying matrices can become computationally expensive as matrix size grows.
Regular matrix multiplication has a time complexity of:
This means that as matrices become larger, the amount of work grows very quickly. Our project explores whether a different structure, inspired by Strassen’s algorithm and parallel work, can help organize this computation more efficiently.
The regular method uses three nested loops. Each cell in the result matrix is calculated by multiplying one row from the first matrix by one column from the second matrix.
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
result[i][j] = 0;
for (k = 0; k < 4; k++) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
Complexity: O(n³)
The Strassen version splits each 4x4 matrix into four 2x2 blocks. Instead of treating the matrix as one large structure, the code breaks it into smaller pieces.
The result blocks are calculated as:
Theoretical Strassen complexity: O(n²·⁸⁰⁷)
In our project, the monks represent divided tasks in the program. Each monk has one responsibility.
Randomly generates Matrix 1.
Randomly generates Matrix 2.
Splits both matrices into 2x2 blocks.
Calculates R1 = AE + BG.
Calculates R2 = AF + BH.
Calculates R3 = CE + DG.
Calculates R4 = CF + DH.
Combines the four result blocks.
Receives the final 4x4 matrix.
Multiplication 1 completed.| File | Description |
|---|---|
regular_matrix_timer.c |
Regular 4x4 matrix multiplication using the standard triple-loop method. |
monk_strassen_timer.c |
Monk-based matrix multiplication using threads and Strassen-style 2x2 block multiplication. |
README.md |
Explains how to compile, run, and test the project. |
DOCUMENTATION.md |
Explains the project purpose, goals, target audience, theory, and limitations. |
Regular version:
gcc regular_matrix_timer.c -o regular_matrix_timer
Monk-based Strassen version:
gcc monk_strassen_timer.c -o monk_strassen_timer -pthread
In theory, Strassen’s algorithm has better complexity than regular matrix multiplication. However, in our 4x4 matrix tests, the parallelized Strassen version took longer than the regular method.
This means that faster theoretical complexity does not always mean faster performance in small practical tests. The advantages of Strassen’s algorithm are more likely to appear with much larger matrices and a more optimized recursive implementation.
The same problem can be solved in different ways, and each method has advantages and disadvantages.
Dividing work between threads can help, but thread creation and management also take time.
A method that is faster in theory may not be faster for small inputs.