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

Determine power dissipated in resistor, Question: With Vout not connect...

Question: With Vout not connected to any additional circuitry, what power is dissipated in the 7 kW resistor?

What are different ways of securing a computer network, What are different ...

What are different ways of securing a computer network? There are lots of ways to do this. Install reliable and updated anti-virus program on all computers. Make sure firewalls

Different technologies involved in establishing wan links, What are the dif...

What are the different technologies involved in establishing WAN links? Analog connections - using conventional telephone lines; Digital connections - using digital-grade telep

What is parabolic dish antenna, Q. What is Parabolic Dish Antenna? - In...

Q. What is Parabolic Dish Antenna? - Incoming signals means that the Signal bounces off of dish and is directed to focus - Outgoing signals signifies transmission is broadca

WOrkstation, Interdepences of workstation hardware and software

Interdepences of workstation hardware and software

Give some examples of the session layer, Session layer examples are Netbios...

Session layer examples are Netbios Names, SQL, NFS, X Windows, and RPC

Parallel programming environment characteristics, Parallel Programming Envi...

Parallel Programming Environment Characteristics  The parallel programming environment consists of an debugger, a editor,  performance evaluator and programme visualizer for i

What are the brigdes, Brigdes Introduction - LAN may require to cove...

Brigdes Introduction - LAN may require to cover more distance than the media can handle effectively or - Number of stations may perhaps be too great for efficient frame d

Verify network connectivity- ccna, Verify Network Connectivity Step 1: ...

Verify Network Connectivity Step 1: Use the ping command to determine network connectivity. You can determine network connectivity using the ping command.  Note: If pings

Networking concepts, Networking Concepts Q1  What are the main feature...

Networking Concepts Q1  What are the main features of TCP connections? Why is it said that TCP provides full-duplex service? Q2  What are the differences between TCP conne

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