Lecture Summary ½ Compiling Cilk

 ! "
#$ " #
$
% ! ! #& #$ # # $ !
! $ # # $ $ $ ' # ( ) $ * !+, - # . / &# ½ ½ 0
1 $ # &# ½
2
½
/ # $ #
(
# ½
½
2 ½
½
34
"
½ ½ $ % ( ½ ½ + $ 34 $ . $ ½ ½ !
Cilk
source
source-to-source
translator
cilk2c
Cilk Run Time System
C compiler
C postsource
gcc
Cilk
RTS
object
code
ld
binary
linking
loader
# ' # $ #$ ! $ # ( ( # $ - #!½
"
# $ ( ( ½ $ 34
5 # % ) ( #$ 6 $
# # $ # ) # ( !"
" #$ %# #½ !
SLOW
FAST
FAST
FAST
FAST
FAST
!
"
# $
# %
&
'
( )
#$ % 7 8 # $ # * 5 )
( & # * #$ *
) # # ( ( # ) !
5 % 9 # (
% 8 8 ( $ 5 # + $
% 8 # ( 5 % 8 # # !7
Cilk
source
frame
x = spawn fib(n-1);
cilk2c
C postsource
entry
join
n
x
y
frame->entry = 1;
frame->n = n;
push(frame);
suspend
parent
entry
join
x = fib(n-1);
run child
if (pop() == FAILURE)
{ frame->x = x;
frame->join--;
[clean up & return
to scheduler ]
}
Cilk
deque
resume
parent
remotely
Cilk
source
SLOW
FAST
FAST
FAST
FAST
FAST
sync;
cilk2c
C postsource
;
( # # $ # # . ½ $ 34
"
$ #$ ( * ( ! % : ( # $%
Æ$ ) $ # #$ %# # #
!
% ; ! # +
5 #
# : # $ $
!9
void fib_slow(fib_frame *frame)
{
int n,x,y;
switch (frame->entry) {
restore
case 1: goto L1;
program
case 2: goto L2;
case 3: goto L3;
counter
}
. . .
frame->entry = 1;
frame->n = n;
push(frame);
same
x = fib(n-1);
if (pop() == FAILURE)
as fast
{ frame->x = x;
clone
frame->join--;
[clean up & return
to scheduler ]
}
}
if (0) {
L1:;
n = frame->n;
}
. . .
sync;
if (frame->join > 0)
{
[clean up & return
to scheduler]
};
Cilk
deque
cilk2c
C postsource
entry
join
n
x
y
entry
join
restore local
variables
if resuming
continue
Cilk
source
frame
SLOW
FAST
FAST
FAST
FAST
FAST
& < $ $ # . ( $ : $ 6 $ $ # ½ $ 34 3#$! 4 $ # # $ !8
"! !$ $ ) $ $
# Æ$
# " + + $ #
$ ( # ( # ( ) !# % = . #$ # > #$ # . $ #$ ( + $ + #$ $ $ $ # $ # % % ? "
$ $
# $ 1
# > $ #
$ !:
+ ,''
"
,
$
- . , %
,''
&
/
(
,
)
- . , ,''
/
012/345
"
/
$
%
63566
&
/
-''
- . , "
-
$
/
%
012/345
&
(
/
) 63566
& '
&'
1
2
3
4
5
11
00
00
11
00
11
00
11
00
11
00
11
11
00
00
11
00
11
00
11
00
11
00
11
11
00
00
11
00
11
00
11
00
11
00
11
11
00
00
11
00
11
00
11
00
11
00
11
11
00
H
11
00
00
11
00
11
00
11
00
11
00
11
00
11
H=T
H
T
T
6
(a)
(b)
(c)
!;
+ ,''
/
5''
-''
"
- . , $
5
%
-''
&
/
(
012/345
) /
63566
" ,
$ 5 . , %
,''
&
/
(
,
)
- . , ,''
/
012/345
"
/
$ % 63566
& & '
&'
$ # #
$ $ $ 7 $ 5 $ $
# @
$ '$
$ : A $ $ 3#4 #
#
$ $ #
#$ # !
B ( ( ( $ - #- $ % # ( % ( C ( ( 5 $ ( $ > > ( !=
+ ( $ + ( # # 5
# #! ( ( ?