Programming based on message passing, Computer Networking

Assignment Help:

Programming Based on Message Passing

As we know, the programming model based on message passing uses high level programming languages like C/C++ along with a number of message passing libraries like PVM and MPI. Here, given an example program of message passing.

Example 1: Addition of array elements using two processors.

In this problem, we have to search the sum of all the elements of an array A of size n. We shall separate n elements into two groups of roughly equal size. The first [n/2] elements are added by the first processor, P0, and last [n/2] elements the by second processor, P1. The two sums then are added to get 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:- Programming based on message passing

Multicasting, MULTICASTING : The answer to above problem is multicastin...

MULTICASTING : The answer to above problem is multicasting. It is the normal form of broadcasting. It acts like broadcasting however it does not broadcast frames automatically

Hacking, can u send me a hacking software of face book for free

can u send me a hacking software of face book for free

Determine the term- web server and webmaster, Determine the term- Web Serve...

Determine the term- Web Server and Webmaster Web Server: A host computer that stores Web pages and responds to requests for viewing. Web servers communicate with Web browse

Discuss your strategy to test wlpc system, Wireless Phone Company (WLPC) is...

Wireless Phone Company (WLPC) is a provider of wireless phone service in the US with 100,000 customers serving mostly small markets. WLPC has just purchased additional airwaves in

Describe differential manchester, Q. Describe Differential Manchester? ...

Q. Describe Differential Manchester? - Inversion at middle of bit interval is utilized for synchronization - Presence or else absence of additional transition at beginning o

Explain the building blocks of client/server, The client side building bloc...

The client side building block moves towards the client side of the application. The server side building block moves towards the server side of the application.

Dns - server attacks, DNS - Server Attacks It’s not so easy to list al...

DNS - Server Attacks It’s not so easy to list all the associated attacks as they are evolving way so fast. As any error of flaw is identified, a patch is released in response

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