Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91755413

Have any Question?


Related Questions in Computer Engineering

Question suppose that a remote transmitter sends a message

Question : Suppose that a remote transmitter sends a message at 2500 Baud and the receiver is expecting the data rate to be 2400 Baud. Calculate the accumulated sample error for one character. Give the answer in bits.

In relation to internet connectivity both you and the

In relation to Internet connectivity, both you and the chemists at Plains Research are concerned about security. What network device or devices can be used to address the concern about security?

Question please review the description of the organization

Question: Please review the description of the organization that is the subject of your semester project. The description of that organization, CITY GENERAL HOSPITAL, is described in the instructions for Phase I that you ...

Write a c functionnbspescapechar s char tnbspthat converts

Write a C function escape(char s[], char t[]) that converts the characters newline and tab into two character sequences n and t as it copies the string t to the string s. Use the C switch statement. Also write the revers ...

What are information silos what are the problems caused by

What are information silos? What are the problems caused by information silos? How organizations can solve the problems caused by information silos?

Identify at least two 2 factors that have led to the

Identify at least two (2) factors that have led to the explosive growth of digital crime over the past a few decades. Next, describe the most common forms of digital crime, and give your opinion as to why those forms you ...

How technology government regulations international

How technology, government regulations, international factors, expectations about the future, and the macroeconomy play a role in managerial decision-making? Carefully explain each by giving example.

The formulas a rarr b and c and a rarr b and a rarr c are

The formulas A → (B ∧ C) and (A → B) ∧ (A → C) are logically equivalent. For this problem, you are going to prove that they are equivalent in two different ways. Prove that A → (B ∧ C) ≡ (A → B) ∧ (A → C) by writing two ...

Argue why wireshark should be outlawed and it is a clear

Argue why Wireshark should be outlawed and it is a clear violation of privacy act and then argue why it should not be out outlawed and that it is a vital resource to be freely used and does not violate the privacy act

Elmers utility function isnbspuxnbspy minxnbspy2 if the

Elmer's utility function is  U ( x ,  y ) = min{ x ,  y 2 }. If the price of  x  is $10 and the price of  y  is $15 and if Elmer chooses to consume 4 units of  y , what must his income be? a. $220 b. $100 c. $320 d. Ther ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As