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
The Five steps to data encapsulation (IN ORDER): 1) User information is changed into data. 2) Data is changed into segments. 3) Segments are changed into datagram and pack

Overhead SONET overhead  is not added as headers or trailers as we have seen  in other  protocols. Instead SONET  insert overhead at a variety of location in middle  of the  f

Q. What do you mean by Flow Control? - How much data sender is capable to transmit before receiving the ACK - Why flow control? - Limitation with receiver 1. Processin

Fundamental of Network The  concept  of network  is not  new. In simple  it means an interconnected set  of some  objects. For decades we are familiar with the radio,  televi

Network Criteria - Performance - It is able to be measured by transit time and response time. Affected by type of medium, number of users and connected HW/SW - Reliability

Determine the rate of communication line The dog could carry 21 gigabytes or 168 gigabits. A speed of 18 km/hour that is equal to 0.005 km/sec. The time to travel the distance


A hypertext link is a special tag that links single page to another page or resource. If you click the link, the browser goes to the link's destination.

Introduction of DNS While discussing about the Internet, one things comes automatically in the n=mind and hence it is directly or indirectly depended on DNS. The DNS which sta

If the host has the subnet ID why do we require a subnet mask?