view libgomp/testsuite/libgomp.c-c++-common/taskloop-reduction-3.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
line wrap: on
line source

/* { dg-do run } */
/* { dg-options "-O2" } */
/* { dg-additional-options "-std=c99" { target c } } */
/* { dg-additional-options "-msse2" { target sse2_runtime } } */
/* { dg-additional-options "-mavx" { target avx_runtime } } */

#define N 1024
long int u[N], m, n;

__attribute__((noipa)) void
foo (void)
{
  int i;
  #pragma omp taskloop simd reduction (+:m) grainsize (64)
  for (i = 0; i < N; ++i)
    m += u[i];
}

__attribute__((noipa)) void
bar (int x)
{
  #pragma omp taskloop simd in_reduction (+:n) grainsize (64) nogroup
  for (int i = (x & 1) * (N / 2); i < (x & 1) * (N / 2) + (N / 2); i++)
    n += 2 * u[i];
}

int
main ()
{
  int i;
  for (i = 0; i < N; ++i)
    u[i] = i;
  #pragma omp parallel master
  {
    foo ();
    #pragma omp taskgroup task_reduction (+:n)
    {
      bar (0);
      bar (1);
    }
  }
  if (m != (long)(N - 1) * (N / 2) || n != (long)(N - 1) * N)
    __builtin_abort ();
  return 0;
}