Parallel Matrix Multiplier
Objective
The purpose of this assignment is to implement a multi-threaded C program that uses a shared bounded buffer to coordinate the production of NxN matrices for consumption in matrix multiplication. For two matrices M1 and M2 to be multiplied, the number of columns of M1 must equal the number of rows of M2. The program will perform parallel work using multiple threads to: (1) produce NxN matrices and place them into a shared buffer, and (2) consume NxN matrices from the bounder buffer for pairing with another matrix for matrix multiplication having a valid number of rows and columns. Matrices consumed from the bounded buffer with an invalid number of elements for multiplication are discarded and the buffer is queried again to obtain a new candidate matrix for multiplication.
Starter code (pcmultiply.tar.gz in Canvas) is provided to help jumpstart implementing the parallel matrix multiplier with the synchronized bounded buffer. The goal of the project is to focus on synchronization and pthreads, not implementing matrix functions and operations as this code is already provided.
Producer algorithm:
One or more producer threads work together to produce “LOOPS” (defined in pcmatrix.h) # of matrices and place them in the shared bounded buffer. The producer should call Matrix * GenMatrixRandom() (refer to matrix.h and matrix.c) to generate a NxN matrix where the number of rows and columns is random between 1 and 4.
Consumer algorithm:
One or more consumer threads work together to perform matrix multiplication. Each consumer thread gets a matrix from the bounded buffer (M1). Then the consumer thread gets a second matrix from the bounded buffer (M2). Calling the matrix.c routine Matrix * MatrixMultiply(Matrix * m1, Matrix * m2) will return a pointer with a result of the matrix multiplication (M3), or a NULL if matrix multiplication fails due to a mismatch of the number of elements. If a NULL is received, then the consumer thread
discards the matrix and memory is free’d by calling void FreeMatrix(Matrix * mat) (refer to matrix.h and
matrix.c). The consumer thread then grabs the next available matrix from the bounded buffer as M2. When a valid matrix M2 is found that pairs with M1, the matrix multiplication operation is performed and the result in M3 is printed using the void DisplayMatrix(Matrix * mat, FILE *stream) routine (refer to matrix.h and matrix.c).
Starter Code:
The following modules are provided:
Module |
Header file |
Source file |
Description |
Counter |
counter.h |
counter.c |
Synchronized counter data structure |
Matrix |
matrix.h |
matrix.c |
Matrix helper routines |
Prodcons |
prodcons.h |
prodcons.c |
Producer Consumer worker thread module |
Pcmatrix |
pcmatrix.h |
pcmatrix.c |
Program main module with int main() |
A Makefile is provided to compile the modules into a pcMatrix binary.
An initial demonstration of the random matrix generation routine, matrix multiplication, and matrix display is provided in pcmatrix.c int main(). The matrix multiplication output format should be followed for the actual program implementation.
The following constant parameters and global values are defined in h: DEFAULTS
NUMWORK |
DEFAULT number of producer and consumer worker threads. |
OUTPUT |
Integer true (1) / false (0) to enable or disable debug output. See matrix.c for example use of #if OUTPUT / #endif. |
MAX |
DEFAULT size of the bounded buffer defined as an array of Matrix struct ptrs. |
LOOPS |
DEFAULT number of matrices to produce/consume. |
DEFAULT_MATRIX_MODE |
DEFAULT type of matrices to produce |
GLOBALS
BOUNDED_BUFFER_SIZE |
Global variable defining the bounded buffer size. |
NUMBER_OF_MATRICIES |
Globalvariabledefiningthenumberofmatricestoproduce/consume. |
MATRIX_MODE |
Defines the type of matrices to produce. (0=random, 1-n=fixed row/col) |
Note that the number of worker threads is handled using a local variable called numw in pcmatrix.c.
Code is included in pcmatrix.c to load command line arguments into the global variables for the user. Dynamically sizing the bounded buffer is already done. The matrix_mode is also already implemented in matrix.c. If no command line arguments are provided, the default values are used. A message is displayed indicating the parameterization:
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme