From 3bc75533d1f87f0617be6c1af98804f9127ec637 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 23 Aug 2021 10:16:24 +0200 Subject: 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 gcc/ * tree.h (OMP_CLAUSE_GRAINSIZE_STRICT): Define. (OMP_CLAUSE_NUM_TASKS_STRICT): Define. * tree-pretty-print.c (dump_omp_clause) : 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. --- libgomp/taskloop.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'libgomp/taskloop.c') diff --git a/libgomp/taskloop.c b/libgomp/taskloop.c index 791178a..9d27dd0 100644 --- a/libgomp/taskloop.c +++ b/libgomp/taskloop.c @@ -97,6 +97,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), #endif TYPE task_step = step; + TYPE nfirst_task_step = step; unsigned long nfirst = n; if (flags & GOMP_TASK_FLAG_GRAINSIZE) { @@ -109,7 +110,22 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), if (num_tasks != ndiv) num_tasks = ~0UL; #endif - if (num_tasks <= 1) + if ((flags & GOMP_TASK_FLAG_STRICT) + && num_tasks != ~0ULL) + { + UTYPE mod = n % grainsize; + task_step = (TYPE) grainsize * step; + if (mod) + { + num_tasks++; + nfirst_task_step = (TYPE) mod * step; + if (num_tasks == 1) + task_step = nfirst_task_step; + else + nfirst = num_tasks - 2; + } + } + else if (num_tasks <= 1) { num_tasks = 1; task_step = end - start; @@ -124,6 +140,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), task_step = (TYPE) grainsize * step; if (mul != n) { + nfirst_task_step = task_step; task_step += step; nfirst = n - mul - 1; } @@ -135,6 +152,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), task_step = (TYPE) div * step; if (mod) { + nfirst_task_step = task_step; task_step += step; nfirst = mod - 1; } @@ -153,6 +171,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), task_step = (TYPE) div * step; if (mod) { + nfirst_task_step = task_step; task_step += step; nfirst = mod - 1; } @@ -225,7 +244,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), start += task_step; ((TYPE *)arg)[1] = start; if (i == nfirst) - task_step -= step; + task_step = nfirst_task_step; fn (arg); arg += arg_size; if (!priority_queue_empty_p (&task[i].children_queue, @@ -258,7 +277,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), start += task_step; ((TYPE *)data)[1] = start; if (i == nfirst) - task_step -= step; + task_step = nfirst_task_step; fn (data); if (!priority_queue_empty_p (&task.children_queue, MEMMODEL_RELAXED)) @@ -303,7 +322,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), start += task_step; ((TYPE *)arg)[1] = start; if (i == nfirst) - task_step -= step; + task_step = nfirst_task_step; thr->task = parent; task->kind = GOMP_TASK_WAITING; task->fn = fn; -- cgit v1.1