Bug 109013 - [OpenMP] Diagnose if multiple 'omp ordered' appear in a loop body
Summary: [OpenMP] Diagnose if multiple 'omp ordered' appear in a loop body
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, openmp
Depends on:
Blocks:
 
Reported: 2023-03-03 17:04 UTC by Tobias Burnus
Modified: 2023-03-03 18:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2023-03-03 17:04:51 UTC
The following code is accepted – while clang errors with:

test.c:18:5: error: exactly one 'ordered' directive must appear in the loop body of an enclosing directive

Cf. "Additional restrictions to the block-associated ordered construct are as follows:"
...
"During execution of the logical iteration of a loop-associated construct, a thread must not execute more than one block-associated ordered region that binds to the corresponding region of the loop-associated construct."



int a[10];

void foo(int n)
{
#if 0
  #pragma omp for ordered schedule(static)
  #pragma omp unroll partial(2)
  for(int i = 1; i < n; i++) {
    #pragma omp ordered
       a[i] += a[i-1];
  }
  // ->
#endif
  #pragma omp for ordered schedule(static)
  for(int i = 1; i < n; i += 2) {
    #pragma omp ordered
       a[i] += a[i-1];
    #pragma omp ordered
       a[i+1] += a[i];
  }
}
Comment 1 Jakub Jelinek 2023-03-03 17:25:57 UTC
This is not easy, because it is only invalid if one ordered dominates the other (so we need cfg to find that out) and further more it is an execution time restriction, so it is unclear if we can error, perhaps just warn?
Comment 2 Jakub Jelinek 2023-03-03 18:03:29 UTC
Even the dominating case could be valid.
E.g. if the body does
#pragma omp ordered
foo ();
bar ();
#pragma omp ordered
baz ();
where bar () calls exit (0);