view libgomp/testsuite/libgomp.oacc-c-c++-common/parallel-reduction.c @ 138:fc828634a951

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:17:14 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* { dg-do run } */
/* { dg-additional-options "-w" } */

#include <stdlib.h>
#include <openacc.h>

#define N 10

int
main ()
{
  int s1 = 0, s2 = 0;
  int i;
  int dummy = 0;

#pragma acc data copy (dummy)
  {
#pragma acc parallel num_gangs (N) reduction (+:s1) copy(s1)
    {
      s1++;
    }
  }

  if (acc_get_device_type () == acc_device_host)
    {
      if (s1 != 1)
	abort ();
    }
  else
    {
      if (s1 != N)
	abort ();
    }

  s1 = 0;
  s2 = 0;

#pragma acc parallel num_gangs (10) reduction (+:s1, s2) copy(s1, s2)
  {
    s1++;
    s2 += N;
  }

  if (acc_get_device_type () == acc_device_host)
    {
      if (s1 != 1)
	abort ();
      if (s2 != N)
	abort ();
    }
  else
    {
      if (s1 != N)
	abort ();
      if (s2 != N*N)
	abort ();
    }

  s1 = 0;

#pragma acc parallel num_gangs (10) reduction (+:s1) copy(s1)
  {
#pragma acc loop gang reduction (+:s1)
    for (i = 0; i < 10; i++)
      s1++;
  }

  if (s1 != N)
    abort ();

  return 0;
}