public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Tobias Burnus <tobias@codesourcery.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>, fortran <fortran@gcc.gnu.org>
Subject: Re: [Patch] Fortran/openmp: Fix '!$omp end'
Date: Fri, 12 Nov 2021 17:07:54 +0100	[thread overview]
Message-ID: <20211112160754.GH2710@tucnak> (raw)
In-Reply-To: <bf20e0b9-ad2b-35d3-96e8-618b22369806@codesourcery.com>

On Fri, Nov 12, 2021 at 04:56:37PM +0100, Tobias Burnus wrote:
> Fortran/openmp: Fix '!$omp end'
> 
> gcc/fortran/ChangeLog:
> 
> 	* parse.c (decode_omp_directive): Fix permitting 'nowait' for some
> 	combined directives, add missing 'omp end ... loop'.
> 	(gfc_ascii_statement): Fix ST_OMP_END_TEAMS_LOOP result.
> 	* openmp.c (resolve_omp_clauses): Add missing combined loop constructs
> 	case values to the 'if(directive-name: ...)' check.
> 	* trans-openmp.c (gfc_split_omp_clauses): Put nowait on target if
> 	first leaf construct accepting it.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gfortran.dg/gomp/unexpected-end.f90: Update dg-error.
> 	* gfortran.dg/gomp/clauses-1.f90: New test.
> 	* gfortran.dg/gomp/nowait-2.f90: New test.
> 	* gfortran.dg/gomp/nowait-3.f90: New test.

Mostly good, except:

> @@ -6132,10 +6134,9 @@ gfc_split_omp_clauses (gfc_code *code,
>     if (mask & GFC_OMP_MASK_TEAMS && innermost != GFC_OMP_MASK_TEAMS)
>       gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TEAMS],
>  				code->ext.omp_clauses, false, false);
> -   if (((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> -	== (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> -       && !is_loop)
> -    clausesa[GFC_OMP_SPLIT_DO].nowait = true;
> +   if ((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> +       == (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
> +    clausesa[GFC_OMP_SPLIT_DO].nowait = false;
>  }

this.  In the standard, yes, for parallel {do,sections,workshare}
indeed the do/sections/workshare doesn't get nowait (either
it is not allowed to specify it at all, or if combined with
target, nowait should go to target and nothing else).
But, for the middle-end, we actually want nowait true
whenever a worksharing construct is combined with parallel,
because when the worksharing construct ends, doing a barrier there
will mean we wait, then immediately get to the implicit barrier at the end
of parallel.

c_omp_split_clauses does:
  /* Add implicit nowait clause on
     #pragma omp parallel {for,for simd,sections}.  */
  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
    switch (code)
      {
      case OMP_FOR:
      case OMP_SIMD:
        if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
          cclauses[C_OMP_CLAUSE_SPLIT_FOR]
            = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
        break;
      case OMP_SECTIONS:
        cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]
          = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
        break;
      default:
        break;
      }
and I think the previous code did exactly that.

So, the patch is ok for trunk without the above hunk.

	Jakub


      reply	other threads:[~2021-11-12 16:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 17:11 Tobias Burnus
2021-11-11 18:01 ` Jakub Jelinek
2021-11-12 11:01   ` Tobias Burnus
2021-11-12 12:02     ` Jakub Jelinek
2021-11-12 15:56       ` Tobias Burnus
2021-11-12 16:07         ` Jakub Jelinek [this message]

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=20211112160754.GH2710@tucnak \
    --to=jakub@redhat.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --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).