public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: Ilya Verbin <iverbin@gmail.com>, Nathan Sidwell <nathan@acm.org>,
	       Thomas Schwinge <thomas_schwinge@mentor.com>,
	Jan Hubicka <jh@suse.cz>,
	       gcc-patches@gcc.gnu.org
Subject: Re: "omp declare target" on DECL_EXTERNAL vars
Date: Mon, 23 May 2016 18:28:00 -0000	[thread overview]
Message-ID: <20160523182801.GA28550@tucnak.redhat.com> (raw)
In-Reply-To: <alpine.LNX.2.20.1605232016230.17947@monopod.intra.ispras.ru>

On Mon, May 23, 2016 at 09:19:47PM +0300, Alexander Monakov wrote:
> 
> So unlike for functions, for variables GCC needs to know exactly whether they
> are 'omp declare target [link]' at all points of use, not just at the point of
> definition.

There are many bugs that just can't be diagnosed by the compiler.
It is up to the users to make sure they write sane code.

> There's a pitfall if the user forgets the pragma on the external declaration:
> 
> === a.c
> 
> #pragma omp declare target
> int a;
> void set_a()
> {
>   a = 42;
> }
> #pragma omp end declare target
> 
> === main.c
> 
> extern int a;
> extern void set_a();
> #pragma omp declare target to(set_a)
> 
> int main()
> {
>   a = 0;
>   #pragma omp target map(tofrom:a)
>     set_a();
> 
>   if (a != 42) abort();
> }
> ===

The above will abort always, no matter if you have #pragma omp declare target to(a)
in main.c or not, because a is already mapped (with infinite refcount), so
the map(tofrom:a) doesn't actually do anything (but prevent
firstprivatization of the var).  With map clause on the target, the only
change would be that the body of the target (but not functions it calls), if
they reference a, would be less efficient (would reference a through some
pointer set up during the mapping, instead of a directly).

	Jakub

      reply	other threads:[~2016-05-23 18:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 16:12 [gomp4.5] Make even Fortran target use firstprivate for scalars by default, assorted fixes Jakub Jelinek
2016-05-20 16:21 ` "omp declare target" on DECL_EXTERNAL vars Jakub Jelinek
2016-05-23 14:37   ` Alexander Monakov
2016-05-23 14:55     ` Jakub Jelinek
2016-05-23 16:15   ` Alexander Monakov
2016-05-23 16:51     ` Jakub Jelinek
2016-05-23 18:19       ` Alexander Monakov
2016-05-23 18:28         ` 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=20160523182801.GA28550@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=amonakov@ispras.ru \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iverbin@gmail.com \
    --cc=jh@suse.cz \
    --cc=nathan@acm.org \
    --cc=thomas_schwinge@mentor.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).