view libgomp/testsuite/libgomp.c++/taskloop-5.C @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 04ced10e8804
children
line wrap: on
line source

#include <omp.h>

__attribute__((noinline, noclone)) void
foo (int &b)
{
#pragma omp parallel
#pragma omp single
  {
    bool f = false;
  #pragma omp taskloop firstprivate (b, f)
    for (int i = 0; i < 30; i++)
      {
	int q = omp_get_thread_num ();
	if (!f)
	  {
	    if (b != 2)
	      __builtin_abort ();
	  }
	else if (b != 8 * q)
	  __builtin_abort ();
	b = 8 * q;
	f = true;
      }
  }
  int n;
#pragma omp parallel
#pragma omp single
  {
    bool f = false;
  #pragma omp taskloop firstprivate (f) lastprivate (b, n)
    for (int i = 0; i < 30; i++)
      {
	int q = omp_get_thread_num ();
	if (f && b != 8 * q)
	  __builtin_abort ();
	b = 8 * q;
	n = q;
	f = true;
      }
  }
  if (b != 8 * n)
    __builtin_abort ();
  b = 9;
#pragma omp parallel
#pragma omp single
  {
    bool f = false;
  #pragma omp taskloop firstprivate (b, f) lastprivate (b, n)
    for (int i = 0; i < 30; i++)
      {
	int q = omp_get_thread_num ();
	if (!f)
	  {
	    if (b != 9)
	      __builtin_abort ();
	  }
	else if (b != 11 * q)
	  __builtin_abort ();
	b = 11 * q;
	n = q;
	f = true;
      }
  }
  if (b != 11 * n)
    __builtin_abort ();
}

int
main ()
{
  int b = 2;
  foo (b);
}