Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code: 1. Goal of this programming assignment The primary goal of this assignment is to understand and gain some familiarity with pthread libraries in

C++ code:

1. Goal of this programming assignment The primary goal of this assignment is to understand and gain some familiarity with pthread libraries in Linix Environment.

2. Requirements (1) Programming language: You have to use either C or C++ to develop your program.

3. Description of programming Write a C/C++ language program to implement multithreaded matrix multiplication using Pthreads.

- Create a separate worker thread to compute each row of the result matrix, instead of a thread for each element.

Do not initialize the contents of the A and B matrices statically. The A and B matrices will be initialized by reading data from an input file (see notes below).

Be able to process multiple sets of input matrices by continuing to read data in the specified format (described below). If any other character than an integer including negative number is specified, output an error message and terminate the program with a non-zero return code.

Each set of data processed must be labeled to indicate which set of data is being output (e.g., Matrix A, Matrix B, etc).

Maximum size of Matrices can be 10000x10000

3.1 Input The input file will be an ASCII file containing numbers that define the dimensions and contents of the A and B matrices for which a matrix product is to be computed. The first line of the input file will contain two numbers specifying the dimensions of the A matrix (M x K). Following that will be M lines, each with K numbers, representing the elements of matrix A. Next will be a line with two numbers specifying the dimensions of the B matrix (K x N). And following that will be K lines, each with N numbers, representing the elements of matrix B. For example, suppose that matrix A has 4 rows and 3 columns and matrix B has 3 rows and 4 columns, as follows:

The lines in the input file would be as follows:

4 3

2 1 3

0 -1 -2

5 1 -1

4 5 8

3 4

3 2 1

0 0 4

2 -1 -1

3 2 4

3.2 Output Program should print the contents of matrix A and matrix B. It should then print lines showing the thread ID numbers for the worker threads it creates. Then it should print the contents of the result matrix C and total execution time. The output from program for the above input should look similar to the following:

Matrix A: 2 1 3

0 -1 -2

5 1 -1

4 5 8

Matrix B: 3 2 1

0 0 4

2 -1 -1

3 2 4

Created worker thread 15823744 for row 0 Created worker thread 26375040 for row 1 Created worker thread 35823744 for row 2 Created worker thread 46375040 for row 3

Matrix C = A x B: 3 17 10 11

2 -10 -6 -7

16 11 5 -5

4 52 30 27

Total execution time using 5 threads is 0.001 ms

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions