e705b8533a
While OpenMP 5.1 implies order(concurrent) is the same thing as order(reproducible:concurrent), this is going to change in OpenMP 5.2, where essentially order(concurrent) means nothing is stated on whether it is reproducible or unconstrained (and is determined by other means, e.g. for/do with schedule static or runtime with static being selected is implicitly reproducible, distribute with dist_schedule static is implicitly reproducible, loop is implicitly reproducible) and when the modifier is specified explicitly, it overrides the implicit behavior either way. And, when order(reproducible:concurrent) is used with e.g. schedule(dynamic) or some other schedule that is by definition not reproducible, it is implementation's duty to ensure it is reproducible, either by remembering how it scheduled some loop and then replaying the same schedule when seeing loops with the same directive/schedule/number of iterations, or by overriding the schedule to some reproducible one. This patch doesn't implement the 5.2 wording just yet, but in the FEs differentiates between the 3 states - no explicit modifier, explicit reproducible or explicit unconstrainted, so that the middle-end can easily switch any time. Instead it follows the 5.1 wording where both order(concurrent) (implicit or explicit) or order(reproducible:concurrent) imply reproducibility. And, it implements the easier method, when for/do should be reproducible, it just chooses static schedule. order(concurrent) implies no OpenMP APIs in the loop body nor threadprivate vars, so the exact scheduling isn't (easily at least) observable. 2021-10-01 Jakub Jelinek <jakub@redhat.com> gcc/ * tree.h (OMP_CLAUSE_ORDER_REPRODUCIBLE): Define. * tree-pretty-print.c (dump_omp_clause) <case OMP_CLAUSE_ORDER>: Print reproducible: for OMP_CLAUSE_ORDER_REPRODUCIBLE. * omp-general.c (omp_extract_for_data): If OMP_CLAUSE_ORDER is seen without OMP_CLAUSE_ORDER_UNCONSTRAINED, overwrite sched_kind to OMP_CLAUSE_SCHEDULE_STATIC. gcc/c-family/ * c-omp.c (c_omp_split_clauses): Also copy OMP_CLAUSE_ORDER_REPRODUCIBLE. gcc/c/ * c-parser.c (c_parser_omp_clause_order): Set OMP_CLAUSE_ORDER_REPRODUCIBLE for explicit reproducible: modifier. gcc/cp/ * parser.c (cp_parser_omp_clause_order): Set OMP_CLAUSE_ORDER_REPRODUCIBLE for explicit reproducible: modifier. gcc/fortran/ * gfortran.h (gfc_omp_clauses): Add order_reproducible bitfield. * dump-parse-tree.c (show_omp_clauses): Print REPRODUCIBLE: for it. * openmp.c (gfc_match_omp_clauses): Set order_reproducible for explicit reproducible: modifier. * trans-openmp.c (gfc_trans_omp_clauses): Set OMP_CLAUSE_ORDER_REPRODUCIBLE for order_reproducible. (gfc_split_omp_clauses): Also copy order_reproducible. gcc/testsuite/ * gfortran.dg/gomp/order-5.f90: Adjust scan-tree-dump-times regexps. libgomp/ * testsuite/libgomp.c-c++-common/order-reproducible-1.c: New test. * testsuite/libgomp.c-c++-common/order-reproducible-2.c: New test.
64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
#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;
|
|
}
|