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

Example multi-layer ann with sigmoid units, Example Multi-layer ANN with Si...

Example Multi-layer ANN with Sigmoid Units: However we will concern ourselves here that with ANNs containing only one hidden layer and as this makes describing the backpropaga

Ready and standard mode for point-to-point message passing, Q. Ready and St...

Q. Ready and Standard mode for point-to-point message passing? Ready mode: Transmitting can be started only if matching receive has already been initiated.  Standard mode: M

Ease of learning - user friendliness, Ease of Learning - User Friendliness ...

Ease of Learning - User Friendliness Much has been made recently of increasing sophistication in technology with one of the major benefits advertised as an increase in somethi

Java Applet, Simple codes for robot using applet

Simple codes for robot using applet

Hiring problem algorithm, Consider the Hire Assistant problem. We interview...

Consider the Hire Assistant problem. We interview n candidates and always hire the best qualified so far. Let n = 5 for our example. Find the probabilities that we hire exactly 1 t

Decomposition model of parallel programming, The PVM system supports functi...

The PVM system supports functional and data decomposition model of parallel programming. It attaches with C, C++, and FORTRAN. The C and C++ language bindings for the PVM user inte

Show block diagram of sequential circuits, Q. Show block Diagram of sequent...

Q. Show block Diagram of sequential circuits? A sequential circuit is an interconnection of storage elements and combinational circuits. The storage elements known as flip-flop

How to execute an instruction, Execution: Now instruction is ready for exec...

Execution: Now instruction is ready for execution. A different opcode will need different sequence of steps for execution. Hence let's discuss a few illustrations of execution of s

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