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

Which of the logic gates are known as universal gates, Which of the logic g...

Which of the logic gates are known as universal gates ? Ans. NAND and NOR are termed as universal gates, since any digital circuit can be realized completely by using either of

Execute sparse matrix dynamically, To execute sparse matrix dynamically, Wh...

To execute sparse matrix dynamically, Which data structure is used Linked List data structure is used to execute sparse matrix dynamically

How to make frames for web documents, Q. How to make frames for web documen...

Q. How to make frames for web documents? Intelligent use of frames can give your pages a cleaner look and make easier to navigate. The fundamental concept goes like this: Every

Is dos a real time os, DOS is not a RTOS (real time Operating system), thou...

DOS is not a RTOS (real time Operating system), though MS DOS can be used with certain APIs to attain the RTOS functionality. For example, the RT Kernel (Real Time Kernel) which ca

User compatibility & appropriateness of inputs and outputs, User Compatibil...

User Compatibility & Appropriateness of Inputs and Outputs User compatibility - this is the degree to which the machine works towards task completion in way that suits the u

Displays a format of floating-point number, Q. Displays a format of floatin...

Q. Displays a format of floating-point number? A floating binary number +1010.001 in a 16-bit register is able to be represented in normalised form (presuming 6 bits for expone

Explain the use of ssl to secure the network, Explain the use of SSL to sec...

Explain the use of SSL to secure the network.  SSL (Secure Sockets Layer) is a protocol developed by Netscape for transferring private documents by the Internet. SSL works by u

The concept of program-parallel computing, The Concept of Process Infor...

The Concept of Process Informally, a method is a program in execution, behind the program has been loaded in the main memory. However, a method is more than just a program code

Explain the structure of a c program, Explain the Structure of a C Program?...

Explain the Structure of a C Program? Each C program consists of one or more functions one of the which must be main(). A function name is forever followed by a pair of parenth

What is mmx technology, What is MMX Technology MMX Technology: MMX (M...

What is MMX Technology MMX Technology: MMX (Multimedia extensions) technology adds 57 new instructions to instruction set of Pentium - 4 microprocessors. MMX technology also

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