Assignment 1: Parallel Matrix Addition Using OpenMP
Objective
The objective of this assignment is to implement a parallel program for matrix addition
using OpenMP. This exercise will enhance your understanding of parallel computing
and the use of OpenMP for performance optimization.
Instructions
1. Setup: Ensure you have a C/C++ compiler with OpenMP support (e.g., GCC).
2. Task:
o Write a program that adds two N×N matrices and stores the result in a
third matrix. The size N should be defined by the user.
3. Requirements:
o Initialize two matrices, A and B, with random integers.
o Implement a function to add the matrices and store the result in a third
matrix C.
o Use OpenMP to parallelize the matrix addition operation.
Steps to Complete the Assignment
1. Matrix Initialization:
o Create two N×N matrices, A and B.
o Fill matrices A and B with random integers.
2. Matrix Addition:
o Write a function to perform the addition of matrices A and B, storing the
result in matrix C.
3. Parallelize the Addition:
o Use OpenMP directives to parallelize the loop responsible for matrix
addition.
4. Output:
o Print the resulting matrix C (optional: print only a portion for large
matrices).
o Experiment with different matrix sizes by modifying N to observe
performance improvements.
o Modify the code to utilize various OpenMP constructs
Submission Requirements
• Submit your source code with appropriate comments explaining your
implementation.
• Include a short report (1-2 pages) discussing:
o Your approach to parallelization.
o Any challenges you faced during implementation.
o Performance comparison between the sequential and parallel version
with different N values, (use omp_get_wtime() to measure execution
time).
Deadline
• [Saturday, November 2 ]