0% found this document useful (0 votes)
5 views2 pages

Computing Lab Lab Test 2

The document outlines the instructions for Computing Lab Test 2, which consists of three questions with a total of 85 marks. Question 1 requires writing a ticket booking system in C or C++ using threads and semaphores, Question 2 involves implementing a naive matrix multiplication algorithm, and Question 3 consists of various shell scripting tasks. Each question includes specific submission requirements and guidelines for file naming.

Uploaded by

cogod1511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Computing Lab Lab Test 2

The document outlines the instructions for Computing Lab Test 2, which consists of three questions with a total of 85 marks. Question 1 requires writing a ticket booking system in C or C++ using threads and semaphores, Question 2 involves implementing a naive matrix multiplication algorithm, and Question 3 consists of various shell scripting tasks. Each question includes specific submission requirements and guidelines for file naming.

Uploaded by

cogod1511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Autumn 2024

Computing Lab Test 2 Full Marks: 85 Time: 160 mins

Submission instructions:
Please upload a zip file with the name <rollno>_computing-lab-test2.zip
containing all the relevant files with correct names (specific filenames are
mentioned in each question)
_____________________________________________________________________________________________________

Question 1 [35 marks]


Write C or CPP code (mentioned clearly) to simulate a ticket booking system. The code should take
three arguments, N, V, C. There are N number of tickets in a train and V number of VIP threads and
C number of Common Person (CP) threads. Check N > V+C > C > V, otherwise exit. Next, your code
should spawn V number of VIP threads and C number of CP threads. Each thread will have a request
data structure, which contains (among other things) the number of tickets they need. VIP threads
can need 1 to 5 tickets (randomly chosen) and CP threads can need 1 to 2 tickets (randomly
chosen). After creation, each thread will sleep up to 20 seconds (randomly chosen) and then go for
booking tickets.

Simulate three booking counters using semaphore. Once a thread gets hold of a booking counter,
it will book the number of tickets requested (if a CP thread wants more than 2 tickets give at max
2 tickets, if a VIP thread want more than 5 tickets, give at max 5 tickets) or failing that (if there are
not enough tickets) book the tickets available, then the thread will exit. If a VIP thread is waiting at
a booking counter it will get priority over all waiting CP threads. After booking tickets a thread will
exit. Once all threads exit, output the following in the main thread and exit: “VIP threads booked
XXX tickets in YYY time” and “CP threads booked XXX tickets in YYY time”. XXX is the total number
of tickets booked and YYY is the total time taken from start to finish of each thread.

Your submission should contain <rollno>_Q1.c / <rollno>_Q1.cpp, <rollno>_READMEQ1


(containing running instructions and any design decision you have made)

Question 2 (25 marks)


Write a program for matrix-multiplication. Let A and B be two input matrices of sizes !" ∗ %"
and !& ∗ %& respectively, where %" = !& . You will be implementing the naïve matrix
multiplication algorithm, where each element of the result matrix C of size !" ∗ %& can be
computed independently from one another. The overall scheme for implementation is:
• Create a function void *mult(void *arg): which multiplies a row of matrix A with a
column of matrix B, and stores the result in the appropriate cell of preallocated
matrix C, all in shared memory.
• The argument arg is a structure of type ProcessData, which stores the input and output
parameters for the function shown below. Note that the actual matrix data is stored in
the shared memory and is accessible to all.
• In the main program, create child processes to compute all the elements of the matrix C.

The structure for passing parameters can be:


// compute A[i,:] * B[:,j] and store in C[i,j]
typedef struct _process_data {

double **A;
double **B;
double **C;
int veclen, i, j;
} ProcessData;
// veclen: () /+,
// i, j: cell to compute
In this part you should simply create !" ∗ %& child processes each for computing each element.
Note that no mutual exclusion is needed as all the output entries are created independently and
all the inputs are already available.

Your submission should contain <rollno>_Q2.c / <rollno>_Q2.ccp, <rollno>_READMEQ2


(containing running instructions and any design decision you have made)

Question 3 (5 + 5 + 5 + 10 = 25 marks)

3.1. Write a shell code segment which can read strings like “2 x 3” as argument and output the
multiplication of those two numbers (e.g., 2 and 3) in the terminal. Write your code in
“<rollno>_Q3.1.bash” file.

3.2. You have three files 1.txt, 2.txt, 3.txt. Each file contains three space separated columns and
each column contains non-negative numbers. Write a shell code segment to compute and print
the average and standard deviation of each of these columns over all the files. Write your code in
“<rollno>_Q3.2.bash” file.

3.3. Assume you have a file where one string (without space) is contained in each line of the file.
Each string is “Peter”, “Paul” or “Mary”. Write a shell code segment to compute the frequency of
occurrences for the strings “Peter”, “Paul” and “Mary”. Write your code in “<rollno>_Q3.3.bash”
file.

3.4. Write a C/C++ code which when you press ctrl+c once, goes to sleep and when you press
ctrl +c again , wakes up and waits for next ctrl +c. The “sigsuspend” call might be useful.
Write your code in “<rollno>_Q3.4.c” or “<rollno>_Q3.2.cpp” fille.

You might also like