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 dynamic key management mechanism, Question: a) Consider the f...

Question: a) Consider the following MIP scenario. Quite a few enterprise networks use private addresses and NAPT for the communication to the Internet. i. Discu

Private networks, Private  Networks The information routes from one ne...

Private  Networks The information routes from one networks  to another  network through  a leased line. If an  organization needs privacy  can use a private networks  or networ

Metropolitan area network ( man)- fundamentals of networks , Normal 0 ...

Normal 0 false false false EN-IN X-NONE X-NONE Metropolitan area Network ( MAN) Metropoli

Reliable data transfer - transport layer, Reliable Data Transfer Figur...

Reliable Data Transfer Figure illustrate the  framework for reliable  transfer. The service  abstraction provided  to the upper  layer  entities is that  of a reliable channel

What are the benefits of networking, What are the benefits of Networking? ...

What are the benefits of Networking? The following are the distinct notes in favor of computer networking. a. The computers, staff and information can be well managed b.

Parallel balance point, Parallel Balance Point In order to implement a ...

Parallel Balance Point In order to implement a parallel algorithm on a parallel computer, K number of processors is needed. It may be noted that the given input is assigned to

Parts count method calculation, M E T HOD OF CALCULATION It involves...

M E T HOD OF CALCULATION It involves counting the number of each part type and multiplying with the generic failure rate of each part. On summing up the product, we obtain t

Point to point architecture - application layer, Point to Point Architectur...

Point to Point Architecture The term  peer means equal which can  be informally  interpreted as a process with  capability similar to the other processes with process communic

Explain about the digital traffic channels, Explain about the Digital traff...

Explain about the Digital traffic channels The most notable difference among the two generations is that first generation systems are almost purely analog, while second generat

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