summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-5.c
blob: 16aa0dd4ac12fde9cde414cd6009bc47dd50c574 (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
/* { dg-additional-options "-Wopenacc-parallelism" } for testing/documenting
   aspects of that functionality.  */

/* Multiple reductions.  */

#include <stdio.h>
#include <stdlib.h>

#define ng 8
#define nw 4
#define vl 32

const int n = 100;

#define DO_PRAGMA(x) _Pragma (#x) /* { dg-line pragma_loc } */

#define check_reduction(gwv_par, gwv_loop)		\
  {							\
  s1 = 2; s2 = 5;					\
DO_PRAGMA (acc parallel gwv_par copy (s1, s2))		\
DO_PRAGMA (acc loop gwv_loop reduction (+:s1, s2))	\
    for (i = 0; i < n; i++)				\
      {							\
         s1 = s1 + 3;					\
         s2 = s2 + 5;					\
      }							\
							\
    if (s1 != v1 && s2 != v2)				\
      abort ();						\
  }

int
main (void)
{
  int s1 = 2, s2 = 5, v1 = 2, v2 = 5;
  int i;

  for (i = 0; i < n; i++)
    {
      v1 = v1 + 3;
      v2 = v2 + 2;
    }

  check_reduction (num_gangs (ng), gang);

  /* Nvptx targets require a vector_length or 32 in to allow spinlocks with
     gangs.  */
  check_reduction (num_workers (nw) vector_length (vl), worker);
  /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "test1" { target *-*-* } pragma_loc } */
  check_reduction (vector_length (vl), vector);
  check_reduction (num_gangs (ng) num_workers (nw) vector_length (vl), gang
		   worker vector);

  return 0;
}