Multi-threading and Thread Synchronization
Question 1: Processing Scheduling using multi-threading – (15 marks)
The amount of time taken to run multiple processes may be reduced by using several Central Processing Units (CPUs) cores in parallel. The diagram below (Figure 1) shows seven processes and the dependencies between them. Each process takes a total of 20 seconds to run, therefore when run in sequence on one CPU core the time taken to run all processes is 7 x20 = 140seconds.
The table below shows the scheduling of the processes when using a single CPU core.
Time |
20s |
40s |
60s |
80s |
100s |
120s |
140s |
CPU1 |
P1 |
P2 |
P3 |
P4 |
P5 |
P6 |
P7 |
- Please complete the following table showing the most efficient scheduling for 2 CPU cores. Remember to consider the dependencies between the processes shown in Figure1.
Time |
20 |
40 |
60 |
80 |
100 |
120 |
140 |
CPU1 |
P1 |
P2 |
P4 |
|
P7 |
|
|
CPU2 |
|
P3 |
P5 |
P6 |
|
|
|
- Please complete the following table showing the most efficient scheduling for 4 CPU cores. Remember to consider the dependencies between the processes shown in Figure1.
Time |
CPU1 |
CPU2 |
CPU3 |
CPU4 |
- Please describe the importance of dependencies in the scheduling of parallel processes
Question 2: Synchronizing Threads – (15 marks)
Synchronization of threads is important to prevent corruption of outputs and shared data in programs. The section of code shown in Column 1 of Figure 2 produces an output using two threads that executed asynchronously.
a) Fill up the column 2 of Figure 2 with the output you expect the code will produce?
Column 1: Code |
Column 2: Output |
class Program { public static void Main(string[] args) { PrintNum p = new PrintNum(); Thread t1 = new Thread(new ThreadStart(p.DisplayN)); Thread t2 = new Thread(new ThreadStart(p.DisplayN)); t1.Start(); t2.Start(); } }
class PrintNum { public void DisplayN () { for (int count = 1; count<= 100; count++) { Thread.Sleep(1000); Console.WriteLine(count); } } } |
|
Figure 2 Code - Synchronization of Threads
b) Please show how the code in Column 1 of Figure 2 can be modified to producethe output shown in column 2 Figure3.
Column 1: Code |
Column 2:Output |
|
1 2 3 4 5 . . . 100 1 2 3 4 5 . . . 100 |
Figure3- Corresponding Code
Question 1
(a) Describe the notion of shared memory in computer systems, distinguishing between Uniform Memory Access (UMA) and Non-Uniform Memory Access (NUMA) architectures.(5 Marks)
(b) Draw the architecture of parallel shared memory considering both UMA and NUMA cases. (5 Marks)
Question 2:
(a) Briefly explain the Parallel Thread Model and explain the concept of Granularity considering this Model. (5 Marks)
(b) The code given below is an example of Parallel Thread Model. (10 Marks)
C#
using System; using System.Threading;
class Program { static void Main() { // Create and start four threads Thread thread1 = new Thread(new ThreadStart(ThreadMethod)); Thread thread2 = new Thread(new ThreadStart(ThreadMethod)); Thread thread3 = new Thread(new ThreadStart(ThreadMethod)); Thread thread4 = new Thread(new ThreadStart(ThreadMethod));
thread1.Start(); thread2.Start(); thread4.Start();
// Wait for both threads to finish thread2.Join(); thread3.Join(); thread4.Join();
Console.WriteLine("Main thread completed."); }
static void ThreadMethod() // Code to be executed by each thread Console.WriteLine("Thread ID: " + Thread.CurrentThread.ManagedThreadId); } } |
The code works for 4 threads. Rectify the error by typing only the line missing here in this column. |
Question 3:
(a) Find the minimum number using The Task Graph Model. Solve it step by step till the last minimum number is attained.(10 Marks)
(b) Describe the master-slave model in parallel and distributed computing. How does it differ fromfork-join or task-based parallelism?(05 Marks)
Question 4:
Sort the following array using Parallel-Quick Sorting Approach. Show how divide and conquer step followed by merging step have been used. (10 Marks)
75 |
15 |
25 |
60 |
75 |
50 |
26 |
48 |
40 |
55 |
Question 5:
Sort the following array using Bitonic Sorting. Explain in detail every step for this process by visualization. (10 Marks)
1 |
5 |
7 |
2 |
8 |
6 |
2 |
9 |
Question 6:
This question is related to week 4 lecture.
Sort the following array using Parallel-Bucket Sorting. Explain in detail every step for this process by visualization. (10 Marks)
12 |
10 |
22 |
9 |
18 |
20 |
14 |
25 |
13 |
Are you struggling to keep up with the demands of your academic journey? Don't worry, we've got your back!
Exam Question Bank is your trusted partner in achieving academic excellence for all kind of technical and non-technical subjects. Our comprehensive range of academic services is designed to cater to students at every level. Whether you're a high school student, a college undergraduate, or pursuing advanced studies, we have the expertise and resources to support you.
To connect with expert and ask your query click here Exam Question Bank