LLVM OpenMP
runtime
test
transform
flatten
parallel-wsloop-foreach.cpp
Go to the documentation of this file.
1
// RUN: %libomp-cxx-compile -fopenmp-version=61 && %libomp-run \
2
// RUN: | FileCheck %s --match-full-lines
3
4
#ifndef HEADER
5
#define HEADER
6
7
#include <cstdio>
8
#include <cstdlib>
9
#include <omp.h>
10
11
enum
{
NThreads
= 2,
MaxIters
= 4 };
12
13
static
void
dump
(
const
char
*Tag,
int
Count
[
NThreads
],
14
int
Pairs[
NThreads
][
MaxIters
][2]) {
15
printf(
"%s\n"
, Tag);
16
for
(
int
T = 0; T <
NThreads
; ++T) {
17
printf(
"tid=%d count=%d\n"
, T,
Count
[T]);
18
for
(
int
K = 0; K <
Count
[T]; ++K)
19
printf(
"tid=%d i=%d j=%d\n"
, T, Pairs[T][K][0], Pairs[T][K][1]);
20
}
21
}
22
23
int
main
() {
24
int
Is[] = {0, 1};
25
int
Js[] = {0, 1};
26
int
Count
[
NThreads
] = {};
27
int
Pairs[
NThreads
][
MaxIters
][2];
28
29
#pragma omp parallel for schedule(static, 1) num_threads(2)
30
#pragma omp flatten
31
for
(
int
i
: Is)
32
for
(
int
j
: Js) {
33
int
T = omp_get_thread_num();
34
int
C
=
Count
[T]++;
35
Pairs[T][
C
][0] =
i
;
36
Pairs[T][
C
][1] =
j
;
37
}
38
dump
(
"with-flatten"
,
Count
, Pairs);
39
40
return
EXIT_SUCCESS;
41
}
42
43
#endif
/* HEADER */
44
45
// The flattened range-based product has four iterations. Static scheduling
46
// gives each thread alternating logical iterations.
47
// CHECK: with-flatten
48
// CHECK-NEXT: tid=0 count=2
49
// CHECK-NEXT: tid=0 i=0 j=0
50
// CHECK-NEXT: tid=0 i=1 j=0
51
// CHECK-NEXT: tid=1 count=2
52
// CHECK-NEXT: tid=1 i=0 j=1
53
// CHECK-NEXT: tid=1 i=1 j=1
i
#define i
Definition
kmp_stub.cpp:88
C
#define C
Definition
omp_nonmonotonic_nowait.c:10
j
int j
Definition
omp_single_copyprivate.c:6
Count
static int Count
Definition
overflow-empty.c:8
dump
static void dump(const char *Tag, int Count[NThreads], int Pairs[NThreads][MaxIters][2])
Definition
parallel-wsloop-foreach.cpp:13
NThreads
@ NThreads
Definition
parallel-wsloop-foreach.cpp:11
MaxIters
@ MaxIters
Definition
parallel-wsloop-foreach.cpp:11
main
int main()
Definition
parallel-wsloop-foreach.cpp:23
Generated on
for LLVM OpenMP by
1.14.0