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

Explain about two-pass assembler, Q. Explain about Two-pass assembler? ...

Q. Explain about Two-pass assembler? Assemblers usually make two or more passes through a source program in order to resolve forward references in a program. A forward referenc

What is a microinstruction, What is a microinstruction? Each word in co...

What is a microinstruction? Each word in control memory having within it a microinstruction.  The microinstruction specifies one or more micro-operations for the system.  A seq

What is grade of service, What is Grade of service? Grade of service:...

What is Grade of service? Grade of service: In a loss system, the traffic carried through the network is usually lower than the actual traffic offered to the network through

What is recursing downwards, What is recursing downwards? And its ways. ...

What is recursing downwards? And its ways. The design process generally works top-down; you start with the higher level operations and proceed to describe lower level operation

Efficiency of vector processing over scalar processing, Efficiency of Vecto...

Efficiency of Vector Processing over Scalar Processing: We know that, a sequential computer processes scalar operands one at a time. Thus, if we have to process a vector of len

Define emulation, Define emulation. Given a computer with a particular ...

Define emulation. Given a computer with a particular instruction set, it is possible to explain additional machine instructions and execute them with extra micro routines. Emul

What do you mean by proc directive, Q. What do you mean by PROC Directive? ...

Q. What do you mean by PROC Directive? PROC Directive: Code segment comprises executable code for a program that includes one or more procedures defined initially with PROC dir

Major characteristics of a computer family, Q. Major characteristics of a c...

Q. Major characteristics of a computer family? Let us summarise the major characteristics of a computer family. These are as below: Figure: Characteristics of computer

Explain interface, What is an Interface? An interface is not a class. I...

What is an Interface? An interface is not a class. It is an entity that is explained by the word Interface. An interface has no implementation; it only has the signature or in

Calculate switching capacity in a two stage network, In a two stage network...

In a two stage network there are 512 inlets and outlets, r=s=24. If the probability that a given inlet is active is 0.8, calculate: Switching capacity Given: N =M =512, α

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