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

Define layered network model, Q. Define layered network model? - The OS...

Q. Define layered network model? - The OSI Reference Model is collection of seven layers every specifying particular network functions. - The process of breaking up the func

Error detection and correction, Error detection and correction The digi...

Error detection and correction The digital traffic stream of second generation systems also lends itself to the use of error detection and correction methods. The result can be

Data alignment in processor arrangements, Data Alignment Arrays are ali...

Data Alignment Arrays are aligned to templates by the ALIGN directive. The ALIGN directive is used to align elements of different arrays with each other, indicating that they s

Discuss about the software in detail, Discuss about the Software in detail ...

Discuss about the Software in detail Software contain a number of components such as SQL Server for database connectivity, Systems Management Server for easy Web management,

Determine the command to disable cdp on an interface, Router(config-if)# no...

Router(config-if)# no cdp enable is the  command to disable CDP on an interface

What are the issues are there in network environment, What are the issues t...

What are the issues there in network environment Some of the issues necessary are: Network planning should be carried out covering the following important issues:

Wlan technology, Identify and briefly explain any four key requirements tha...

Identify and briefly explain any four key requirements that need to be examined when considering deploying a WLAN technology.

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