Question: Threads in C++ Code needs to be adjusted. Question is for Java but is implemented in C++. Code has been commented where it needs fixing

Threads in C++

Code needs to be adjusted. Question is for Java but is implemented in C++. Code has been commented where it needs fixing (inside main).

Question:

1. Part A) Partitioning array into fixed chunks.

Evaluate method for a polynomial has been provided here. Using the Polynomial class, you have to use java threads in the Polynomial class such that the polynomial evaluation calculations gets distributed among threads. Look at the vector addition demo using threads to get started. Use it as a template to get started with Multi-threaded Polynomial evaluation.

Answer for java is provided here:

https://www.chegg.com/homework-help/questions-and-answers/5-53-title-polynomial-evaluation-using-java-threads-group-assignment-allowed-submit-group--q39898568?trackid=9b3ea157b3da&strackid=c2eb7050c356

// CPP code to illustrate // Queue in Standard Template Library (STL) #include #include #include #include

#define MAX 50000 #define COEFFICIENT 1

using namespace std;

class Term { public: int coefficient; int degree; Term(int coef, int deg) { coefficient = coef; degree = deg; } };

double power(double x, int degree) { if(degree == 0) return 1; if(degree == 1) return x;

return x * power(x, degree - 1); }

double sequential(int coeffArr[], double x) { int maxDegree = MAX - 1; int i; double answer = 0; for( i = 0; i < maxDegree; i++) { double powerX = power(x, i);

//printf("%f ", powerX); answer = answer + coeffArr[i] * powerX; } return answer; }

// Print the queue void showq(queue gq) { queue g = gq; while (!g.empty()) { Term t = g.front(); cout<

void initialize(int coeffArr[]) { int maxDegree = MAX - 1; int i; for( i = 0; i < maxDegree; i++) { coeffArr[i] = COEFFICIENT; } }

// Driver Code int main() { int coeffArr[MAX]; initialize(coeffArr); double x = 0.99; queue gquiz; Term *t = new Term(3,2); gquiz.push(*t); Term *t1 = new Term(13,12); gquiz.push(*t1); cout << "The queue gquiz is : "; showq(gquiz);

cout << " gquiz.size() : " << gquiz.size();

Term firstTermInQ = gquiz.front(); cout << " gquiz.front() : " << firstTermInQ.coefficient<<" "<

//error is in this block int numThreads; cin>>numThreads; int chunkSize = ceil(MAX/numThreads); thread *threads = new thread[numThreads]; for(int i = 0; i

// printf("Goodbye, World! "); // first.join(); // second.join(); for(int i = 0; i

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!