Dana Vrajitoru
B424/B524 Parallel and Distributed Programming

B424/B524 Homework 2

Due date: Thursday, September 10, 2020.

Ex. 1. Carbonate Account.

Create an account on the Carbonate computing system by going to One.IU, logging in with your usual account, and entering "Create Additional Accounts". In the first item returned by the search, check the Carbonate option and then click "Create" below the list. You will need to check a couple of boxes to agree to cite the system in publications and such.

The account is normally created quickly, and you will get an email when it is available. Then you'll be able to login to it by ssh or sftp with the host name
carbonate.uits.iu.edu

Ex. 2. Philosophers Problem.

Download the following files:
Makefile
main.cc
solution2.cc
solution2.h

These files contain a simulation of the philosophers problem discussed in the lecture for this week and an implementation of the second solution from the slides.

Compile these files with the command make and execute the program with the command phils or ./phils.

Implement your own solution to the problem to reduce the likelihood or even eliminate the famine situation. Modify whichever functions you think appropriate for this, probably starting with the function Philosopher.

Suggestions: for each fork, you can use a variable that keeps track of the philosopher that has used it the last time and try to avoid, if possible, allocating the fork to the same one again. You can also add a counter for each philosopher and allocate the fork in a way that favors the philosopher that has eaten less.

Note. Currently, the eaten and meditated array are not protected by mutexes because each thread only accesses the element at their own index. If that changes in your program, you will needto add some mutexes to protect the access to these arrays too, the way it's done with the forks array. Similarly with other data structures you may add.

Upload to Canvas

Upload the source files you have modified to Canvas, including the header file if more prototypes are added. Add a paragraph in the submission explaining the idea in your solution and how it is supposed to reduce the famine.