Show the programmes for parallel systems, Computer Engineering

Assignment Help:

Q. Show the Programmes for Parallel Systems?

Adding elements of an array using two processor    

 int sum, A[ n] ;  //shared variables                                                                                              

void main ( ){

                         int i ;

for (i=0; i

scanf ("%d",&A[i] );                                                                                                   

sum=0;                                                                                                                         

// now create process to be executed 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 executed 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 last half of array is passed to processor P1 that adds them. For the meantime processor P0 adds the first half of array. The variable sum is locked to avoid inconsistency.


Related Discussions:- Show the programmes for parallel systems

What are spa/gpa parameters (sap memory), What are SPA/GPA parameters (SAP ...

What are SPA/GPA parameters (SAP memory) SPA/GPA parameters are field values saved globally in memory.  There are two ways to use SPA/GPA parmeters: By setting field attrib

When will the current screen processing terminates, When will the current s...

When will the current screen processing terminates? A current screen processing terminates when control reaches either a Leave-screen or the end of PAI.

How 2-domain name servers contain exactly same set of names, Does it makes ...

Does it makes sense for two domain name servers to contain exactly the same set of names? Why? Yes. This is very advantageous for two domain servers having similar set of names

Conversion of fractional number into its binary number, Conversion of fract...

Conversion of fractional number 0.6875 into its equivalent binary number ? Ans. Multiply the fractional number 0.6875 with 2 until the remainder becomes 0 that is, Ther

Define edge-triggered s-r flip-flop, Define Edge-triggered S-R flip-flop ...

Define Edge-triggered S-R flip-flop Basic Symbol small triangle, called the dynamic input indicator, is used to identify an edge-triggered flip-flop. Truth Table.

Gustafsons law, Amdahl's law is suitable for applications where response ti...

Amdahl's law is suitable for applications where response time is critical. On the other hand, there are a lot of applications which need that accuracy of the resultant output shoul

Gralands robots, You have been contacted by Jean-Luc Picard commanding offi...

You have been contacted by Jean-Luc Picard commanding officer of Star Trek: The Next Generation. The Commander needs your support to develop a software routine to simulate the Robo

user to enter the weight, A red and blue car were involved in a head-on co...

A red and blue car were involved in a head-on collision. The red car was at a standstill and the blue car was possibly  speeding. Eye witness video recorded suddenly following the

Storage devices, Logic manufactures have produced 'large scale' logic (LSI)...

Logic manufactures have produced 'large scale' logic (LSI) blocks to achieve complex functions; a typical set of logic functions is that of data storage. There are two main types o

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