File: bin_cilk_dr.cilk

package info (click to toggle)
massivethreads 1.02-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,924 kB
  • sloc: ansic: 27,814; sh: 4,559; cpp: 3,334; javascript: 1,799; makefile: 1,745; python: 523; asm: 373; perl: 118; lisp: 9
file content (28 lines) | stat: -rw-r--r-- 497 bytes parent folder | download
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
#include <stdio.h>
#include <stdlib.h>
#include <tpswitch/cilk_dr.cilkh>

cilk long bin(int n) {
  cilk_begin;
  if (n == 0) cilk_return(1);
  else {
    long x, y;
    spawn_(x = spawn bin(n - 1));
    spawn_(y = spawn bin(n - 1));
    sync_;
    cilk_return(x + y);
  }
}

cilk int main(int argc, char ** argv) {
  cilk_begin;
  int n = atoi(argv[1]);
  long x;
  dr_start(0);
  spawn_(x = spawn bin(n));
  sync_;
  dr_stop();
  printf("bin(%d) = %ld\n", n, x);
  dr_dump();
  cilk_return(0);
}