Question: C++ code only (please don't do it in C # or Java ) Given the serial code that finds the minimum of an array, convert

C++ code only (please don't do it in C # or Java ) Given the serial code that finds the minimum of an array, convert the code into a parallel program, create at least three threads and use them to find the min of the elements of the array given in the code. Submit your code in C++

Please use these codes:

int a[] = { 4, 3, 1, 6, 8, 9, 100, 23, 13, 44, 14, 67, 89, 34, 23, 69, 100, 65, 32, 33, 4 ,5 ,6 ,18 }; int min = 1000; // adds every item of the array to the sum for (int i = 0; i < 24; i++) { if (min > a[i]) min = a[i]; } cout << min << endl;

#include #include using namespace std;

int anarray[] = { 21, 13, 12, 15, 2, 4, 7, 9, 12, 7 }; int sum = 0; const int p = 2; const int n = 10;

void myThreadMethod(int id) { for (int i = id*(n/p);i<(id + 1)*(n/p); i++) { sum += anarray[i]; } }

int main() {

thread* t[p]; for (int i = 0; i

for (int i = 0; ijoin(); }

cout <<"Result =" << sum<< endl;

}

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!