[Solved] ECE39595-Homework 9

$25

File Name: ECE39595-Homework_9.zip
File Size: 178.98 KB

SKU: [Solved] ECE39595-Homework 9 Category: Tag:
5/5 - (1 vote)

In this homework well convert a sequential program to a program that executes items in a work queue in parallel.

What you need to do:

  1. Have the QuickSort function inherit from the Command abstract class, and implement the pure virtual functions declared in Command.
  2. Write a DotProduct class that also inherits from the Command abstract class and implements its pure virtual functions. DotProduct will have two constructors, a zero arg and a constructor that takes an int that is the length of the a and b arrays whose dot product will be taken. DotProduct also needs to implement operator<<(). Ill include sample output that will make it clear what the output should be.
  3. A WorkerQueue class that implements a work queue, where work items are shared_ptr<Command> objects. The queue should be implemented using a C++ std::vector.

In addition to any needed constructors (I used a single zero-arg constructor) you will need to implement a get() function that returns a shared_ptr<Command> of some entry in the queue, and removes that entry from the queue. Removing the entry from the queue should be properly synchronized using a std::mutex and a std::lock_guard.

You will also need to implement a put() function, that takes a std::shared_ptr<Command> as an argument and returns a void, that adds the std::shared_ptr<Command> to the work queue. The add of the shared pointer to the queue should be properly synchronized.

  1. In the file main.cpp, the worker function should be uncommented and the write that is done with identify( ) should be called. You should hold a lock different than the lock used for WorkQueue when calling identify so that there is not a race on std::ostream.

In the main function, we will time the time it takes to

  1. add eight std::shared_ptr<Command> objects to the work queue. Four will point to dot products and four will point to quick sorts.
  2. Start four threads that run the worker function, passing your work queue as an argument.
  3. Wait until all four threads have finished.
  1. Print out the execution time, the number of threads, etc., as shown in the sample output.

When compiling, use the -pthread option at the end of your list of files or you will get linker errors. You will need the following include files: <vector> for std:vector, <chrono> for timing (you will also need to put using namespace std:chrono after the includes and any defines in your main.cpp file), <memory> for std::share_ptr, <mutex> for locks, plus the normal stuff.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] ECE39595-Homework 9
$25