summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/loop-transforms/tile-2.C
blob: 780421fa4c75069b935d398d561562481269307d (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// { dg-additional-options "-std=c++11" }
// { dg-additional-options "-O0" }

#include <vector>
#include <stdio.h>

constexpr unsigned fib (unsigned n)
{
  return n <= 2 ? 1 : fib (n-1) + fib (n-2);
}

int
test1 ()
{
  std::vector<int> v;

  for (unsigned i = 0; i <= 9; i++)
    v.push_back (1);

  int sum = 0;
  for (int k = 0; k < 10; k++)
    #pragma omp tile sizes(fib(4))
    for (int i : v) {
      for (int j = 8; j != -2; --j)
	sum = sum + i;
    }

  return sum;
}

int
test2 ()
{
  std::vector<int> v;

  for (unsigned i = 0; i <= 10; i++)
    v.push_back (i);

  int sum = 0;
  for (int k = 0; k < 10; k++)
#pragma omp parallel for collapse(2) reduction(+:sum)
#pragma omp tile sizes(fib(4), 1)
  for (int i : v)
    for (int j = 8; j > -2; --j)
	sum = sum + i;

  return sum;
}

int
main ()
{
  int result = test1 ();

  if (result != 1000)
    {
      fprintf (stderr, "%d: Wrong result: %d\n", __LINE__, result);
      __builtin_abort ();
    }

  result = test2 ();
  if (result != 5500)
    {
      fprintf (stderr, "%d: Wrong result: %d\n", __LINE__, result);
    __builtin_abort ();
    }

  return 0;
}