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

Show the transmission control protocol, Q. Show the Transmission Control Pr...

Q. Show the Transmission Control Protocol? Transmission Control Protocol (TCP) TCP makes Internet reliable. TCP solves many problems which can occur in a packet switching

When one speech sample appears in time multiplexed system, In a time multip...

In a time multiplexed space switching system, one speech sample appears every? One speech sample shows every 125 micro sec, in a time multiplexed space switching system.

Write a short note on pointer operators in c, Write a short note on pointer...

Write a short note on pointer operators in c Pointers (that is, pointer values) are generated with the ''address-of'' operator &, which we can also think of as the ''pointer-to

Salient points about addressing mode, Salient points about addressing mode ...

Salient points about addressing mode are:  This addressing mode is employed to initialise value of a variable. Benefit of this mode is that no extra memory accesses are

Distinguish between combinational & sequential logic circuit, Distinguish b...

Distinguish between combinational logic circuits and sequential logic circuits. Ans: Combinational logic circuits:- (i) Outputs only depend upon present state of the i

What is php, The PHP Hypertext Pre processor is a programming language that...

The PHP Hypertext Pre processor is a programming language that permits web developers to make dynamic content that interacts with databases. PHP is basically used for developing we

Ldb need not be defined in the abap/4 dictionary, All nodes in the structur...

All nodes in the structure of LDB need not be defined in the ABAP/4 Dictionary False. One has to describe all nodes in the Dictionary or single has to select all nodes that a

Comparator, 6 bit magnitude comparator

6 bit magnitude comparator

Illustrate working of t flip-flop, Q. Illustrate working of T Flip-Flop? ...

Q. Illustrate working of T Flip-Flop? T (Toggle) flip-flop is attained from JK flip-flop by combining inputs J and K together. The implementation of T flip-flop is displayed in

What is real time clock, Real time clock A real-time clock keeps the t...

Real time clock A real-time clock keeps the time in real time - i.e. in hours and minutes. Software for the real-time clock comprises an interrupt service procedure which is c

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