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

Two commands that save the running-config to a tftp server, Name the two co...

Name the two commands that save the running-config to a TFTP server Ans)  Two commands are:- a) copy running tftp  b) write network

Networking concepts and applications, iLab 2: Office Network Expansion ...

iLab 2: Office Network Expansion Connect to the iLab here. Submit your assignment to the Dropbox located on the silver tab at the top of this page. (See "Due Da

Metropolitan area network ( man)- fundamentals of networks , Normal 0 ...

Normal 0 false false false EN-IN X-NONE X-NONE Metropolitan area Network ( MAN) Metropoli

Determine the maximum output current, A logic gate drives a load, which has...

A logic gate drives a load, which has a resistance of 1 kÙ and a capacitance of 20 pF. The printed circuit track connecting the gate to its load has an 40 pF capacitance to ground.

Mips instruction - set and explain the restrict pipelining, 1.  Consider th...

1.  Consider these two potential additions to the MIPS instruction set and explain how they would restrict pipelining. a)  cp d1(r1), d2(r2) copy contents of word at address

Control flow in distributed enrollment protocol , Control Flow: Once the c...

Control Flow: Once the client has established a network connection with a server, the server must instantiate a new, empty, BasicEnrollmentManager implementation for this client,

Long term evolution and network requirements-ethernet , You are a network c...

You are a network consultant working for a large European networVservice provider and have been given the task of reviewing the future network requirements of the company for its f

What do you mean by auto-reconfiguration, What do you mean by Beaconing an...

What do you mean by Beaconing and Auto-Reconfiguration? When a station does not receive a message from its nearest active upstream neighbor, it sends out a warning, otherwise c

Network virtual terminal - transport layer , Normal 0 false f...

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

When a switch is said to be congested, When a switch is said to be congeste...

When a switch is said to be congested? It is possible that a switch receives packets faster than the shared link can accommodate and keeps in its memory, for an extended period

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