Define an array of size 1000

Assignment Help Basic Computer Science
Reference no: EM131030914

Write a parallel program with MPI functions to do the following:

1) Define an array of size 1000.

2) Generate a random integer in the range of: 0 t0 999 for: n.

3) Generate n random integers in the range of: 0 to 1000 and save them in array.

4) For m (its value comes from the keyboard) processes divide that array to (m-1) segments. All the segments except the last one must be equal (Note that the last segment may get bigger than other segments)

5) Each of process p1, p2, p3,..., pm-1 obtains the biggest number from its segment and send it to the process with rank = 0.

6) Process 0 receives a number from each process: p1, p2, p3,..., pm-1, finds the biggest number and print it.

Note: If m -1 is bigger n terminate the execution of the program with an appropriate message the shows the value of m-1 and n.

The following is a serial program. It may help.

Note: Remember the variable comm_sz in the parallel program must not get its value in the program or via scanf.

//File name: a.c

#include
#include
#include
#define atmost 1000
int find(int* a, int from, int to){
int i, b;
printf("%d----%d\n", from,to);
b = a[from];
for(i = from + 1; i
if(a[i] > b)
b = a[i];
return b;
}

int main(){
int i, n, a[atmost], comm_sz, biggest, h, b;
printf("How many segments? ");
scanf("%d", &comm_sz);
srand((unsigned)time(NULL));
n = rand()%atmost;
printf("n = %d\n", n);
for(i = 0; i
a[i] = rand() % 10001;
printf("a[%d] = %d, ", i, a[i]);
}
printf("\n");
h = n/(comm_sz-1);
biggest = -1;
printf("h = %d\n", h);
for(i = 0; i
if(i == comm_sz - 2)
b = find(a, i * h, n-1);
else
b = find(a, i * h, (i+1) * h - 1);
if(b > biggest)
biggest = b;
}
printf("The biggest is: %d\n", biggest);
return 0;
}

Note: Since I need to test your project use static array (i.e. Do not use the built-in function: malloc). Name your array: a. Only use one array. Do not sort.

Reference no: EM131030914

Questions Cloud

Write a program that produces a list of nz notes and coins : Money dispenser calculatorWrite a program that produces a list of NZ notes and coins required to give change for a user-entered amount up to $1000.
Hierarchical arrangement of lines of authority : The typically hierarchical arrangement of lines of authority, communications, rights and duties of an organization. Organizational structure determines how the roles, power and responsibilities are assigned, controlled, and coordinated, and how in..
What are the key sources of financing these organisations : Identify the differences in their reports structure and content - What are the key performance indicators?
Pros and cons of separating and integrating : Discuss pros and cons of "separating" and "integrating" the sourcing and logistics functions. Examine whether this BPM project of Gap led to the right decision to split them.
Define an array of size 1000 : For m (its value comes from the keyboard) processes divide that array to (m-1) segments. All the segments except the last one must be equal (Note that the last segment may get bigger than other segments)
What explanations can you find for high teen pregnancy rates : What explanations can you find for the high teen pregnancy rates in Texas, Mississippi, Georgia and North Carolina - Why do you think the teen pregnancy rate is lower in the Northeast and some parts of the Midwest and North?
Impact of regulatory requirements : Though sustainability initiatives are often driven by regulatory requirements, an increasing number of companies notice that they frequently result in decreased operating costs and increased revenues.
States the argument unilever is likely to make in its appeal : Recommends to the General Counsel how FDA should respond to these arguments, and what course it should adopt when regulating the sale and labeling of Just Mayo products. Write the memorandum.
Would you use dantes classification : If you were to organize a contemporary hell for the great villains of our day, would you use Dante's classification or would you construct another schema? On what basis would it be organized?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Design a combinational circuit

Design a combinational circuit that accepts a 4-bit number and output a 3-bit binary number that approximates the square root of the number

  Perform research on the topic of personal work planning

Perform research on the topic of personal work planning. In your own words, explain the importance of creating and maintaining personal work plans. If you are not working, but are part of an association or know of an organisation, please answe..

  How it utilizes it and did the designer or programer choose

1-direct manipulation 2-menu selection 3-form fill-in 4-command language 5-natural language For each one,provide a software example you've used that utilizes it, and how it utilizes it and did the designer or the programer choose the correct style..

  Analyze the data to make business decisions

Database reports give us with ability to further analyze the data and give it in format which can be used to make business decisions.

  Distinction between input and output lines

How many cross points would be required if there were no distinction between input and output lines (i.e., if any line could be interconnected to any other line serviced by the crossbar)?

  Very important component of your system

The user interface is a very important component of your system. In this assignment you are first asked to read and understand a popular set of usability heuristics. Readings (Jakob Nielsen is a very renowned usability expert):

  Provide a plan that addresses planned organizational change

Question 6.6. (TCO F) Provide a plan that addresses planned organizational change using judicious automation, rationalization of procedures, business process redesign, and constructive paradigm shifts that improve the way business is managed.

  Create a web page for a store that rents computers

Create a Web page for a store that rents computers by the hour. Use an external style sheet. Format the heading level styles in olive and the paragraphs in blue. Format the heading and body elements using sans-serif fonts, such as Arial and Helvetica..

  What types of output and information delivery

What types of output and information delivery would you suggest for the system? Please support answer with references from the Internet. When citing references please do so with APA 6th edition formatting.

  Display the most frequently occurring word

the program should count how many times each word appears and display the most frequently occurring word, along with how many times it occurs.

  Find the sum of all the multiples

Write a program to find the sum of all the multiples of 3 or 5 below N. for example: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

  How the game was integrated with the concepts of computing

Each week, you will explore a new game through the lens set up by the weekly material. For example, when working with Turing machines, you may wish to represent the concept through a game of Hangman.

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