summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/examples-4/declare_target-1.c
blob: 6d4bc4fac12bf61f495a8555b14847cbd656ca4e (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
/* { dg-do run } */

#include <stdlib.h>

#define THRESHOLD 20

#pragma omp declare target
int fib (int n)
{
  if (n <= 0)
    return 0;
  else if (n == 1)
    return 1;
  else
    return fib (n - 1) + fib (n - 2);
}
#pragma omp end declare target

int fib_wrapper (int n)
{
  int x = 0;

  #pragma omp target if(n > THRESHOLD) map(from:x)
    x = fib (n);

  return x;
}

int main ()
{
  if (fib (15) != fib_wrapper (15))
    abort ();
  if (fib (25) != fib_wrapper (25))
    abort ();
  return 0;
}