https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114596

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The scoring is according to TR12:

> Each trait selector for which the corresponding trait appears
> in the construct trait set in the OpenMP context is given the
> value 2^(pāˆ’1) where p is the position of the corresponding trait,
> c_p, in the construct trait set

And:

> Specifically, the ordering of the set of constructs is
> c1, . . . , cN , where c1 is the construct at the outermost
> nesting level and cN is the construct at the innermost nesting level.

and

> construct trait set ā€” The trait set that consists of all enclosing
> constructs at a given point in an OpenMP program up to a target construct.
>
> enclosing context ā€” For C/C++, the innermost scope enclosing a directive.


At the call site:
  {teams, parallel, for, parallel, for}

Selector in declare variant:
  {teams, parallel, for}

Looking at 'context traits that contains all selectors in the same order are
used', I see:

(1)  *teams* *parallel* *for* parallel for
(2)  *teams* *parallel* for parallel *for*
(3)  *teams* parallel for *parallel* *for*

Sandra wrote:
> By my reading, the OpenMP context at the point of call to f17 is
> {teams, parallel, for, parallel, for} with associated scores
> {1, 2, 4, 8, 16}

In my reading (see second quote above), the order of enclosing contexts is
inside out and the scores are:
p = {5,4,3,2,1} ā†’ score = {16,8,4,2,1}

Thus:
(1) 16 + 8 + 4 = 28
(2) 16 + 8 + 1 = 25
(3) 16 + 2 + 1 = 19

where (1) wins because of:

> if the traits that correspond to the construct selector set appear
> multiple times in the OpenMP context, the highest valued subset of
> context traits that contains all trait selectors in the same order
> are used;

* * *

This matches what the testcase has:

> match (construct={teams,parallel,for}) /* 16+8+4 */  (= 28)

* * *

-----<quote>----------
$ install/bin/x86_64-linux-gnu-gcc declare-variant-12.c -fopenmp
-foffload=disable -S
...
constructs[0] = omp_for, scores[0] = 4, score = 16
constructs[1] = omp_parallel, scores[1] = 3, score = 8
constructs[2] = omp_teams, scores[2] = 2, score = 4

For selector construct = {teams, parallel, for}
  score1 = 29   score2 = 29
-----<quote>----------

The constructs[i]'s score look fine.

But I wonder why score == 29 and not 28.

Reply via email to