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

Error detection-general, Q. Error Detection-General? Sender transmi...

Q. Error Detection-General? Sender transmits every data unit twice Receiver performs bit-by-bit comparison between those two versions of data. Any mismatch would

Error control in TCP, Q. Show the Error control in TCP? Error control ...

Q. Show the Error control in TCP? Error control in TCP Detect lost segments, out-of-order segments, corrupted segments and duplicated segments Three tools: chec

Evolution of data communication, Question 1 Discuss the following         ...

Question 1 Discuss the following                     Evolution of Data Communication                     Elements of Data Communication System Question 2 Explain the following

What is the purpose of cables being shielded, What is the purpose of cables...

What is the purpose of cables being shielded and having twisted pairs? The main purpose of this is to stop crosstalk. Crosstalks are electromagnetic interferences or noise that

Why mac address called physical address, MAC address called Physical addres...

MAC address called Physical address Because it's not changeable

Define routing, Define Routing? The process of determining systematical...

Define Routing? The process of determining systematically hoe to forward messages toward the destination nodes based on its address is known as routing.

Describe the star topology, QUESTION a) The aim of a computer network ...

QUESTION a) The aim of a computer network is to increase efficiency and reduce costs. Explain how networks of computers achieve the above. b) Describe the star topology. Su

How is computer networks used in sales and marketing, Q. How is computer ne...

Q. How is computer networks used in sales and marketing?  Marketing and sales:   Computer networks are used extensively in both marketing and sales organizations. Marketing pr

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