Addition of array elements using two processors, Computer Engineering

Assignment Help:

Q. Addition of array elements using two processors?

In this example we have to find sum of all elements of an array A of size n. We will divide n elements in 2 groups of roughly equivalent size. The first [n/2] elements are added by first processor P0 and last [n/2] elements by 2nd processor P1.  The two sums then are added to obtain the final result. The program is given below:

Program for P0

#include

#define n 100

int main(int argc, char **argv) {

int A[n];

int sum0 =0, sum1=0,sum;

MPI_Init(&argc, &argv);

for( int i=0;i

scanf("%d", &A[i]);

MPI_Send( &n/2, n/2, MPI_INT,1, 0, MPI_COMM_WORLD);

for(i=1; i

 sum0+=A[i];

sum1=MPI_Recv(&n/2, n/2, MPI_INT,1, 0, MPI_COMM_WORLD);

sum=sum0+sum1;

printf("%d",sum);

MPI_Finalize();

}

Program for P1,

int func( int B[int n])

{

MPI_Recv(&n/2, n/2, MPI_INT,0, 0, MPI_COMM_WORLD);

 int sum1=0 ;

for (i=0; i

  sum1+=B[i];

MPI_Send( 0, n/2, MPI_INT,0, 0, MPI_COMM_WORLD);

}


Related Discussions:- Addition of array elements using two processors

Define external variable declaration, Summarize the distinction between an ...

Summarize the distinction between an external variable definition and an external variable declaration. When we have ''declared'' a variable, we have meant that we have told th

Explain quadratic probing with respect to hashing technique, Quadratic prob...

Quadratic probing: In the above case when the first insertion is made the probability of latest element being inserted in a certain position is 1/n    where n is the size of the a

What are the rules of timescale directive, What are the Rules of Timescale ...

What are the Rules of Timescale directive Rules -  'Timescale directive, like all compiler directives, affects all modules compiled after directive,  whether  in  same  fi

Determine the binary equivalent of hexadecimal FA, The binary equivalent of...

The binary equivalent of (FA) 16   is ? Ans. (FA) 16 = (11111010) 10

Explain about quarter inch cartridge tapes, Q. Explain about Quarter Inch C...

Q. Explain about Quarter Inch Cartridge Tapes? Quarter Inch Cartridge Tapes (QIC Standard): These tape cartridges record information sequentially in a track with one head. Wh

Case x and z difference which is preferable and why, Case x, z difference, ...

Case x, z difference, which is preferable, why? CASEZ : Special version of case statement that uses a Z logic value to signify don't-care bits. CASEX : Special

Explain about magnetic tape, Explain about Magnetic tape      a) They a...

Explain about Magnetic tape      a) They are mostly used for keeping files of data  b )It is one of the cheapest and slowest methods for storage

Full form of www, What do you understand by WWW WWW: The World Wide ...

What do you understand by WWW WWW: The World Wide is an architectural framework for accessing linked documents increase out over thousands of machines all over the world. It

Write c program to read the text book number, With a C program to read the ...

With a C program to read the text book number, title, author and publisher into a structure and print these values. # include # include void main() { struct boo

Write Your Message!

Captcha
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