





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: S-Gen Purpose Cmptn-GPU; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Spring 2006;
Typology: Study notes
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















!"
$ %&
%
'
'
'
'
( )'
( *
+
'
,
&
%
'
'
'
'
(
'
&'
/ !
!(
!
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(
&
' &
&
, 3
&
( & !!
&
!
!! ! (
0 !,
D ( ( '
3 *
&
,
A
'
,<
!
'
+"
7 "
! '
& &
! !6 ! '
!