

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The instructions and problems for homework 1 of the cse 160 course at the university of california, san diego, focusing on thread-based parallelism and performance in java. Students are required to answer specific questions about threads, synchronization, and concurrency, as well as write and test code segments. The document also includes information on getting a cse account and the homework policy.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Thread-based Parallelism and Performance Due April 7, 2005 in Lecture
CSE160 Homework Policy : Cheating WILL be taken seriously. It is not fair to honest students to take cheating lightly, nor is it fair to the cheater to let him/her go on thinking that is a reasonable alternative in life.
Getting a CSE160 Account: You should to this right away, as it may take a little while to get the accounts set up. In order to get accounts on the fwgrid machines visit the following link http://fwgrid.ucsd.edu/register_project.php. Then fill up all the necessary information.
For any other doubts contact [email protected]
Thread-based Parallelism and Performance
Homework Problem 1. Consider the following basic questions about threading and synchronization in Java. Answer each as succinctly as possible. Provide a code segment where requested. It is not a requirement that you run your code for the purpose of the homework, but that is often a good strategy to make sure that you understand things correctly.
1.a. Threads and Parallelism. Are threads the only way to express parallelism/concurrency in Java? (Explain why yes or no)
Write a small section of code that creates a large amount of parallelism (say 100-fold) as quickly as possible.
Explain how long it takes to go from sequential to 100-fold concurrency (in general terms, not exact timings), explain why your method is the fastest.
1.b. Threads and Processor Parallelism. For over twenty years, multithreaded programs have been able to exploit multiple processors in a machine to obtain higher performance (processor parallelism). However, when two threads execute simultaneously (running on two processors), it can be quite different from when they are executed in an interleaved fashion. Write a short program whose purpose it is to detect whether the Java program is being run on a machine with true parallelism. Explain how the program decides whether threads are being run in parallel and announces the result. Partial credit for programs that never announce the wrong answer, but in some cases can’t decide.
1.c. Synchronized Methods. Java uses synchronized methods to control concurrent access to object state. Write a program which defines two classes RightSideUp and UpSideDown to maintain the state of a sailboat. Define operations which update the state of these two objects, appropriately synchronized, to ensure that no one accessing these objects could ever see an inconsistent view (that is both RightSideUp and UpSideDown) in the same state. Beware of deadlock!
Homework Problem 2. There is a single threaded and a double threaded version of the MergeSort algorithm given in the /home/cse160/hw1. The double-threaded version has a bug which prevents it from running properly (you can run it a few times yourself to check it). You are expected to detect the bug and suggest a way to solve it. The student is not expected to hand in the corrected code but the solution description should be detailed enough to suggest a working solution.
Note: To run the programs use java ProgramName DataSize, where DataSize has to be some perfect power of 2.
usage: java SingleThreadedMergeSort 8192 usage: java DoubleThreadedMergeSort 16384
-*-
Homework Problem 3.a. Write a program that launches a given number of threads (T). The program also takes as input an integer value (Max). All the threads then try to increment a common integer object (make sure to ensure that access to this object is synchronized). Each thread is assigned a unique id (generated sequentially). All increments to the Integer’s value are made in steps of 1 and the thread releases the lock on the Integer object after every increment. The thread that makes the increment taking the object’s value to Max is declared the winner.