File: cilk1.cilk

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (34 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cilk-lib.cilkh>
// stdlib.h invokes waitstatus.h;  In Cilk-5.4.6, cilkc can't handle some
//  of that syntax on Ubuntu 11.10, and many other distros.
// atoi uses stdlib.h
// #include <stdlib.h>
int atoi (char *number);
#include <stdio.h>

// Usage:  THIS_FILE <number>

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);
  }
}

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;
}