public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Chung-Lin Tang <cltang@codesourcery.com>
To: Jakub Jelinek <jakub@redhat.com>,
	Tobias Burnus <tobias@codesourcery.com>,
	 gcc-patches <gcc-patches@gcc.gnu.org>,
	Fortran List <fortran@gcc.gnu.org>
Subject: Re: [PATCH, OpenMP 5.1, Fortran] Strictly-structured block support for OpenMP directives
Date: Sat, 16 Oct 2021 02:44:12 +0800	[thread overview]
Message-ID: <15f5d294-20a6-c9d2-409d-4d9c3e9c1100@codesourcery.com> (raw)
In-Reply-To: <20211014111929.GX304296@tucnak>

On 2021/10/14 7:19 PM, Jakub Jelinek wrote:
> On Thu, Oct 14, 2021 at 12:20:51PM +0200, Jakub Jelinek via Gcc-patches wrote:
>> Thinking more about the Fortran case for !$omp sections, there is an
>> ambiguity.
>> !$omp sections
>> block
>>    !$omp section
>> end block
>> is clear and !$omp end sections is optional, but
>> !$omp sections
>> block
>> end block
>> is ambiguous during parsing, it could be either followed by !$omp section
>> and then the BLOCK would be first section, or by !$omp end sections and then
>> it would be clearly the whole sections, with first section being empty
>> inside of the block, or if it is followed by something else, it is
>> ambiguous whether the block ... end block is part of the first section,
>> followed by something and then we should be looking later for either
>> !$omp section or !$omp end section to prove that, or if
>> !$omp sections
>> block
>> end block
>> was the whole sections construct and we shouldn't await anything further.
>> I'm afraid back to the drawing board.
> 
> And I have to correct myself, there is no ambiguity in 5.2 here,
> the important fact is hidden in sections/parallel sections being
> block-associated constructs.  That means the body of the whole construct
> has to be a structured-block, and by the 5.1+ definition of Fortran
> structured block, it is either block ... end block or something that
> doesn't start with block.
> So,
> !$omp sections
> block
> end block
> a = 1
> is only ambiguous in whether it is actually
> !$omp sections
> block
>    !$omp section
> end block
> a = 1
> or
> !$omp sections
> !$omp section
> block
> end block
> !$omp end sections
> a = 1
> but both actually do the same thing, work roughly as !$omp single.
> If one wants block statement as first in structured-block-sequence
> of the first section, followed by either some further statements
> or by other sections, then one needs to write
> !$omp sections
> !$omp section
> block
> end block
> a = 1
> ...
> !$omp end sections
> or
> !$omp sections
> block
>    block
>    end block
>    a = 1
> ...
> end block
> 
> Your patch probably already handles it that way, but we again need
> testsuite coverage to prove it is handled the way it should in all these
> cases (and that we diagnose what is invalid).

The patch currently does not allow strictly-structured BLOCK for sections/parallel sections,
since I was referencing the 5.1 spec while writing it, although that is trivially fixable.
(was sensing a bit odd why those two constructs had to be specially treated in 5.1 anyways)

The bigger issue is that under the current way the patch is written, the statements inside
a [parallel] sections construct are parsed automatically by parse_executable(), so to enforce
the specified meaning of "structured-block-sequence" (i.e. BLOCK or non-BLOCK starting sequence of stmts)
will probably be more a bit harder to implement:

!$omp sections
block
    !$omp section
    block
      x=0
    end block
    x=1           !! This is allowed now, though should be wrong spec-wise
    !$omp section
    x=2
end block

Currently "$!omp section" acts essentially as a top-level separator within a sections-construct,
rather than a structured directive. Though I would kind of argue this is actually better to use for the
user (why prohibit what looks like very apparent meaning of the program?)

So Jakub, my question for this is, is this current state okay? Or must we implement the spec pedantically?

As for the other issues:
(1) BLOCK/END BLOCK is not generally handled in parse_omp_structured_block, so for workshare,
     it is only handled for the top-level construct, not within workshare. I think this is what you meant
     in the last mail.

(2) As for the dangling-!$omp_end issue Tobias raised, because we are basically using 1-statement lookahead,
     any "!$omp end <*>" is naturally bound with the adjacent BLOCK/END BLOCK, so we should be okay there.

Thanks,
Chung-Lin

  reply	other threads:[~2021-10-15 18:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 13:59 Chung-Lin Tang
2021-10-07 16:33 ` Tobias Burnus
2021-10-07 17:09 ` Jakub Jelinek
2021-10-08 16:14   ` [PATCH] openmp: Add support for OpenMP 5.1 structured-block-sequences Jakub Jelinek
2021-10-14 10:20   ` [PATCH, OpenMP 5.1, Fortran] Strictly-structured block support for OpenMP directives Jakub Jelinek
2021-10-14 11:19     ` Jakub Jelinek
2021-10-15 18:44       ` Chung-Lin Tang [this message]
2021-10-15 19:02         ` Jakub Jelinek
2021-10-20 12:30           ` [PATCH, v2, OpenMP 5.2, " Chung-Lin Tang
2021-10-20 16:15             ` Jakub Jelinek
2021-10-21  7:00               ` Chung-Lin Tang
2021-10-21  9:19                 ` [committed] testsuite: Fix up gfortran.dg/gomp/strictly*.f90 testcases Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15f5d294-20a6-c9d2-409d-4d9c3e9c1100@codesourcery.com \
    --to=cltang@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=tobias@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).