gcc/libgomp/testsuite/libgomp.c-c++-common/taskloop-4.c
Jakub Jelinek 3bc75533d1 openmp: Add support for strict modifier on grainsize/num_tasks clauses
With strict: modifier on these clauses, the standard is explicit about
how many iterations (and which) each generated task of taskloop directive
should contain.  For num_tasks it actually matches what we were already
implementing, but for grainsize it does not (and even violates the old
rule - without strict it requires that the number of iterations (unspecified
which exactly) handled by each generated task is >= grainsize argument and
< 2 * grainsize argument, with strict: it requires that each generated
task handles exactly == grainsize argument iterations, except for the
generated task handling the last iteration which can handles <= grainsize
iterations).

The following patch implements it for C and C++.

2021-08-23  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree.h (OMP_CLAUSE_GRAINSIZE_STRICT): Define.
	(OMP_CLAUSE_NUM_TASKS_STRICT): Define.
	* tree-pretty-print.c (dump_omp_clause) <case OMP_CLAUSE_GRAINSIZE,
	case OMP_CLAUSE_NUM_TASKS>: Print strict: modifier.
	* omp-expand.c (expand_task_call): Use GOMP_TASK_FLAG_STRICT in iflags
	if either grainsize or num_tasks clause has the strict modifier.
gcc/c/
	* c-parser.c (c_parser_omp_clause_num_tasks,
	c_parser_omp_clause_grainsize): Parse the optional strict: modifier.
gcc/cp/
	* parser.c (cp_parser_omp_clause_num_tasks,
	cp_parser_omp_clause_grainsize): Parse the optional strict: modifier.
include/
	* gomp-constants.h (GOMP_TASK_FLAG_STRICT): Define.
libgomp/
	* taskloop.c (GOMP_taskloop): Handle GOMP_TASK_FLAG_STRICT.
	* testsuite/libgomp.c-c++-common/taskloop-4.c (main): Fix up comment.
	* testsuite/libgomp.c-c++-common/taskloop-5.c: New test.
2021-08-23 10:16:24 +02:00

99 lines
2.2 KiB
C

/* { dg-do run } */
/* { dg-options "-O2" } */
int u[64], v;
__attribute__((noinline, noclone)) int
test (int a, int b, int c, int d, void (*fn) (int, int, int, int),
int *num_tasks, int *min_iters, int *max_iters)
{
int i, t = 0;
__builtin_memset (u, 0, sizeof u);
v = 0;
fn (a, b, c, d);
*min_iters = 0;
*max_iters = 0;
*num_tasks = v;
if (v)
{
*min_iters = u[0];
*max_iters = u[0];
t = u[0];
for (i = 1; i < v; i++)
{
if (*min_iters > u[i])
*min_iters = u[i];
if (*max_iters < u[i])
*max_iters = u[i];
t += u[i];
}
}
return t;
}
void
grainsize (int a, int b, int c, int d)
{
int i, j = 0, k = 0;
#pragma omp taskloop firstprivate (j, k) grainsize(d)
for (i = a; i < b; i += c)
{
if (j == 0)
{
#pragma omp atomic capture
k = v++;
if (k >= 64)
__builtin_abort ();
}
u[k] = ++j;
}
}
void
num_tasks (int a, int b, int c, int d)
{
int i, j = 0, k = 0;
#pragma omp taskloop firstprivate (j, k) num_tasks(d)
for (i = a; i < b; i += c)
{
if (j == 0)
{
#pragma omp atomic capture
k = v++;
if (k >= 64)
__builtin_abort ();
}
u[k] = ++j;
}
}
int
main ()
{
#pragma omp parallel
#pragma omp single
{
int min_iters, max_iters, ntasks;
/* If grainsize is present, # of task loop iters is >= grainsize && < 2 * grainsize,
unless # of loop iterations is smaller than grainsize. */
if (test (0, 79, 1, 17, grainsize, &ntasks, &min_iters, &max_iters) != 79
|| min_iters < 17 || max_iters >= 17 * 2)
__builtin_abort ();
if (test (-49, 2541, 7, 28, grainsize, &ntasks, &min_iters, &max_iters) != 370
|| min_iters < 28 || max_iters >= 28 * 2)
__builtin_abort ();
if (test (7, 21, 2, 15, grainsize, &ntasks, &min_iters, &max_iters) != 7
|| ntasks != 1 || min_iters != 7 || max_iters != 7)
__builtin_abort ();
/* If num_tasks is present, # of tasks is min (# of loop iters, num_tasks)
and each task has at least one iteration. */
if (test (-51, 2500, 48, 9, num_tasks, &ntasks, &min_iters, &max_iters) != 54
|| ntasks != 9)
__builtin_abort ();
if (test (0, 25, 2, 17, num_tasks, &ntasks, &min_iters, &max_iters) != 13
|| ntasks != 13)
__builtin_abort ();
}
return 0;
}