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

Parallel random access machines, PRAM is one among the models which are use...

PRAM is one among the models which are used for designing the parallel algorithm as shown in Figure. The PRAM model comprises the following components: i)  A group of identical

What is cartridge drive, Q. What is Cartridge Drive? Cartridge Drive: ...

Q. What is Cartridge Drive? Cartridge Drive: A cartridge is a protective covering or case which is used to hold a magnetic tape, disk, a printer ribbon or toner. Contents are

Give difference between assembler and compiler, Give difference between ass...

Give difference between assembler and compiler. Assembler: It is the translator for an assembly language of computer. An assembly language is a low-level programming language

Insert images in dreamweaver, Q. Insert images in Dreamweaver? You will...

Q. Insert images in Dreamweaver? You will learn two methods to insert images in Dreamweaver-using Dreamweaver's main menu and using Objects panel. 1. Click anywhere in the l

Define the fundamentals of computer system, Define the Fundamentals of comp...

Define the Fundamentals of computer system A computer processes digital information. In order to do that it runs (executes) a machine language program. As an illustration, when

Display methods, Describe a console application project to show the differe...

Describe a console application project to show the different formatting styles used in display methods(i.e.Console.writeLine()).

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

Multi-threaded processors, The use of distributed shared memory in parallel...

The use of distributed shared memory in parallel computer architecture however the use of distributed shared memory has the problem of accessing the remote memory that results in l

What is monkey testing, What is Monkey testing? The monkey testing is ...

What is Monkey testing? The monkey testing is the process of testing here and there for judging the application trying to observe the accessing dissimilar functionalities is i

Data type, Define data type and abstract data type comment upon the signifi...

Define data type and abstract data type comment upon the significant of both

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