Programming based on message passing, Computer Networking

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);

}

Posted Date: 3/2/2013 7:51:49 AM | Location : United States







Related Discussions:- Programming based on message passing, Assignment Help, Ask Question on Programming based on message passing, Get Answer, Expert's Help, Programming based on message passing Discussions

Write discussion on Programming based on message passing
Your posts are moderated
Related Questions
Quetion: A photodiode with a dark current of 10 nA has a responsivity of 0.4 A/W at a certain wavelength. What current flows through the photodiode when it is reverse biased an

For VOIP, first you need to consider the codec to use. Although there are many voice codecs, MyCo wants the safest bet and suggests that you design with the most known and oldest c

The following information was obtained from a host computer: 00:05:17.176507 74.125.228.54.1270 > 64.254.128.66.25: S 2688560409:2688560409(0) win 16384 (DF) (ttl 46, id 2096

MIME The Multipurpose Internet Mail Extensions While  the message  headers described in are satisfactory for sending  ordinary  ASCII text they are  not sufficiently Reich for

Q. Explain about Virtual Circuit Switching? Virtual Circuit Switching - All packets belong to a message (or) session is preserved. - Single route is selected between s

The diagram below offers an overall view on the methods use by both the OSI and TCP/IP model. ISO Approach - Occasionally called Horizontal Approach - OSI asse


Q. What is Data traffic? Data traffic Peak data rate : max data rate of the traffic Average data rate = (amount of data)/time Maximum Burst size: max. l

What are the two types of Transmission technologies, basis on which computer networks can be categorized? Broadly there are two types of transmission technology: 1. Broadc

Question The circuit in the figure is driven by a 9 mV amplitude signal generator with an output impedance of 2 kW. What is the output voltage amplitude from the circuit in the