GRIFFITH COLLEGE DUBLIN
QUALITY AND QUALIFICATIONS IRELAND
EXAMINATION
POSTGRADUATE DIPLOMA IN SCIENCE IN BIG DATA MANAGEMENT
AND ANALYTICS
PARALLEL AND DISTRIBUTED PROGRAMMING
Module Code: PGDBD-PDP
POSTGRADUATE DIPLOMA IN SCIENCE IN COMPUTING
PARALLEL AND DISTRIBUTED PROGRAMMING
Module code: PGDC-PDP
MASTER OF SCIENCE IN BIG DATA MANAGEMENT AND ANALYTICS
PARALLEL AND DISTRIBUTED PROGRAMMING
Module code: MSCBD-PDP
MASTER OF SCIENCE IN COMPUTING
PARALLEL AND DISTRIBUTED PROGRAMMING
Module code: MSCC-PDP
Lecturer(s): Osama Abushama
External Examiner(s): Dr Mubashir Husain Rehmani
Dr Joseph Rafferty
Date: 26th May 2023 Time: 2.15-5.15
THIS PAPER CONSISTS OF FIVE QUESTIONS
FOUR QUESTIONS TO BE ATTEMPTED
ALL QUESTIONS CARRY EQUAL MARKS
Page 1 of 4
QUESTION 1
Write using parallel programming models a C program for a system that consist of N MPI processes:
each machine should generate a random array size M and compute average, then send the average to
MPI process 0, where all averages are summed up. You must write a program that uses MPI API calls
to achieve this task.
(a) Write the C MPI code.
(15 marks)
(b) Write a C OpenMP version.
(10 marks)
Total (25 marks)
QUESTION 2
Consider the class Delivery.
class Delivery {
private int[] box;
public Delivery(int n) {
box = new int[n];
for (int i = 0; i < n; i++) {
box[i] = 0;
}
}
public void deliver(int parcels, int i) {
box[i] = box[i] + parcels;
}
public int empty(int i) {
int res = box[i];
box[i] = 0;
return res;
}
}
This implements a sequence of message boxes. Delivery men can add a number of parcels to a box.
The owner of the box can empty the box. For simplicity, we only record the number of items in
each box.
(a) Make a thread safe version of class Delivery in such a way that delivery men that want to
deliver parcels in disjoint boxes simultaneously do not block each other.
(5 marks)
(b) Suppose we want to add a transfer function, which transfer parcels from one box to another.
Discuss what the main concurrency-related risk is, when adding this to your thread safe
version, and how this risk can be avoided.
(10 marks)
(c) Give a thread safe lock-free version of Delivery.
(10 marks)
Total (25 marks)
Page 2 of 4
QUESTION 3
(a) Consider the following fragment of a light handling system.
// nrLights is length of lights array
// length of init is the same as length of lights
# pragma omp parallel for shared (lights, init, MAX, DIMMODE) private (i)
for (i = 1; i < nrLights; ++i) {
lights[i] = init[i];
if (lights[i] < lights[i - 1])
lights[i] = lights[i - 1];
}
}
Describe what will be the effect of the OpenMP pragma on the behaviour of this fragment.
(5 marks)
(b) Suppose we transform the following program fragment:
[Link]();
try {
x = 3;
y = 4;
}
finally {
[Link]();
}
into the following program fragment
[Link]();
try {
y = 4;
}
finally {
[Link]();
}
x = 3;
Suppose this is used in a context with other threads that need up-to-date values of variables x
and y. Explain whether this program transformation is okay. Motivate your answer.
(5 marks)
Page 3 of 4
(c) Suppose we have the following two threads (where initially x, y and z are equal to 0 and t is
a lock):
// Thread 1 // Thread 2
z = 3; [Link]();
y = (z + 3); r1 = z;
[Link](); x = 64;
r2 = x; [Link]();
x = 32;
[Link]();
What are the possible final values of r1 and r2. Use the notions of program order and
synchronization order to explain your answer.
(10 marks)
(d) Give a realistic example how careless use of the two locks could lead to a deadlock.
(5 marks)
Total (25 marks)
QUESTION 4
(a) Explain what is the difference between MPI_send and MPI_Ssend?
(10 marks)
(b) What does OpenMP collapse perform?
(5 marks)
(c) Explain how fork-join pool works and what does work stealing mean?
(10 marks)
Total (25 marks)
QUESTION 5
Write a Java class for general system using ReentrantLock with one condition. The system has a
maximum capacity of N spaces. The system must have two methods, a method to take a resource and
method to return a resource. You can call them take and return, assume the content of the system is
integers.
(a) Write the code for the take method.
(10 marks)
(b) Write the code for the return method.
(10 marks)
(c) How can you achieve a similar system with minimal code? No code needed, explain only.
(5 marks)
Total (25 marks)
Page 4 of 4