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
Name the categories of Multiplexing? There are three categories of multiplexing a. Frequency Division Multiplexing (FDM) b. Time Division Multiplexing (TDM)    i. Sync

Take the maximum packet lifetime, T.  It's stated that T must be big enough to make sure the packet and its ACK have vanished.  Why do we have to have the ACK?

The application layer This  layer enables users  to access the  network  by providing  a few  services to the user some of the protocols and services available to the  user ar

State the Nyquist theorem The Nyquist theorem is thermo of mathematics and has nothing to deal with technology. It says that if you have the function whose Fourier spectrum doe

Troubleshoot and Correct VTP and Configuration Errors When all errors are corrected, you should be capable to ping PC4 from PC1, PC5 from PC2, and PC6 from PC3. You should also

Error Detection- Check Sum The Checksum generator are subdivides the data unit into equal segments of "n" bits (usually 16) These segments are added utilizing one's c


CAM- Content Address Memory.  Its another name of MAC address table.

Questions: A signal of amplitude 10 mV is fed to the amplifier in the figure. What is the amplitude of the voltage at the output from the amplifier?

What is Ring Topology? The physical ring topology is a circular loop of point-to-point links. Every device connects directly to the ring or indirectly by and interface device o