atomic negation of a variable

General OpenMP discussion

atomic negation of a variable

Postby vondele » Thu Nov 28, 2013 2:04 pm

I'm surprised to learn that negation seemingly can not be performed atomically, but instead needs a trick. Is there a rationale for this, or something for 4.1 ?

SUBROUTINE test_atomic_negate(a)
INTEGER :: a

! Not valid...
!$OMP ATOMIC
a=-a

! valid but not quite elegant
!$OMP ATOMIC
a=0-a
END SUBROUTINE test_atomic_negate
vondele
 
Posts: 1
Joined: Thu Nov 28, 2013 1:49 pm

Re: atomic negation of a variable

Postby MarkB » Fri Nov 29, 2013 5:33 am

I don't know of any rationale for this, other than it would need to be specified as a special case. I guess that x = .not. x should be allowed too, and the relevant unary operators in C/C++ (-,~ and !).
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 7 guests