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

  That reads ten numbers from input and prints

Write a C program that reads ten numbers from input and prints them in reverse order. We assume that the data consists of integers. The program should conform to the following format

  Write programme that allows a user to enter distinct words

Write a programme that allows a user to enter three distinct words and returns them as a single string

  Coinflip to prompt for and input a number

Write a program and name it CoinFlip to prompt for and input a number of times to flip a coin, then to output the number of "heads" and the number of "tails" that were flipped.

  Program on basic arithmetic operation

Two integers must be compared before the arithmetic operation and Subtract the two integers provided the first integer is greater than the second integer, otherwise add the two integers and subtract the second integer from the first integer.

  Write a recursive function squares

Write a recursive function squares that takes a list of numbers, and returns a new list of the squares of those numbers.

  Two types of sporting teams

Select two types of sporting teams and de?ne subclasses for them. These classes shouldinherit from a base team class such as that created in Exercise 1. Include uniquecharacteristics about the sport.

  Design a class box that defines a box on a floor

Design a class box that defines a box on a floor. A box has a number and an (a,b) location where a and b are numbers between -5, and 5.

  Write a program that will read in number of 2 point basket

Write a program that will read in the number of 2 point baskets and the number of 3 point baskets a player makes.  Print the number of each baskets and the total number of points scored.

  Generate mathematical problems based on the difficulty level

Generate mathematical problems based on the difficulty level selected. You must implement the following five levels of difficulty

  Program that takes a number between

Write a program that takes a number between -121 and 121 and output that number in the format of power of 3 (1,3,9,27)example:13 = 9+3+1

  Prepare a c program using the fork() system call

Perform required error checking to ensure that a positive integer is passed on the command line - Prepare a C program using the fork() system call that generates this sequence in the child process. The starting number will be provided from the comm..

  Objective1 to give students practice in calling and writing

objective1. to give students practice in calling and writing their own functions.2. to give students practice in

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