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
Multiplexing Multiplexing is the set of techniques that allows simultaneous transmission of multiple signals across a single  data like. It  is methods  for efficient utiliza

FAULT TREE ANALYSIS Reliability engineering, in a nutshell is concerned with failures.   How failures occur, how often they occur, and how to minimize them are the basic proble

Illustrate about the working of Socks protocol SOCKS is an open, industry-standard protocol advanced by the Authenticated Firewall Traversal working group of the IETF (Internet

Q. Illustrate TCP – bytes and segments? TCP - bytes & segments TCP at the sending site collects bytes into a packet called a segment TCP adds a header to each se

Question 1 List 10 common ActiveX controls Question 2 Discuss Network Interface using any OS Question 3 Explain BGP components and its working Question 4 G

State in brief about the Graceful degradation With FDMA or TDMA, a fixed number of users can concurrently access the system. Though, with CDMA, as more user concurrently access

Name the two commands that save the running-config to a TFTP server Ans)  Two commands are:- a) copy running tftp  b) write network

Process to send data is called as encapsulation and process to receive data is called De-encapsulation.

1.  Detail for each of the four following MIPS instructions, which actions are being taken at each of their five steps.  Do not forget to mention how and during which steps each in

Q. What is Source Routing? Source Routing - Sender of packet defines bridges and routes that packet should take - Complete path of bridge IDs and destination address i