public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/102698] omp atomic capture Abnormal results after running multiple times
Date: Tue, 12 Oct 2021 12:20:11 +0000	[thread overview]
Message-ID: <bug-102698-4-O64traJhDO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102698-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
!$omp atomic capture
v = x
x = ior(x, expr)
!$omp end atomic
etc. is conceptually similar to
!$omp atomic load
v = x
!$omp end atomic
!$omp atomic update
x = ior(x, expr)
!$omp end atomic
except that the capture form is atomic even together, the v is really the value
of x right before the successful atomic ior, while in the latter case some
other
thread could modify x in between those 2 atomic constructs.  And similarly,
the forms that have v = x at the end are similar to two atomics in the other
order.
There are many cases where it is useful, e.g. for the fetch before operation
you atomically or some flag but then you want to perform some code in the
current thread only if the flag wasn't set before, etc.  Similarly for the
fetch after the operation.  It really depends on what the code wants to
achieve.
What your testcase does is not useful though, you basically want to have 2
arrays the same content, you can achieve that by copying the atomically changed
array to the other one at the end of parallel region, or by doing the atomics
on both arrays separately.

      parent reply	other threads:[~2021-10-12 12:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12  3:35 [Bug fortran/102698] New: " han.wu@compiler-dev.com
2021-10-12  6:31 ` [Bug fortran/102698] " rguenth at gcc dot gnu.org
2021-10-12  8:14 ` jakub at gcc dot gnu.org
2021-10-12  9:09 ` jakub at gcc dot gnu.org
2021-10-12 12:03 ` han.wu@compiler-dev.com
2021-10-12 12:20 ` jakub at gcc dot gnu.org [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=bug-102698-4-O64traJhDO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).