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

Explain the term hardware cost, Hardware Cost It indicates to the cost ...

Hardware Cost It indicates to the cost concerned in the functioning of an interconnection network. It comprises the cost of arbiter unit, connectors, switches, interface logic

What is the disadvantage of a star topology, What is the disadvantage of a ...

What is the disadvantage of a star topology? One major drawbacks of star topology is that once the central hub or switch get damaged, the whole network becomes unusable.

Implement a web server on personal computer, Question: a) The Systems ...

Question: a) The Systems Administrator of Acme Company performs the backup of the website database file every day at 15:50. The original file location is database.sql. The Ad

Create and simulate a network - netml system, Create and simulate a network...

Create and simulate a network similar to the one shown here, using the NetML system. The network is a little more complex, as depicted at the right. There is an extra node

Presentation layer of osi reference model, Q. Presentation layer of osi ref...

Q. Presentation layer of osi reference model? - The presentation layer makes sure that the information that the application layer of one system sends out is readable by the app

Low-earth-orbiting leo satellites , LOW-Earth Orbiting have more advantageo...

LOW-Earth Orbiting have more advantageous in Mobile based communication devices like PDAs, Cell phones and automobile communications. The LOW-Earth Orbiting is a satellite of orbit

Which type for communication switch do, In case of any new event switch do ...

In case of any new event switch do broadcast, after that always do Unicast.

Local and wide area networking, A. Current setting A new bank has its he...

A. Current setting A new bank has its headquarters located in City A. Recently, the bank has opened its first branch in City B, and its data centre in City C. The three cities a

What are the disadvantages of ospf protocol, Disadvantages of OSPF protocol...

Disadvantages of OSPF protocol i) Single Area ii) High Hardware Requirements iii) Troubleshooting

Private network, Single company or organization owns this. They are usually...

Single company or organization owns this. They are usually LAN technologies. There can be multiple LANs in a campus or building linked together. They are sometimes known Intranet.

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