![]() |
![]() |
|
02158 Concurrent Programming Fall 2024 |
Mandatory Assignment 4: Go Studies |
Home | Plan | Material |
As for CP Lab 4.
In this assignment, you will have use the package/module notion of Go.
Alternatively you may compile the programs using go build <program>.go and run the resulting binary program <program>[.exe] afterwards.
This problem was already given as Exercise B in CP Lab4 to which you are referred.
Download and run the barrier.go program (known from the lectures). Inspect the program code, run it, and make sure you understand all parts.
Now the barrier sync() method should be extended with an integer parameter and an integer result: sync(contrib int) int. The sync() operation should still make the workers meet, but return the sum of the workers' contribution parameter to all workers.
In the main program, each worker should use its number as its contribution. Hence the resulting sum is expected to be 45 (right?), which should be checked by each worker.
Beware that the solution should take fast reentry at the barrier into account and block for reentrance (on another condition queue) while the sum is being distributed. Luckily, you may safely assume that spurious wakeups do not occur in Go.
Hand in the revised program as sum_barrier.go and describe your solution.
Aside: The extended operation mimics the essential workings of the MPI_AllReduce() collective communication operation in MPI (Message Passing Interface).
You are given a professional implementaion of a producer/consumer queue queue.go.
The queue is supposed to work as a work queue on which tasks (here called items) are submitted for execution by a pool of consumer goroutines.
Too avoid flooding, the queue is lossy. It has a limited capacity which, when reached, causes items to be lost when adding items to the queue.
Consider the following questions:
Unzip the file and enter the demo directory. Here execute the command go build queue_demo.go, run the resulting queue_demo[.exe] program a couple of times and explain the resuls.
Aside: The bounded queue studied above is actually a component in the Jaeger distributed tracing system, developed by the Uber company as part of their services.
The actual version provided is a (slightly simplified) commit of of this component as of August 2019.
Since this version, the component has been further developed (and corrected). Especially an operation Resize() to change the capacity of the queue has been added in the latest version.
As seen in Problem 3, the claim that the earliest items are dropped first when the queue capacity is reached is not what is implemented.
In certain contexts, it is desirable to have a queue in which the oldest elements are discarded in case of capacity problems. One example would be a buffer where program trace events are held before being stored in persistent storage. In case of a crash, hopefully the most recent events are intact in the store.
In this problem you should implement a queue with the same operations as in the queue.go, but where the oldest elements are discarded when the queue has reached its capacity. Such a queue is often called an overwriting ring buffer. The ring buffer should be implemented in a file ring_buffer.go defining a package ring_buffer.
The implementation may be based on the given queue.go still internally using a channel for the queue but discarding items from the other end. This could be achieved by letting the Produce() operation "make room for itself" by removing an old item if it finds the the queue to be full.
(Alternatively the ring buffer may be reimplemented by a server using an array to hold elements. For this, you may get inspiration from the blocking bounded buffer shown at the lectures: buffer.go.)
Device a program ring_buffer_demo.go which demontrates that the oldest elements are in fact discarded first.
The assignment should be made in groups of 1-3 students. These may be the (subsets of) the provious groups, new groups or indivituals.
If you want to hand in, you must apply to get registered for a Mandatory 4 group. Please inform the teacher about this, no later than Wednesday November 27.
All groups should do Problem 1. Groups of 2 students are expected to do one of the extra Problems 2, 3, and 4 as well while groups of 3 students must do two of the extra problems.
Of course, each group must work on its own. In particular you must not exchange any form of code or texts with other groups. Any repositories you use, must be private.
Use of generative AI is not recommended, but if you do anyhow, it must be declared (for what and how).
The asssignment must be handed in on DTU Learn no later than
The hand-in should comprise the following:
The report should include
Feedback before the exam will be given only to groups who need approval in order to be admitted to the exam. Feedback to others will be given later.
Assistance for the assignment will be available on November 23, during the lab session as indicated on the course plan.
In case of amendments or updates, these will appear here. Major updates will be announced on DTU Learn.
Hans Henrik Løvengreen, Nov 22, 2024 |