Programming Assignment 2: ThreadsCSE3320 001/003/900Due: Wednesday March 24nd, 2021 5:30PM CSTDescriptionThe purpose of this project is to practice threaded programming by solving variousproblems. The objectives of this project is to learn:1. Get familiar with threading.2. How to use mutexes, semaphores, and conditional variables in a threading library.3. How to design efficient solutions for mutual exclusion problems.Project submissionFor this assignment, create a gzipped file containing the following items, and submit itthrough Canvas.1. A report that briefly describes how you solved the problems and what you learnedfor each part. For each part of the assignment your report must:1. Explain the problem and identify evaluation metrics for experiments2. Explain your choice of threading libraries3. Explain the design of the experiment and develop programs for evaluation4. Detail your collected experimental results5. Analyze, graph, and interpret experimental results and draw conclusions2. The source code files containing your test cases for parts 1-3.Part 1 (40 pts)Given two character strings s1 and s2. Write a threaded program to find out the numberof substrings, in string s1, that is exactly the same as s2. For example, supposenumber_substring(s1, s2) implements the function, then number_substring(“abcdab”,“ab”) = 2, number_substring(“aaa”, “a”) = 3, number_substring(“abac”, “bc”) = 0. Thesize of s1 and s2 (n1 and n2) as well as their data are input by users. Assume that n1mod NUM_THREADS = 0 and n2 < n1/NUM_THREADS.The provided program is a sequential solution of the problem. read_f() reads the twostrings from a file named “string.txt and num_substring() calculates the number ofsubstrings.You can find the source for this assignment on GitHub at: https://www.github.com/CSE3320/Substring-Assignment .Write a parallel program using a threading library based on this sequential solution.You may use pthreads, C++ threads, Intel TBB, or another threading library. You mustprovide your rationale for choosing the library AND provide instructions for setting upthe VM to use your library if additional libraries need to be installed.HINT: Strings s1 and s2 are stored in a file named “string.txt”. String s1 is evenlypartitioned for NUM_THREADS threads to concurrently search for matching withstring s2. After a thread finishes its work and obtains the number of local matchings,this local number is added into a global variable showing the total number of matchedsubstrings in string s1. Finally this total number is printed out. You can find an exampleof the “string.txt” in the attached source code.Part 2 (35 pts)Use condition variables to implement the producer-consumer algorithm. Assume twothreads: one producer and one consumer. The producer reads characters one by onefrom a string stored in a file named “message.txt”, then writes sequentially thesecharacters into a circular queue. Meanwhile, the consumer reads sequentially from thequeue and prints them in the same order. Assume a buffer (queue) size of 5 characters.Write a threaded program using condition variables.Part 3 (25 pts)Write two micro-benchmarks to quantify the costs of context switch between multipleprocesses and multiple threads. Learn from the lat_ctx benchmark from the lmbenchbenchmark suite about how to measure the context switch cost between multipleprocesses. Understand how this benchmark works and adapt it to write your ownbenchmarks. Configure the number of vCPUs to more than one but run all processes/threads on one vCPU. Vary the number of processes/threads to study if the contextswitch cost varies. Below is a related work on quantifying the cost of context switch.https://www.cs.rochester.edu/~kshen/papers/expcs2007.pdfTips(1) Shutdown your VM and change to VM setting to use 4 vCPUs.(2) Verify that your VM has 4 vCPUs:$ cat /proc/cpuinfoYou should have 4 CPUs (processor: 0-3).AdministrativeThis assignment must be coded in C or C++. Any other language will result in 0 points.You programs will be compiled and graded on a CSE 3320 VM. Please make sure theycompile and run on theVM before submitting them. Your report MUST providecompilation steps.Your program is to be turned in via Canvas. Submission time is determined by theCanvas system time. You may submit your programs as often as you wish. Only yourlast submission will be graded.There are coding resources and working code you may use on Canvas and in the coursegithub repository at: https://github.com/CSE3320/Substring-Assignment . You are freeto use any of that code in your program if needed. You may use no other outside code.You MAY use any threading library available for C or C++/Academic IntegrityThis assignment must be 100% your own work. No code may be copied from friends,previous students, books, web pages, etc. All code submitted is automatically checkedagainst a database of previous semester’s graded assignments, current student’s codeand common web sources. By submitting your code on Canvas you are attesting thatyou have neither given nor received unauthorized assistance on this work. Code that iscopied from an external source or used as inspiration, excluding the course github orCanvas, will result in a 0 for the assignment and referral to the Office of StudentConduct.
- Assignment status: Already Solved By Our Experts
- (USA, AUS, UK & CA PhD. Writers)
- CLICK HERE TO GET A PROFESSIONAL WRITER TO WORK ON THIS PAPER AND OTHER SIMILAR PAPERS, GET A NON PLAGIARIZED PAPER FROM OUR EXPERTS