Example programmes for parallel systems-adding element, Computer Networking

Assignment Help:

Example Programmes for Parallel Systems

Now we shall complete this with the examples on shared memory programming.

Example 13: Adding elements of an array using two processor int sum, A[ n] ; //shared variables

void main ( ){

int i ;

for (i=0; i

// now create process to be implemented by processor P1

fork(1) add (A,n/2,n-1, sum); // process to add elements from index n/2 to -

1.sum is output variable         // now create process to be implemented by processor

 P0                                                                                           add (A,0,n/2-1, sum);

join 1 ;

printf ("%d", sum);

}

add (int A[ ], int lower, int upper, int sum) {

int sum1=0, i;

 for (i=lower; i<=upper; i++)

sum1=sum1+A[i];

lock sum;

sum=sum+sum1;

unlock sum ;

}

In this program, the last half of the array is passed to processor P1 which adds them. Meanwhile processor P0 adds the first half of the array. The variable sum is locked to avoid inconsistency.


Related Discussions:- Example programmes for parallel systems-adding element

Network topology and design, Question 1: The following is a dump of a T...

Question 1: The following is a dump of a TCP header in hexadecimal format: 00CD0018 00000EF1 00000D5D 502200D1 01BF0010 Please answer the following two parts of questions

Illustrate error detection-simple parity check, Q. Illustrate Error Detecti...

Q. Illustrate Error Detection-Simple Parity Check? Error Detection-Simple Parity Check A redundant bit called as Parity Bit? is added to every data unit. Even Pa

Cidr presentation, Inside a device, every address mask is stored as a 32-bi...

Inside a device, every address mask is stored as a 32-bit number. When we submit a prefix and an address mask they use a changed form of dotted decimal addressing known CIDR addres

Rip routes entering and leaving the router, Recognize the command that will...

Recognize the command that will show the RIP routes entering and leaving the router? Ans) Route# debug ip rip

Briefly describe how the file system is organized in unix, Question: a)...

Question: a) Briefly describe how the file system is organized in Unix. b) What is the importance of the "touch" command. Give one of its disadvantage. c) Name three d

Why it is necessary to have layering in a network, Why it is necessary to h...

Why it is necessary to have layering in a network? A computer network is a very complex system. It becomes very difficult to execute as a single entity. The layered approach di

Global positioning system (gps) tracking, By utilizing measurements of the ...

By utilizing measurements of the so-called pseudo range between an object and each of several earth orbiting GPS satellites, the object can be very accurately located in space. A g

Define the term - hot swapping, Define the term - Hot swapping The rel...

Define the term - Hot swapping The reliability of the machine can be dramatically improved by installing the best components. Hot swapping is a concept through which component

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