gcc/libgomp/testsuite/libgomp.c-c++-common/target-imperfect1.c
Sandra Loosemore 410df0843d OpenMP: New C/C++ testcases for imperfectly nested loops.
gcc/testsuite/ChangeLog
	* c-c++-common/gomp/imperfect-attributes.c: New.
	* c-c++-common/gomp/imperfect-badloops.c: New.
	* c-c++-common/gomp/imperfect-blocks.c: New.
	* c-c++-common/gomp/imperfect-extension.c: New.
	* c-c++-common/gomp/imperfect-gotos.c: New.
	* c-c++-common/gomp/imperfect-invalid-scope.c: New.
	* c-c++-common/gomp/imperfect-labels.c: New.
	* c-c++-common/gomp/imperfect-legacy-syntax.c: New.
	* c-c++-common/gomp/imperfect-pragmas.c: New.
	* c-c++-common/gomp/imperfect1.c: New.
	* c-c++-common/gomp/imperfect2.c: New.
	* c-c++-common/gomp/imperfect3.c: New.
	* c-c++-common/gomp/imperfect4.c: New.
	* c-c++-common/gomp/imperfect5.c: New.

libgomp/ChangeLog
	* testsuite/libgomp.c-c++-common/imperfect1.c: New.
	* testsuite/libgomp.c-c++-common/imperfect2.c: New.
	* testsuite/libgomp.c-c++-common/imperfect3.c: New.
	* testsuite/libgomp.c-c++-common/imperfect4.c: New.
	* testsuite/libgomp.c-c++-common/imperfect5.c: New.
	* testsuite/libgomp.c-c++-common/imperfect6.c: New.
	* testsuite/libgomp.c-c++-common/target-imperfect1.c: New.
	* testsuite/libgomp.c-c++-common/target-imperfect2.c: New.
	* testsuite/libgomp.c-c++-common/target-imperfect3.c: New.
	* testsuite/libgomp.c-c++-common/target-imperfect4.c: New.
2023-08-25 19:42:50 +00:00

81 lines
1.6 KiB
C

/* { dg-do run } */
/* Like imperfect1.c, but enables offloading. */
static int f1count[3], f2count[3];
#pragma omp declare target enter (f1count, f2count)
#ifndef __cplusplus
extern void abort (void);
#else
extern "C" void abort (void);
#endif
int f1 (int depth, int iter)
{
#pragma omp atomic
f1count[depth]++;
return iter;
}
int f2 (int depth, int iter)
{
#pragma omp atomic
f2count[depth]++;
return iter;
}
void s1 (int a1, int a2, int a3)
{
int i, j, k;
#pragma omp target parallel for collapse(3) map(always, tofrom:f1count, f2count)
for (i = 0; i < a1; i++)
{
f1 (0, i);
for (j = 0; j < a2; j++)
{
f1 (1, j);
for (k = 0; k < a3; k++)
{
f1 (2, k);
f2 (2, k);
}
f2 (1, j);
}
f2 (0, i);
}
}
int
main (void)
{
f1count[0] = 0;
f1count[1] = 0;
f1count[2] = 0;
f2count[0] = 0;
f2count[1] = 0;
f2count[2] = 0;
s1 (3, 4, 5);
/* All intervening code at the same depth must be executed the same
number of times. */
if (f1count[0] != f2count[0]) abort ();
if (f1count[1] != f2count[1]) abort ();
if (f1count[2] != f2count[2]) abort ();
/* Intervening code must be executed at least as many times as the loop
that encloses it. */
if (f1count[0] < 3) abort ();
if (f1count[1] < 3 * 4) abort ();
/* Intervening code must not be executed more times than the number
of logical iterations. */
if (f1count[0] > 3 * 4 * 5) abort ();
if (f1count[1] > 3 * 4 * 5) abort ();
/* Check that the innermost loop body is executed exactly the number
of logical iterations expected. */
if (f1count[2] != 3 * 4 * 5) abort ();
}