Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102419492
fibonacci.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Feb 20, 13:07
Size
583 B
Mime Type
text/x-c
Expires
Sat, Feb 22, 13:07 (2 d)
Engine
blob
Format
Raw Data
Handle
24353171
Attached To
R11821 phys-743-lecture
fibonacci.c
View Options
#include "timing.h"
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
long
int
fibonacci
(
int
n
)
{
long
int
x
,
y
;
if
(
n
<
2
)
{
return
n
;
}
else
{
#pragma omp task shared(x)
x
=
fibonacci
(
n
-
1
);
#pragma omp task shared(y)
y
=
fibonacci
(
n
-
2
);
#pragma omp taskwait
return
(
x
+
y
);
}
}
int
main
()
{
int
n
=
42
;
double
t1
,
t2
;
long
int
fib
=
0
;
t1
=
second
();
#pragma omp parallel
{
#pragma omp single nowait
{
fib
=
fibonacci
(
n
);
}
}
t2
=
second
();
printf
(
"fib(%d) = %ld (in %g [s])
\n
"
,
n
,
fib
,
(
t2
-
t1
));
return
0
;
}
Event Timeline
Log In to Comment