logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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:

 

  1. 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:

(5/5)
Attachments:

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

858 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

956 Answers

Hire Me
expert
Husnain SaeedComputer science

507 Answers

Hire Me
expert
Atharva PatilComputer science

653 Answers

Hire Me
June
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30