Faculty of Science and Technology EXAMINATION QUESTION PAPER Exam in: INF-2202 Concurrent and Data-Intensive Programming Date: 2017-02-20 Time: 09:00 - 13:00 Place: Teo-H3, 3.416 Approved aids: None Type of sheets (squares/lines): Lines Number of pages incl. cover page: 3 Contact person during the exam: John Markus Bjørndalen Phone: 90148307 NB! It is not allowed to submit scratch paper along with the answer sheets. If you do submit scratch paper, it will not be evaluated. UiT / Postboks 6050 Langnes, N-9037 Tromsø / 77 64 40 00 / postmottak@uit.no / uit.no Question 1 - Concurrent linked list (40%) In this question you will implement a concurrent singly linked data structure. The list should be ordered by an integer key value. You can use either Python, Go or pseudo code. a) Coarse-grained synchronisation Implement the add and remove function for a singly linked list using coarse-grained synchronisation. We are interested in a simple solution that is thread safe. b) Starvation What is starvation? Can starvation be a problem for your coarse-grained synchronisation implementation in a)? c) Contention An issue with coarse-grained synchronisation is contention. What is contention? Why can we experience contention in systems? d) Fine-grained synchronisation Re-implement the add and remove functions using fine-grained synchronisation. We are interested in a solution where individual nodes in the list can be locked. Question 2 - Spark (20%) a) Advantages What is spark? Why is spark well suited for data-intensive computing? b) RDD What is an RDD in Spark? How are they instantiated? c) Map One of the transformations on RDDs provided by Spark is map. Explain how map transforms RDDs. How does map transformations simplify concurrent programming? Question 3 - Sieve of Eratosthenes (30%) The Sieve of Eratosthenes is an ancient Greek method for finding prime numbers. We start by writing a list of numbers, starting with the smallest known prime number, 2. Then we cross out all numbers that are divisible by 2: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 .. The next number that is not crossed out (3) is the next prime number. We then cross out all numbers divisible by 3 (several will already have been crossed out as they are divisible by both 2 and 3). 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 .. We then continue the method as follows: • Scan for the next non-crossed number to find the next prime. UiT / Postboks 6050 Langnes, N-9037 Tromsø / 77 64 40 00 / postmottak@uit.no / uit.no 2/ 3 • Cross out all number divisible by the newly found prime. One way of implementing this in Go is to use a pipeline of goroutines, where the first goroutine sends a sequence of numbers to the next. The first goroutine is a number generator, which is analogous with creating the list above. The next goroutines in the list use the following algorithm: • Receive a number from the left goroutine and print it. This is the prime number kept by this goroutine. • while true do: – receive a number from the left. – if it is divisible by the goroutine’s prime number, drop it – if it is not divisible by the goroutine’s prime number, pass it it on to the next goroutine on the right Prime filter Drop 4,6,8,10.... Keep/print 3 Prime filter Send 5,7,11,13,.... Keep/print 2 Send 3,5,7,9,11,.... Number gen Send 2,3,4,5,6,7,.... Each goroutine in the pipeline is a filter, removing numbers that are known, at that stage, not to be prime numbers and passing on numbers that might be prime numbers. The following is an illustration: Drop 9,15,21.... a) Go In Go, what is a goroutine? What is a channel? b) Implementation Implement the Sieve of Eratosthenes in Go. c) Load balancing Load balancing involves trying to share workload between, for instance, processes or processors in a system to make sure we don’t have idle resources while other resources are busy with large workloads. Is the workload balanced between the filter processes in our program? Why? Hint: focus on the first and last few processes of the pipeline. Question 4 - Terms (10%) Give a short description of the following terms: a) What is concurrency? b) What is deadlock? c) What is a critical section? UiT / Postboks 6050 Langnes, N-9037 Tromsø / 77 64 40 00 / postmottak@uit.no / uit.no 3/ 3
© Copyright 2025 Paperzz