DAA Mini Project
DAA Mini Project
MINI PROJECT
Title: Write a Program to Implement Matrix Multiplication. Also Implement Multithreaded
Matrix Multiplication with Either One Thread per Row or One Thread per Cell. Analyze and
Compare Their Performance.
Abstract:
This document presents a program that demonstrates matrix multiplication using both single-
threaded and multithreaded approaches. The performance of both methods is analyzed and
compared based on execution time. The multithreaded approach leverages the capabilities of
modern processors by distributing the workload across multiple threads, thus potentially
reducing computation time. The study highlights the efficiency of multithreading in matrix
operations, providing insights into performance optimization techniques.
Introduction:
Objectives:
System Requirements:
Conclusion:
The program successfully demonstrates matrix multiplication using both single-threaded and
multithreaded approaches. The results indicate that while the single-threaded approach is
straightforward, the multithreaded approach can lead to performance improvements, particularly
in larger matrices. However, for smaller matrices, the overhead of thread creation may negate
these benefits. This exploration highlights the importance of choosing the appropriate method
based on matrix size and system architecture, emphasizing the value of multithreading in
enhancing computational efficiency.
# DAA MINI PROJECT (Multithreaded Matrix Multiplication: A Comparative
Performance Analysis)
#include <iostream>
#include <pthread.h>
#include <cstdlib>
#include <chrono>
int matA[MAX][MAX];
int matB[MAX][MAX];
int matC[MAX][MAX];
int step_i = 0;
int main()
{
// Generating random values in matA and matB
for (int i = 0; i < MAX; i++)
{
for (int j = 0; j < MAX; j++)
{
matA[i][j] = rand() % 10;
matB[i][j] = rand() % 10;
}
}
// Reset matC
fill(&matC[0][0], &matC[0][0] + sizeof(matC) / sizeof(matC[0][0]),0);
// Declaring four threads for multithreading
pthread_t threads[MAX_THREAD];
return 0;
}