logo Use CA10RAM to get 10%* Discount.
Order Nowlogo

implement a multi-threaded C program that uses a shared bounded buffer to coordinate the production of NxN matrices for consumption in matrix multiplication.C Programming

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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.C Programming

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:

 

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

526 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

972 Answers

Hire Me
expert
Husnain SaeedComputer science

670 Answers

Hire Me
expert
Atharva PatilComputer science

698 Answers

Hire Me