Added Compiler Support for _Cilk_spawn and _Cilk_sync for C++.
[official-gcc.git] / gcc / testsuite / g++.dg / cilk-plus / CK / fib-tplt.cc
blobdbc2da881a9e04ffe17486779a049e08ef573114
1 /* { dg-options "-fcilkplus" } */
2 /* { dg-do run { target i?86-*-* x86_64-*-* arm*-*-* } } */
3 /* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* arm*-*-*-* } } } */
5 struct fib_struct
7 int x;
8 int *y;
9 int z[3];
10 struct fib_struct *ptr_next;
11 struct fib_struct operator+(struct fib_struct &other) {
12 struct fib_struct z ;
13 z.x = (*this).x + (other.x);
14 return z;
16 struct fib_struct operator-(int other) {
17 struct fib_struct z ;
18 z.x = this->x - other;
19 return z;
21 bool operator<(int number) {
22 return (this->x < number);
27 template <typename T>
28 T fib (T z) {
29 if (z < 2) return z;
30 T a = _Cilk_spawn fib<T>(z - 1);
31 T b = fib<T>(z - 2);
32 T c = a + b;
33 return (a+b);
37 int sfib(int x)
39 if (x < 2) return x;
40 int a = sfib(x-1);
41 int b = sfib(x-2);
42 return (a+b);
45 int main () {
46 int z = 30;
47 int parallel_fib = fib<int>(z);
48 int serial_fib = sfib(z);
49 if (serial_fib != parallel_fib)
50 __builtin_abort ();
52 return 0;