Example programmes for parallel systems-adding element, Computer Networking

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.

Posted Date: 3/4/2013 5:19:31 AM | Location : United States







Related Discussions:- Example programmes for parallel systems-adding element, Assignment Help, Ask Question on Example programmes for parallel systems-adding element, Get Answer, Expert's Help, Example programmes for parallel systems-adding element Discussions

Write discussion on Example programmes for parallel systems-adding element
Your posts are moderated
Related Questions
What are IP addresses? IP address refers to the name of a computer on a network, like the Internet. An Identifier for a computer or device on a TCP/IP network, like the

Q. What is network layer of osi model? - Describe end-to-end delivery of packets. - Defines logical addressing thus that any endpoint can be identified. - Defines how ro

When you move the NIC cards from one PC to another PC, does the MAC address gets transferred as well? Yes, that's because MAC addresses are hard-wired into the NIC circuitry, n


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

Illustrate about the working of Socks protocol SOCKS is an open, industry-standard protocol advanced by the Authenticated Firewall Traversal working group of the IETF (Internet

Distance covered, Based on size, ownership and physical architecture - LAN (Local Area Network) - Suitable for smaller geographical area - MAN (Metropolitan Area Network) - S

Explain how the lan model be developed The LAN model can be developed incrementally. If LAN is just a long cable. it cannot be brought down by single failure (if servers are re

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

What advantages does fiber optics have over other media? One main advantage of fiber optics is that is it less susceptible to electrical interference. It also supports higher ba