Cilk - Parallel and Concurrent Programming - Notes | CMPSCI 691, Study notes of Computer Science

Material Type: Notes; Class: S-Gen Purpose Cmptn-GPU; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Spring 2006;

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-bgp
koofers-user-bgp 🇺🇸

4.5

(2)

10 documents

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
  
  
 
 
  
  
    
     
!
" " #
$

 

pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download Cilk - Parallel and Concurrent Programming - Notes | CMPSCI 691 and more Study notes Computer Science in PDF only on Docsity!



 

 



 

  

    !"

$ %&





  



 %

 '

'

'

  

 

'

 ( )'

( *



+ 









'

,

& 



 %

 '

'

'

  

 

'

 ( 







 

 

 





 '



   &'

   



/ ! 

!( 

      !



0

    '

'

'

! 

!( 



2     3 '





 &

 (      !



 ( 



  !'

 !   



    

  

! (  

!

  4  !   

.

  5









 

  







)( '

'

3 !

67 ,'

'

2  





* '



!



 

 

'

6

( '



'



 )  9 :  08



9* '



!



(     '



 

6

-  

 &

8



9* '



!



   

 "

60

  



9* '



!



     



 

6

! '

  8



9

'% )   

*

 

6& 

 * '



!



6



fork()



+,







  • ) ( '

/    !!



 

 

   





( !(  ! (  

!

  





;











  

  

int

main

(int

argc, char

*argv[])

{

int

n,

result;

n

=

atoi(argv[1]);

result

= fib(n);

printf(“Result:%d\n”,

result);

return

0;

}

int

fib (int

n)

{

if

(n<2) return n;

else {

int x, y;x

= fib

(n-1);

y

= fib

(n-2);

return (x+y);

}

}





    

cilk

int

main

(int

argc, char

*argv[])

{

int

n,

result;

n

=

atoi(argv[1]);

result

=

spawn

fib(n);

sync

;

printf(“Result:%d\n”,

result);

return

0;

}

cilk

int

fib

(int n)

{

if

(n<2) return n;

else {

int x, y;x

=

spawn

fib (n-1);

y

=

spawn

fib (n-2);

sync

;

return (x+y);

}

}



  

 



 !'

'

 (  



*!(   

  • 



3 (   ,

0  $1' 

 " ') (  

 "

8

!    



2  $

? (   

    

*!(  !  ( 

  

'

'





 





 )

 " )

?*!( 

  



  

 

 

 ( 3    ! 



2  $1 

' 

 

 







 



.!  ( '



  &  3 

  

3 '



 !

 !



!'

 



!    "



/ (  

    '

'

'

'

!, 



/ A B / C 

@ 



!



 3 

 

   

 

 D ( '











@



  , &  



!



?+



@





!





@





 









 



.  , & 



!$ 



 







 

  



  , D ( !,  (  

   

    

 !'

'

   

.   



(    ,

'

 

 

      ,E  D ( 

   '

 3  ! 

'

 

'%   

 %   

  3 " ( % ') (  



 '

  ( 

   &

   !   ! ( 

!





 !   !4 



" 





 '





   

 

  

cilk

int

fib

(int n)

{

if

(n<2) return n;

else {

int x, y;x

=

spawn

fib (n-1);

y

=

spawn

fib (n-2);

sync

;

return (x+y);

}

}



1

int

fib (int

n)

2

{

3

fib_frame

*f;

frame

pointer

4

f

= alloc(sizeof(f));*

allocate frame

5

f->sig =

fib_sig;

initialize

frame

6

if (n<2)

{

7

free(f,

sizeof(f));*

free

frame

8

return

n;

9

}

10

else

{ …

}

   

 

  



$

%

 





2       ! (  '









'

 !'

  

3 ( (    !  !(  *!( 

 



B    ! (  4   ! ( ( 

 !      

 D ( 



'

'



 

'% 

,!'

'

 (  



 ! !,  ! 

'

  E( 



  &

' &

&





 



  • D (   '

 

    

  ,  3     

& 



(  & !!   



     



  &

!

 !!  ! ( 





0 !,

  D (    ( '

 3 *  

& 

  ,

A 

 '

  ,<

 

 !

 '





+"

7 "

   ! '

 & &   

!   !6  !  '



!