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
MASTER OF SCIENCE IN BIG DATA MANAGEMENT AND ANALYTICS
PARALLEL AND DISTRIBUTED PROGRAMMING
Module code: MSCBD-PDP
Lecturer(s): Osama Abushama
External Examiner(s): Dr Joseph Rafferty
Date: 17th January 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 3
QUESTION 1
Write a C MPI program where each process declares a variable containing a value equal to its MPI
rank times 100. Then, all processes participate to a collective operation calculating the sum of all
these variables and store the sum in a variable held on MPI process 0, which then prints it.
(a) Write the C MPI code.
(15 marks)
(b) Write a C OpenMP version of the solution.
(10 marks)
Total (25 marks)
QUESTION 2
(a) How threads are implemented in java?
(5 marks)
(b) How can you ensure all threads that started from main must end in order in which they started
and also main should end last?
(5 marks)
(c) What is significance of using the Volatile keyword?
(5 marks)
(d) What is the difference between wait() and sleep()?
(10 marks)
Total (25 marks)
QUESTION 3
For the OpenMP code below, answer the following for part (a) and (b):
int locks[100];
float data[1000000];
#pragma par for
for (i=0; i < 1000000; i++) {
lock(locks[g(i)%100]);
f(data[g(i)]);
unock(locks[g(i)%100]);
}
Assume the function f only accesses its argument, may read, and write it, and does not synchronize
internally.
(a) How many threads can be active at any time?
(5 marks)
(b) Assuming locking is free, is it possible that the loop executes sequentially because of locking?
(5 marks)
Page 2 of 3
(c) For the OpenMP code below, answer the following: Given the loops:
#pragma par for
for (i=0; i < 1000000; i++)
f(data[g(i)]);
}
Assume the function f only accesses its argument, may read and write it, and does not
synchronize internally. What can you say about g that would make this program race free?
(5 marks)
(d) Given the loops below, is the code safe, the code run on four threads, explain
#pragma par for private (t, j)
for (i=0; i < 1000000; i++) {
t = my_thread_id( ) // t is assigned a unique integer thread id
for (j=0; j < 1000000; j++) {
data[j] = t;
}
}
(10 marks)
Total (25 marks)
QUESTION 4
Implement a Java class to control access to a Garden with 2 gates, access to the garden should be
controlled using Semaphores or ReentrantLock, also you need a method to return visitor count in the
garden, you have two conditions to maintain, access to garden only when it is open and if there is a
space for visitors, assume garden can have up to 150 visitor at any time.
(a) Write the control class for accessing, leaving and counting visitors.
(20 marks)
(b) Write the thread class.
(5 marks)
Total (25 marks)
QUESTION 5
Write a Java program to implement a safe Buffer with limited size N using ReentrantLock for
integers.
(a) Write a java class to implement the methos put and get.
(15 marks)
(b) Write a producer and consumer threads to interact with the buffer.
(10 marks)
Total (25 marks)
Page 3 of 3