aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
blob: 4bf62c3828f3f52ab7fe01f213196b2a1d5a8d45 (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
/* { dg-do run } */
/* { dg-additional-options "-foffload-options=nvptx-none=-latomic" { target offload_target_nvptx } } */

#include <stdlib.h>

#define N 512

#define GENERATE_TEST(T)	\
int test_##T (void)		\
{				\
  T a[N], res = 0;		\
				\
  for (int i = 0; i < N; ++i)	\
    a[i] = i & 1;		\
				\
_Pragma("omp target teams distribute reduction(||:res) defaultmap(tofrom:scalar)") \
  for (int i = 0; i < N; ++i)	\
    res = res || a[i];		\
				\
  /* res should be non-zero.  */\
  if (!res)			\
    return 1;			\
				\
_Pragma("omp target teams distribute reduction(&&:res) defaultmap(tofrom:scalar)") \
  for (int i = 0; i < N; ++i)	\
    res = res && a[i];		\
				\
  /* res should be zero.  */	\
  return res;			\
}

GENERATE_TEST(char)
GENERATE_TEST(short)
GENERATE_TEST(int)
GENERATE_TEST(long)
#ifdef __SIZEOF_INT128__
GENERATE_TEST(__int128)
#endif

int main(void)
{
  if (test_char ())
    abort ();
  if (test_short ())
    abort ();
  if (test_int ())
    abort ();
  if (test_long ())
    abort ();
#ifdef __SIZEOF_INT128__
  if (test___int128 ())
    abort ();
#endif
}