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

Data alignment in processor arrangements, Data Alignment Arrays are ali...

Data Alignment Arrays are aligned to templates by the ALIGN directive. The ALIGN directive is used to align elements of different arrays with each other, indicating that they s

Define some solutions of security, What is Security solutions Though t...

What is Security solutions Though there are a number of security solutions available due to sophistication in technology, there are a number of risks and difficulties attached

Network, do you do paraphrase

do you do paraphrase

Command to view the configuration-register value, Recognize the command to ...

Recognize the command to view the configuration-register value Ans) show version is the command to view the configuration-register value

Determine the switch in a physical ring, Switch In a physical ring ...

Switch In a physical ring configuration any disabled or else disconnected node can disable the entire network Use of a switch can permit the ring to bypass an inactive

What is 100base-fx, 100Base-FX Utilizes two identical optical fiber...

100Base-FX Utilizes two identical optical fibers in star topology One fiber holds frames from the station to hub one from hub to station Encoding is 4B/5B Si

Explain the term - carrier sense multiple access, What is use of Carrier se...

What is use of Carrier sense multiple access Carrier sense multiple access with collision detection (CSMA/CD) is a form of medium access control in which a station listens to

Electronic cheques, Electronic Cheques   Another mechanism for Internet p...

Electronic Cheques   Another mechanism for Internet payment is electronic cheques. With electronic cheques, the payer (either an individual consumer or a business) instructs his

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