Reference no: EM13760064
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 <stdio.h>
#include <time.h>
#include <stdlib.h>
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();
}
Finally implemented your firewall and vpn solutions
: You have finally implemented your firewall and VPN solutions and are feeling much better about your network's security posture. It is now the end of the fiscal year, and your CISO is looking to you for future budget requirements.
|
Resources required for implementation
: Method of obtaining necessary approval(s) and securing support from your organization's leadership and fellow staff.
|
Wlan it manager for an organization
: Assume you are the IT manager for an organization tasked with evaluating whether or not to deploy internal wireless access for employees.
|
Write a paper on globalization and religious fundamentalism
: Write a paper on Globalization and religious fundamentalism.
|
Write a parallel program with the sequent simulator
: 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 sec..
|
What major attractions are close to where you live
: What major attractions are close to where you live? How have they impacted your local economy? Is shopping considered a tourist activity? If so, what are some famous shopping locations?
|
Managing health care quality
: The main complaint among the patients is the quality of care. Your job is to understand the state of the hospital, create value, increase efficiency, and turn the facility into a local hospital of choice.
|
Should joan s make her own reservations
: In the same magazine they saw an ad for an airline that serves this destination, including Web site information for reservations. Should Joan S make her own reservations or should Joan S seek the help of a travel agency?
|
Find graph theory concepts that correspond to social concept
: Suppose we make a graph in which nodes are people and edges correspond to some form of social interaction, such as "talk to" or "socializes with" Find graph theory concepts that correspond to social concepts such as popularity, cliques, and hermi..
|