summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cilk-plus/CK/fib-tplt.cc
blob: dbc2da881a9e04ffe17486779a049e08ef573114 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* { dg-options "-fcilkplus" } */
/* { dg-do run { target i?86-*-* x86_64-*-* arm*-*-* } } */
/* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* arm*-*-*-* } } } */

struct fib_struct
{
  int x;
  int *y;
  int z[3];
  struct fib_struct *ptr_next;
  struct fib_struct operator+(struct fib_struct &other) {
    struct fib_struct z ;
     z.x = (*this).x + (other.x);
    return z; 
  }
  struct fib_struct operator-(int other) {
    struct fib_struct z ;
    z.x = this->x - other;
    return z;
  }
  bool operator<(int number) {
   return (this->x < number);
  }
    
};

template <typename T>
T fib (T z) {
    if (z < 2) return z;
    T a = _Cilk_spawn fib<T>(z - 1);
    T b = fib<T>(z - 2);
    T c = a + b;
    return (a+b);
}


int sfib(int x)
{
  if (x < 2) return x;
  int a = sfib(x-1);
  int b = sfib(x-2);
  return (a+b);
}

int main () {
     int z = 30;
     int parallel_fib = fib<int>(z);
     int serial_fib = sfib(z);
    if (serial_fib != parallel_fib) 
      __builtin_abort ();
    
    return 0;
}