Write a parallel program with the sequent simulator

Assignment Help C/C++ Programming
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();
}

 

 

Reference no: EM13760064

Questions Cloud

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..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Compute square roots to a desired degree of accuracy

write a program which will compute square roots to a desired degree of accuracy.

  Program that can serve as a simple calculator

Write a program that can serve as a simple calculator. This calculator keeps track of a single number (of type double) that is called result and that starts out as 0.0. Each cycle allows the user to repeatedly add, subtract, multiply, or divide by..

  C -programming in what ways are the

in what ways are the initializationrepetition testand update steps alike for a sentinel-controlled loop and an

  Find the largest element and print out the index and value

Write a function maxv() that returns the largest element of a vector argument. Find the largest element and print out the index and value.

  Static field holds total winnings for all horses in stable

static field holds total winnings for all horses in the stable // total winnings are shown after each horse wins,

  Prepare an arbitrary sinusoidal waveform

Create a program to compute the derivative of an arbitrary input function, with arbitrary duration and arbitrary limits

  Implement the delivery company

Implement the delivery company using the classes given in the class diagram above.

  Evaluate the mathematical constant of p

Write a C++ program to evaluate the mathematical constant of PI - Guess a random number between 0.00 and 1.00 and assign this to x.

  Write a recursive function to draw the pattern

write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the above pattern.

  Give examples of pretest and posttest loops

Give examples of pretest and posttest loops - Discuss the syntax of while, for, and do...while loops. Give examples.

  Write specifications for a method

Write specifications for a method that advances any given date by one day. Include a statement of purpose, pre- and post-conditions, and a description of the parameters.

  Using virtual methods, organize the animals

Using virtual methods, organize the animals in a small zoo, having as guests lions, parrots, alligators, penguins, elephants, cobras, zebras, hawks, turkeys and rabbits.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd