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

Deadlock avoidance or prevention, Deadlock Avoidance To avoid deadlock...

Deadlock Avoidance To avoid deadlocks two types of strategies are used: 1) Static prevention: It uses V and P operators and Semaphores to allocate and deallocate shared res

Message passing programming, Message passing is probably the most extensive...

Message passing is probably the most extensively used parallel programming paradigm today. It is the mainly natural, portable and efficient approach for distributed memory systems.

Data sharing - fundamentals of networks, Data Sharing One of the most ...

Data Sharing One of the most important uses of networking is to allow the sharing of data. Before networking was common an accounting employee who wanted to prepare a report f

Give some examples of private network addresses, Give some examples of priv...

Give some examples of private network addresses. 10.0.0.0 with a subnet mask of 255.0.0.0 172.16.0.0 with subnet mask of 255.240.0.0 192.168.0.0 with subnet mask of 255.2

Packet switching and virtual circuit packet switching, Describe Circuit swi...

Describe Circuit switching, Packet switching and Virtual Circuit Packet switching. Explain their suitability for different applications such as telephone and internet. Packet S

Describe the concept of successor and feasible successor, Describe the conc...

Describe the concept of successor and feasible successor?

Case study, #questi Scenario: Your Case Study must be based on the informat...

#questi Scenario: Your Case Study must be based on the information provided. There will be no additional information. This must be submitted in a .doc, or .pdf format. If you sen

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