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

Process of skype is a web-based service, Skype is a web-based service which...

Skype is a web-based service which offers cheap and free phone calls. Explain step by step (in terms of networking technology) what really happens from the point when you initiate

Routing table - network layer and routing , Routing Table A routing  t...

Routing Table A routing  table has columns  for at  three types o information  the network  ID  the cost  and the  ID of the  next  router. The  network  ID is the final  desti

What is star topology, What is Star topology Each station is directly c...

What is Star topology Each station is directly connected to a common central node. Typically, each station attaches to a central node via two point-to-point links, one for tran

Cdma gsm back haul network, S t d "B" 6.4 m Ku-BAND EARTH STATION (2004) ...

S t d "B" 6.4 m Ku-BAND EARTH STATION (2004)   D-Sat (District Satellite Project) circuits for rural connectivity via satellite are in operation. Purpose of this project i

Explain the term dimensionality of interconnection network, Dimensionality ...

Dimensionality of Interconnection Network Dimensionality refers the arrangement of processing elements or nodes in an interconnection network. In linear network or single dimen

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

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

Evaluate error detection in crc polynomials, Q. Evaluate Error Detection in...

Q. Evaluate Error Detection in CRC Polynomials? The divisor in the CRC generator is most habitually represented as an algebraic Polynomial. Reasons: It is short

Explain transparent bridges and learning bridges, Transparent Bridges & Lea...

Transparent Bridges & Learning Bridges - Builds table by examining destination as well as source address of each packet it receives - Learning bridges - If address is not

What is the routing algorithm used by rip and igrp, Distance vector-based r...

Distance vector-based routing algorithms (also called as Bellman-Ford algorithms) pass periodic copies of a routing table from router to router. Regular updates among routers commu

Show coaxial cable connectors, Q. Show Coaxial Cable Connectors? - A mo...

Q. Show Coaxial Cable Connectors? - A most common is barrel connector (BNC) - T-connectors are utilized to branch off to secondary cables - Terminators are necessary for

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