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

An implementation of matrix ADT (abstract data type) is given in matrix.c. The API (application programming interface) functions that operates on the matrices are listed in matrix.h. One of the functions,

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Problem 1. Matrix multiplication (50 points)

In this exercise we will continue to work on the matrix ADT.

An implementation of matrix ADT (abstract data type) is given in matrix.c. The API (application programming interface) functions that operates on the matrices are listed in matrix.h. One of the functions,

mulMatrix(), performs matrix multiplication, which is implemented in matrix.c.

In this assignment, we implement mulMatrix thread() in mmul.c, which has the same interface as mulMatrix(),

but performs matrix multiplication with two threads. We only need to change mmul.c.

test-mmul.c is provided to test our implementation. The program takes the following arguments from the

command line: the number of rows in the first matrix, the number of columns in the first matrix, and the

number of columns in the second matrix. Then it fills two matrices with random numbers, and compares

the result of mulMatrix() and mulMatrix thread(). If no argument is specified, the program works on two

matrices of size 6 × 6. In addition, if a command line option -t<n> is present, test-mmul prints the time (in

seconds) spent on matrix multiplications, using the average of <n> calls.

Here are some sample sessions running test-mmul. The first command multiplies a matrix of 1000 by 500

with a matrix of 500 by 800. The resulting matrix is 1000 by 800. The second command also shows the

timing information, the average of calling each multiplication function 3 times. time1 is the average time

on mulMatrix() and time2 is the average time on mulMatrix thread(). The numbers are likely to change

in different runs.

$./test-mmul 1000 500 800

Good work!

$./test-mmul 100 500 300 -t3

Good work!

num_runs=3 time1=0.0652 time2=0.0341 speedup=1.9132

Problem 2. Printing (50 points)

Suppose p printers need to get j print jobs done. The print jobs are already placed in a queue. The starter

code printing.c defines a type job_queue_t for the queue and provides functions to operate on the queue.

A printer performs the following operations in a loop.

  1. Call q_num_jobs() to get the number of remaining jobs in the queue.
  2. If no job is pending, exit from the loop.
  3. Call q fetch job() to get a job from the queue. The function returns an integer indicating how long

the job takes

  1. Use macro print_job() to print. The macro simulates the fact that different print jobs take different

amounts of time to complete.

  1. Keep track the number of jobs the printer has done.

The function printer_single() in the starter code printing.c shows how a single printer completes all

the jobs.

The tasks in this problem are to use threads to simulate the process of multiple printers completing the print

jobs. Each thread is a printer and performs similar operations as printer_single(). Apparently, threads

need to coordinate their operations on the queue, which is shared by all printers. A mutex is defined in the

job_queue_t structure for this purpose.

The program printing takes optional arguments from the command line. An argument can be one of the

following.

• -p <n>. Specify the number of printers. The default value is 2.

• -j <n>. Specify the number of jobs. The default value is 20.

• -d. Call the demo function showing the operations of a single printer and exit.

Checking results. A script check-printing.py is provided to check the output of printing. Below is an

example of how to use check-printing.py.

$./printing -p 5 -j 1000 | python3 ./check-printing.py

If you have made check-printing.py executable by command "chmod +x ./check-printing.py", you can

run it directly.

$./printing -p 5 -j 1000 | ./check-printing.py

Note that it is not guaranteed that a program that passes the check is correct. We should also examine the

output manually sometimes. Some synchronization errors may manifest themselves only for some values of

the parameters. And even for the same parameters, errors may happen non-deterministically due to different

timing and scheduling orders of the threads. You may run the program multiple times even with the same

parameters. For example, the following bash command runs the above example for 10 times. (Yes, it looks

like a loop in C! and it may not work in other shells.)

for ((n=0;n<10;n++)); do ./printing -p 5 -j 1000 | python3 check-printing.py; done

Debugging. gdb supports multithreading. Run your code in gdb until it stops at a breakpoint or appears

to stop making progress. If threads are not making progress, interrupt the execution with Ctrl-C to get to

the gdb prompt. Here are some commonly used thread commands.

• info threads See what threads are running.

• thread n Switch to thread n, where n is a thread number.

• thread apply [threadno] [all] args Apply commands to one or more threads.

(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

798 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

814 Answers

Hire Me
expert
Husnain SaeedComputer science

808 Answers

Hire Me
expert
Atharva PatilComputer science

850 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