LLVM OpenMP
parallel-wsloop-collapse-through-tile-iterator.cpp
Go to the documentation of this file.
1// RUN: %libomp-cxx-compile-and-run | FileCheck %s --match-full-lines
2// RUN: %libomp-cxx-compile -O2 && %libomp-run | FileCheck %s --match-full-lines
3
4// collapse consuming a tiled range-based-for loop.
5
6#ifndef HEADER
7#define HEADER
8
9#include <cstdlib>
10#include <cstdio>
11
12struct Range {
13 int lo, hi;
14 struct It {
15 int v;
16 int operator*() const { return v; }
18 ++v;
19 return *this;
20 }
22 It t = *this;
23 ++v;
24 return t;
25 }
26 bool operator==(const It &o) const { return v == o.v; }
27 bool operator!=(const It &o) const { return v != o.v; }
28 int operator-(const It &o) const { return v - o.v; }
29 It operator+(int n) const { return It{v + n}; }
30 };
31 It begin() const { return It{lo}; }
32 It end() const { return It{hi}; }
33};
34
35int main() {
36 Range r{0, 5};
37
38 printf("iter2\n");
39#pragma omp parallel for collapse(2) num_threads(1)
40#pragma omp tile sizes(2)
41 for (int v : r)
42 printf("v=%d\n", v);
43
44 printf("iter3\n");
45#pragma omp parallel for collapse(3) num_threads(1)
46#pragma omp tile sizes(2)
47 for (int v : r)
48 for (int j = 0; j < 2; ++j)
49 printf("v=%d j=%d\n", v, j);
50
51 printf("done\n");
52 return EXIT_SUCCESS;
53}
54
55#endif /* HEADER */
56
57// CHECK: iter2
58// CHECK-NEXT: v=0
59// CHECK-NEXT: v=1
60// CHECK-NEXT: v=2
61// CHECK-NEXT: v=3
62// CHECK-NEXT: v=4
63// CHECK-NEXT: iter3
64// CHECK-NEXT: v=0 j=0
65// CHECK-NEXT: v=0 j=1
66// CHECK-NEXT: v=1 j=0
67// CHECK-NEXT: v=1 j=1
68// CHECK-NEXT: v=2 j=0
69// CHECK-NEXT: v=2 j=1
70// CHECK-NEXT: v=3 j=0
71// CHECK-NEXT: v=3 j=1
72// CHECK-NEXT: v=4 j=0
73// CHECK-NEXT: v=4 j=1
74// CHECK-NEXT: done