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

Compare delays in packet switching and circuit switching, In this question,...

In this question, you will compare delays in packet switching (i.e. in IP networks), in circuit switching (i.e. in PSTN telephony) and in virtual circuit packet switching (i.e. in

Commands and responses - application layer, Commands SMTP uses comma...

Commands SMTP uses commands  and response  to transfer  message between a client  and a  server.  Each  commands  or reply  is terminated by a two character ( carriage re

What is a tag, In HTML, a tag shows the browser what to do. When you write ...

In HTML, a tag shows the browser what to do. When you write an HTML page, you enter tags for lot of  reasons -- to change the appearance of text, to show a graphic, or to make a co

What is internet, What is Internet? Internet is a collection of network...

What is Internet? Internet is a collection of networks or network of networks. Various networks like LAN and WAN connected by suitable hardware and software to work in a seamle

Plot way forms for the modulation schemes, Plot way forms for the following...

Plot way forms for the following modulation schemes using Mathlab: a) 2 ASK   4 ASK                       b)  BFSK     4 FSK                             c) BPSK 4

Mpi functions and environment, MPI contains hundreds of functions, a small ...

MPI contains hundreds of functions, a small subset of which is enough for most practical purposes. We shall talk about some of them in this unit. Functions for MPI Environment:

What security risks present on the networks, Security risks present on the ...

Security risks present on the networks Lots of risks are present everywhere on Internet as well as on Intranet, if it is not known what is being done. Every day a number of

State the reason for intranet system breaks down, State the reason for Intr...

State the reason for Intranet system breaks down Care must be taken to ensure that proper spare parts are available even after about five years of commissioning. In addition t

Types of vts sonet sdh, Types of VTs There are  several  option for  pa...

Types of VTs There are  several  option for  payload are actually mapped into the VT.  Locked mode VTs  bypass the pointers with a fixed  byte oriented mapping of limited flexi

Tree interconnection network, Tree interconnection network Tree inter...

Tree interconnection network Tree interconnection network(TIN)), processors are organized in a whole binary tree pattern.

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