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

What is cam, CAM- Content Address Memory.  Its another name of MAC address ...

CAM- Content Address Memory.  Its another name of MAC address table.

Explain the layer which is closer to the user, There is only an applicatio...

There is only an application layer which is closer to user and also gives many application which user directly linked.for ex:- web browser

Function of tcp - ip transport layer, Q. Function of TCP/IP Transport Layer...

Q. Function of TCP/IP Transport Layer ? TCP/IP Transport Layer - Defines two standard transport protocols UDP and TCP - TCP equipment a dependable data-stream protocol

Explain network services, Explain Network Services Network services are...

Explain Network Services Network services are the thing that a network can do. The main networking services are File Services: This contains file transfer, storage, data m

State the concept of multicast typing, Multicast An identifier for a se...

Multicast An identifier for a set of interfaces (typically belonging to dissimilar nodes). A packet sent to a multicast address is delivered to all interfaces identified by tha

Define ike modes, Normal 0 false false false EN-IN X-...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Networks classification - point to point network , Normal 0 fal...

Normal 0 false false false EN-IN X-NONE X-NONE Networks classification

WAN, what is a WAN

what is a WAN

State the process of calculate the drift rate, State the process of calcula...

State the process of calculate the drift rate A drift rate of 10 -9 means 1 second in 109 seconds or 1 nsec every second. At OC-1 speed, say 50 Mbps for simplicity, a bit las

#title.assignment., hii i want to make a assignment from you. please help m...

hii i want to make a assignment from you. please help me.

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