Complete the following program to write a parallel program


Complete the following program to write a parallel program with the Sequent Simulator for the following task: Hire two processors. One processor searches the first half of a array and finds the largest number. The second processor searches the second half of the array and finds the largest number. The function: main compares these two numbers and displays the largest one.

Note: Do not copy the simulator. Just copy from the comment I have (//Write your complete program (including the header files) below this line. Assume there is nothing above this line.) the parts you write.
Note: For your help I included code sequential programming to find the largest number.
#include
#include
#include

int macs[2];
int *a, *b, *max;
/*
Use variable a to allocate an array of size n in shared memory. Use variable max to create an array of size 2 in shared memory to store the largest number of the first and second half of the array.

I used variables b and macs for to find the largest numbers of the first and second half of the array sequentially.
*/

void sequentialFindBiggest(int n){
int from, to, i;

from = 0;
to = n/2;
macs[0] = b[from];
for(i = from + 1; i <= to; i++)
if(macs[0] < b[i])
macs[0] = b[i];
from = n/2 + 1;
to = n - 1;
macs[1] = b[from];
for(i = from + 1; i <= to; i++)
if(macs[1] < b[i])
macs[1] = b[i];
}


void parallelFindBiggest(int n){
int from, to, i;
/* Complete this function.
This function is implemented by two processors. One has id zero and the other id one. The one with id zero finds the largest number of the first half of the array and stores in max[0]. The one with id one finds the largest number in the 2nd half of the array and stores in max[1].
*/
}


void main(){
time_t s;
int i, n;

time(&s);
srand((unsigned int) s);
n = rand()%100 + 10;
printf("n = %d\n", n);
b = (int *)malloc(n * sizeof(int));
for(i = 0; i < n; i++){
b[i] = rand()%1000;
printf("%d, ", b[i]);
}
sequentialFindBiggest(n);
if(macs[0] > macs[1])
printf("\nThe biggest number is: %d\n", macs[0]);
else
printf("\nThe biggest number is: %d\n", macs[1]);

initialize();
/* Complete this part.
You need to allocate n locations in the shared memory for array: a. You also need to allocate two locations in the shared memory for array: max. Now write a for-loop to assign a[i] = b[i] for i from zero to n - 1.
Next hire two processes, pass the name parallelFindBiggest and n to function m_fork.
Next terminate (kill) these two processes.
Then use and if-else to display the largest number of array: max.
*/
clean();
}

 

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Complete the following program to write a parallel program
Reference No:- TGS01030153

Expected delivery within 24 Hours