omp atomic capture

Discussion of the OpenMP 3.1 draft specifications closed May 1, 2011. (Read only)

omp atomic capture

Postby anv » Tue Feb 15, 2011 5:37 am

Couple of notes on omp atomic capture construct.

Let's look at the code of atomic "capture old" construct:
Code: Select all
#pragma omp atomic capture
{v = x; x binop= expr}

  • The specification explicitly disallows the access to x in expr. But what is the point in allowing the access to v there? It looks more like an indirect access to x through the variable v. I think this access to v in expr should be explicitly disallowed by the specification (probably in all forms of atomic capture construct, regardless that it looks harmless in the "capture new" forms).
  • The spirit of atomic capture supposes the following natural sequence of actions:
    • Evaluate expr first (need not be atomic). This may be time consuming action with possible side effects, constructors/destructors calls etc.
    • Read old x, Update x, Write new x, all done atomically.
    • Save old or new value of x into v depending on the form of capture construct (need not be atomic).
    My key point here is that the sequence of operations is inherently non-sequential. If we suppose to keep sequential semantics (that is doing v=x BEFORE the evaluation of expr), then the atomic capture will lose its value completely and become equivalent to critical section, that is obviously not its goal. So I suggest adding some explicit note to the specification, like for example "the evaluation of atomic region, it’s side-effects, and any constructors/destructors are not guaranteed to happen in the same order as the sequential semantics".
Thanks,
Andrey
anv
 
Posts: 31
Joined: Wed Dec 12, 2007 9:36 am

Re: omp atomic capture

Postby jakub » Mon Feb 28, 2011 10:50 am

Yeah, I think for the { v = x; x = expr; } form x and expr should be disallowed from referencing v (and similarly for the fortran atomic capture where capture-stmt goes first.
jakub
 
Posts: 74
Joined: Fri Oct 26, 2007 3:19 am

Re: omp atomic capture

Postby jakub » Mon Feb 28, 2011 12:44 pm

Another thing I'm missing on omp atomic capture is that there is no syntax for atomic swap operation, capture old value and store new expression. I think that is pretty common operation, e.g. in the ia64 and GCC intrinsics it is
__sync_lock_test_and_set. Something like
#pragma omp atomic capture
{ v = x; x = expr; }
This would atomically read old value from x into v and store expr into x. Capture of the new value doesn't make sense in this case (i.e. { x = expr; v = x; } which would be ambiguous with the capture old value and store; capturing new value can be done non-atomically, by
temp = expr;
#pragma omp atomic write
x = temp;
v = temp;
).
jakub
 
Posts: 74
Joined: Fri Oct 26, 2007 3:19 am

Re: omp atomic capture

Postby bronis » Sat Mar 12, 2011 7:47 am

All:

The Language Committee is reviewing this topic. We will make some changes to reflect it. While the exact changes still need to be resolved through the committee process, it is likely that we will disallow the accesses to v as well as x as suggested. We will also consider Jakub's atomic swap proposal. My expectation is that we will eventually support it although the committee will have to evaluate the time frame for that support.

Bronis
bronis
 
Posts: 5
Joined: Thu Oct 09, 2008 4:38 am


Return to Draft 3.1 Public Comment

Who is online

Users browsing this forum: No registered users and 2 guests