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

Coffee and Company Security Case Study, This is a report, I am working on a...

This is a report, I am working on another one. This report is on finding a better solution dealing with customer, wifi, management, etc.

Quantity of numbers that a system administrator has to enter, In order to l...

In order to limit the quantity of numbers that a system administrator has to enter, Cisco can use which abbreviation to show 0.0.0.0?  Ans) Cisco uses host to state 0.0.0.0. Thi

Structure of internet servers address, In a client's software , the structu...

In a client's software , the structure of an Internet server's address keyed is as follows: Where: http refer for the communication protocol to be used www refer for th

Determine 100base-t4 ethernet, 100Base-T4 Utilizing four pairs of c...

100Base-T4 Utilizing four pairs of category 3 (voice grade) UTP to transmit 100 Mbps Two pairs are bidirectional and other two are unidirectional 8B/6T (eight bin

Http request message, HTTP Request Message The first  line of  an HTTP...

HTTP Request Message The first  line of  an HTTP request message  is called the  line. The subsequent lines are called  the header lines. The  request  line has  fields the me

Frequency division multiplexing, Frequency Division Multiplexing Frequ...

Frequency Division Multiplexing Frequency  division  multiplexing (FDM) is an analogy technique that can be applied when the bandwidth of a link is greater than the combined b

Explain stop--and--wait automatic repeat request, Q. Explain Stop--and--Wai...

Q. Explain Stop--and--Wait automatic repeat request? 1. Numbering frames prevents the retaining off duplicate frames. 2. Numbered acknowledgement are needed in case of delay

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