OMP_CLAUSE_ORDER);
OMP_CLAUSE_ORDER_UNCONSTRAINED (c)
= OMP_CLAUSE_ORDER_UNCONSTRAINED (clauses);
+ OMP_CLAUSE_ORDER_REPRODUCIBLE (c)
+ = OMP_CLAUSE_ORDER_REPRODUCIBLE (clauses);
OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE] = c;
}
OMP_CLAUSE_ORDER);
OMP_CLAUSE_ORDER_UNCONSTRAINED (c)
= OMP_CLAUSE_ORDER_UNCONSTRAINED (clauses);
+ OMP_CLAUSE_ORDER_REPRODUCIBLE (c)
+ = OMP_CLAUSE_ORDER_REPRODUCIBLE (clauses);
OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
cclauses[C_OMP_CLAUSE_SPLIT_FOR] = c;
s = C_OMP_CLAUSE_SPLIT_SIMD;
tree c;
const char *p;
bool unconstrained = false;
+ bool reproducible = false;
matching_parens parens;
if (!parens.require_open (parser))
p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
if (strcmp (p, "unconstrained") == 0)
unconstrained = true;
- else if (strcmp (p, "reproducible") != 0)
+ else if (strcmp (p, "reproducible") == 0)
+ reproducible = true;
+ else
{
c_parser_error (parser, "expected %<reproducible%> or "
"%<unconstrained%>");
check_no_duplicate_clause (list, OMP_CLAUSE_ORDER, "order");
c = build_omp_clause (loc, OMP_CLAUSE_ORDER);
OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = unconstrained;
+ OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = reproducible;
OMP_CLAUSE_CHAIN (c) = list;
return c;
tree c, id;
const char *p;
bool unconstrained = false;
+ bool reproducible = false;
matching_parens parens;
if (!parens.require_open (parser))
p = IDENTIFIER_POINTER (id);
if (strcmp (p, "unconstrained") == 0)
unconstrained = true;
- else if (strcmp (p, "reproducible") != 0)
+ else if (strcmp (p, "reproducible") == 0)
+ reproducible = true;
+ else
{
cp_parser_error (parser, "expected %<reproducible%> or "
"%<unconstrained%>");
check_no_duplicate_clause (list, OMP_CLAUSE_ORDER, "order", location);
c = build_omp_clause (location, OMP_CLAUSE_ORDER);
OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = unconstrained;
+ OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = reproducible;
OMP_CLAUSE_CHAIN (c) = list;
return c;
fputs (" ORDER(", dumpfile);
if (omp_clauses->order_unconstrained)
fputs ("UNCONSTRAINED:", dumpfile);
+ else if (omp_clauses->order_reproducible)
+ fputs ("REPRODUCIBLE:", dumpfile);
fputs ("CONCURRENT)", dumpfile);
}
if (omp_clauses->ordered)
unsigned inbranch:1, notinbranch:1, nogroup:1;
unsigned sched_simd:1, sched_monotonic:1, sched_nonmonotonic:1;
unsigned simd:1, threads:1, depend_source:1, destroy:1, order_concurrent:1;
- unsigned order_unconstrained:1, capture:1, grainsize_strict:1;
- unsigned num_tasks_strict:1;
+ unsigned order_unconstrained:1, order_reproducible:1, capture:1;
+ unsigned grainsize_strict:1, num_tasks_strict:1;
ENUM_BITFIELD (gfc_omp_sched_kind) sched_kind:3;
ENUM_BITFIELD (gfc_omp_device_type) device_type:2;
ENUM_BITFIELD (gfc_omp_memorder) memorder:3;
{
if (m == MATCH_ERROR)
goto error;
- if (gfc_match (" reproducible : concurrent )") == MATCH_YES
- || gfc_match (" concurrent )") == MATCH_YES)
+ if (gfc_match (" reproducible : concurrent )") == MATCH_YES)
+ c->order_reproducible = true;
+ else if (gfc_match (" concurrent )") == MATCH_YES)
;
else if (gfc_match (" unconstrained : concurrent )") == MATCH_YES)
c->order_unconstrained = true;
{
c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDER);
OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = clauses->order_unconstrained;
+ OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = clauses->order_reproducible;
omp_clauses = gfc_trans_add_clause (c, omp_clauses);
}
= code->ext.omp_clauses->order_concurrent;
clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_unconstrained
= code->ext.omp_clauses->order_unconstrained;
+ clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_reproducible
+ = code->ext.omp_clauses->order_reproducible;
}
if (mask & GFC_OMP_MASK_PARALLEL)
{
= code->ext.omp_clauses->order_concurrent;
clausesa[GFC_OMP_SPLIT_DO].order_unconstrained
= code->ext.omp_clauses->order_unconstrained;
+ clausesa[GFC_OMP_SPLIT_DO].order_reproducible
+ = code->ext.omp_clauses->order_reproducible;
}
if (mask & GFC_OMP_MASK_SIMD)
{
= code->ext.omp_clauses->order_concurrent;
clausesa[GFC_OMP_SPLIT_SIMD].order_unconstrained
= code->ext.omp_clauses->order_unconstrained;
+ clausesa[GFC_OMP_SPLIT_SIMD].order_reproducible
+ = code->ext.omp_clauses->order_reproducible;
/* And this is copied to all. */
clausesa[GFC_OMP_SPLIT_SIMD].if_expr
= code->ext.omp_clauses->if_expr;
== GF_OMP_FOR_KIND_DISTRIBUTE;
bool taskloop = gimple_omp_for_kind (for_stmt)
== GF_OMP_FOR_KIND_TASKLOOP;
+ bool order_reproducible = false;
tree iterv, countv;
fd->for_stmt = for_stmt;
&& !OMP_CLAUSE__SCANTEMP__CONTROL (t))
fd->have_nonctrl_scantemp = true;
break;
+ case OMP_CLAUSE_ORDER:
+ /* FIXME: For OpenMP 5.2 this should change to
+ if (OMP_CLAUSE_ORDER_REPRODUCIBLE (t))
+ (with the exception of loop construct but that lowers to
+ no schedule/dist_schedule clauses currently). */
+ if (!OMP_CLAUSE_ORDER_UNCONSTRAINED (t))
+ order_reproducible = true;
default:
break;
}
+ /* For order(reproducible:concurrent) schedule ({dynamic,guided,runtime})
+ we have either the option to expensively remember at runtime how we've
+ distributed work from first loop and reuse that in following loops with
+ the same number of iterations and schedule, or just force static schedule.
+ OpenMP API calls etc. aren't allowed in order(concurrent) bodies so
+ users can't observe it easily anyway. */
+ if (order_reproducible)
+ fd->sched_kind = OMP_CLAUSE_SCHEDULE_STATIC;
if (fd->collapse > 1 || fd->tiling)
fd->loops = loops;
else
end do
end
-! { dg-final { scan-tree-dump-times "#pragma omp distribute order\\(concurrent\\)" 6 "original"} }
+! { dg-final { scan-tree-dump-times "#pragma omp distribute order\\(reproducible:concurrent\\)" 6 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp distribute order\\(unconstrained:concurrent\\)" 6 "original"} }
-! { dg-final { scan-tree-dump-times "#pragma omp for nowait order\\(concurrent\\)" 6 "original"} }
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait order\\(reproducible:concurrent\\)" 6 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp for nowait order\\(unconstrained:concurrent\\)" 6 "original"} }
-! { dg-final { scan-tree-dump-times "#pragma omp for order\\(concurrent\\)" 2 "original"} }
+! { dg-final { scan-tree-dump-times "#pragma omp for order\\(reproducible:concurrent\\)" 2 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp for order\\(unconstrained:concurrent\\)" 2 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp parallel" 12 "original"} }
-! { dg-final { scan-tree-dump-times "#pragma omp simd linear\\(i:1\\) order\\(concurrent\\)" 6 "original"} }
+! { dg-final { scan-tree-dump-times "#pragma omp simd linear\\(i:1\\) order\\(reproducible:concurrent\\)" 6 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp simd linear\\(i:1\\) order\\(unconstrained:concurrent\\)" 6 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp taskloop" 2 "original"} }
! { dg-final { scan-tree-dump-times "#pragma omp teams" 8 "original"} }
pp_string (pp, "order(");
if (OMP_CLAUSE_ORDER_UNCONSTRAINED (clause))
pp_string (pp, "unconstrained:");
+ else if (OMP_CLAUSE_ORDER_REPRODUCIBLE (clause))
+ pp_string (pp, "reproducible:");
pp_string (pp, "concurrent)");
break;
/* True for unconstrained modifier on order(concurrent) clause. */
#define OMP_CLAUSE_ORDER_UNCONSTRAINED(NODE) \
(OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_ORDER)->base.public_flag)
+/* True for reproducible modifier on order(concurrent) clause. */
+#define OMP_CLAUSE_ORDER_REPRODUCIBLE(NODE) \
+ TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_ORDER))
#define OMP_CLAUSE_REDUCTION_CODE(NODE) \
(OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_REDUCTION, \
--- /dev/null
+#include <unistd.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ int a[128];
+ #pragma omp teams num_teams(5)
+ {
+ #pragma omp loop bind(teams)
+ for (int i = 0; i < 128; i++)
+ {
+ a[i] = i;
+ if (i == 0)
+ usleep (20);
+ else if (i == 17)
+ usleep (40);
+ }
+ #pragma omp loop bind(teams)
+ for (int i = 0; i < 128; i++)
+ a[i] += i;
+ }
+ for (int i = 0; i < 128; i++)
+ if (a[i] != 2 * i)
+ abort ();
+ #pragma omp teams num_teams(5)
+ {
+ #pragma omp loop bind(teams) order(concurrent)
+ for (int i = 0; i < 128; i++)
+ {
+ a[i] *= 2;
+ if (i == 1)
+ usleep (20);
+ else if (i == 13)
+ usleep (40);
+ }
+ #pragma omp loop bind(teams) order(concurrent)
+ for (int i = 0; i < 128; i++)
+ a[i] += i;
+ }
+ for (int i = 0; i < 128; i++)
+ if (a[i] != 5 * i)
+ abort ();
+ #pragma omp teams num_teams(5)
+ {
+ #pragma omp loop bind(teams) order(reproducible:concurrent)
+ for (int i = 0; i < 128; i++)
+ {
+ a[i] *= 2;
+ if (i == 2)
+ usleep (20);
+ else if (i == 105)
+ usleep (40);
+ }
+ #pragma omp loop bind(teams) order(reproducible:concurrent)
+ for (int i = 0; i < 128; i++)
+ a[i] += i;
+ }
+ for (int i = 0; i < 128; i++)
+ if (a[i] != 11 * i)
+ abort ();
+ return 0;
+}
--- /dev/null
+#include <unistd.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ int a[128];
+ #pragma omp parallel num_threads(8)
+ {
+ #pragma omp barrier
+ #pragma omp for nowait schedule (dynamic, 2) order(reproducible:concurrent)
+ for (int i = 0; i < 128; i++)
+ {
+ a[i] = i;
+ if (i == 0)
+ usleep (20);
+ else if (i == 17)
+ usleep (40);
+ }
+ #pragma omp for nowait schedule (dynamic, 2) order(reproducible:concurrent)
+ for (int i = 0; i < 128; i++)
+ a[i] += i;
+ }
+ for (int i = 0; i < 128; i++)
+ if (a[i] != 2 * i)
+ abort ();
+ return 0;
+}