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

  Write a function that compares two stacks for equality

Write a function that compares two stacks for equality. The function takes two stacks as parameters and returns true if they are identical.  The stacks should remain unchanged after the function returns to the calling program.

  Need a prg that lets user enter total rainfal

Need a prg that lets user enter total rainfall for each of 12 months into an array of doubles,prg should then calculate and display total rainfall for year,the average monthly rainfall, and the months with highest and lowest amounts

  Program to translates letter grade into number grade

In C++ (should be able to compile in Visual Studio 2010): Write a program to translates letter grade into number grade. Letter grades are A,B,C,D and F, possibly followed by a + or -.

  Prepare the weighted scoring model for three exams

Prepare the weighted scoring model. Final grades are based on three exams worth 15%, 20%, and 25%, respectively; homework is worth 20%.

  Program should read in the file and place periods

Create a C++ program that will read this file and correct errors in the English syntax of the file. The program should Read in the file and Place periods at the end of all sentences throughout this file

  Program to declare array alpha of components of type int

Write C++ statements to do the following: Declare an array alpha of 15 components of the type int. Output the value of the tenth component of the array alpha.

  Write a program that will input letters grade(a,b,c,d,f)

Write a program that will input letters grade(A,B,C,D,F), the number of which is input by the user (a maximum of 50 grades). The grades will be read into array. A function will be called five times(once for each letter grade) and will return the tota..

  Collection of course components and weighting schemes

Define the data type that represents the collection of course components and weighting schemes and break down the required functionality into modular, reusable functions

  Write a program that calculates an employees wage for a

write a program that calculates an employees wage for a week. an employees wage is calculated as followsi if the number

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Computes the sum and displays it

Prepare a C++ program that asks the user for an integer n and computes the sum 1^2+2^2+3^2+4^2+....+n^2 and displays it in the output screen.

  Numbers until the user wants and in the end display

Write a C program to enter the numbers until the user wants and in the end display the product of numbers entered by the user. The program should terminate once the user enters the character 'n' and continue computing product if user enters 'y'

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