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

IP address, what is variable ip address

what is variable ip address

What is a lan, What is a LAN? LAN stands for Local Area Network. It ref...

What is a LAN? LAN stands for Local Area Network. It refers to the connection among computers and other network devices that are located within a small physical location.

Switch - network layer and routing , Switch Generally called  as two ...

Switch Generally called  as two  layer switch . it  performs  on physical  and data  link  layers. It  is  a bridge it has many  ports  that allow  better  performance. Since

Show concept of permutation network, Q. Show Concept Of Permutation Network...

Q. Show Concept Of Permutation Network? In permutation interconnection networks the information transfer necessitates data transfer from input set of nodes to output set of nod

Example of the datalink layer, MAC (media access control) and LLC (logical ...

MAC (media access control) and LLC (logical link control) are both layer 2 protocols.

Explain the operation of a token ring topology for a lan, Question: (a)...

Question: (a) Show by means of a diagram the Ethernet frame structure and describe the six fields of the Ethernet frame structure. (b) Explain the operation of the Carrier S

Describe the advantages of intranet to the organisation, Describe the advan...

Describe the advantages of Intranet to the organisation The most obvious advantage is that everyone with access to a computer terminal connected to the Intranet can obtain the

What is full-duplex ethernet, Full-Duplex Ethernet 10Base5 as well ...

Full-Duplex Ethernet 10Base5 as well as 10Base2 are half-duplex Full-duplex raises capacity of each domain No require for CSMA/CD

How many types of twisted pair cable are there, How many types of twisted p...

How many types of twisted pair cable are there We can find two types of twisted pair cables, namely: Unshielded Twisted Pair Cable (UTP) and Shielded Twisted Pair Cable (STP).

Transport layer , Transport Layer In computer networking it the transp...

Transport Layer In computer networking it the transport  layer is where  sessions are  exchanged between  hosts. This layer resides  between  the application layer and  networ

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