Topic: atomic max/min


Author: algrant109@gmail.com
Date: Wed, 2 Nov 2016 14:38:08 -0700 (PDT)
Raw View
------=_Part_3640_579137608.1478122688894
Content-Type: multipart/alternative;
 boundary="----=_Part_3641_1142799906.1478122688895"

------=_Part_3641_1142799906.1478122688895
Content-Type: text/plain; charset=UTF-8

I'd like to propose atomic max/min. This is slightly different from what
Bronek Kozicki proposed in N3696,
but I guess he might end up being co-author. Here's what I was proposing to
write as rationale:

-----

This paper proposes extending the atomic operations library to add atomic
maximum/minimum operations on integer datatypes. These were
originally proposed by N3696 as special cases of a general priority update
mechanism, where objects were tested and conditionally updated.
In contrast to N3696, we propose atomic maximum/minimum independently of
any more general mechanism and follow the behavior of
existing atomic operations in specifying that the operations have the
effect of unconditional memory updates with respect to memory
ordering.

Background and motivation

Atomic maximum/minimum operations are useful in a variety of circumstances
in multithreaded applications:
- optimal implementation of certain lock-free shared data structures
- reductions in data-parallel applications: for example, OpenMP supports
maximum/minimum as a reduction operation
- recording the maximum so far reached in an optimization process, to allow
unproductive threads to terminate
- collecting statistics, such as the largest item of input encountered.

These atomic operations already exist in everal other languages or
programming systems, including OpenCL, C++ AMP and CUDA, and are
offered by some hardware implementations. The combination of an application
need, increasing availability in other languages, and
availability in hardware, add up to a strong case for providing these
operations in C++.

Notes on the proposal

- An atomic maximum/minimum operation has the effect of a read-modify-write
operation, irrespective of whether the value changes.
  This accords with existing atomic operations and avoids the need to deal
with data-dependent memory effects. Conditional stores,
  barriers etc. may be used to implement the operations as long as the
overall effect with respect to memory order is that of an atomic
  read-modify-write.
- syntactically, max/min are not operators in C++, so there are no compound
operators to overload; instead we propose a second set
  of named functions, of the form op_fetch.
- signed and unsigned maxmum/minimum operations have different results (for
the existing atomics, signed and unsigned operations
  will generally differ at most in overflow behavior). The atomic type
determines the type of the operation.
- this paper proposes operations on integral and pointer types only. If
both this proposal and the floating-point atomics as proposed in
  P0020 are adopted then we propose that atomic floating-point
maximum/minimum operations also be defined, in the obvious way.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6d3c460a-a6fe-4b66-a44b-3ff58189fb49%40isocpp.org.

------=_Part_3641_1142799906.1478122688895
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I&#39;d like to propose atomic max/min. This is slightly d=
ifferent from what Bronek Kozicki proposed in N3696,<div>but I guess he mig=
ht end up being co-author. Here&#39;s what I was proposing to write as rati=
onale:<div><br></div><div>-----=C2=A0</div><div><br></div><div><div>This pa=
per proposes extending the atomic operations library to add atomic maximum/=
minimum operations on integer datatypes. These were</div><div>originally pr=
oposed by N3696 as special cases of a general priority update mechanism, wh=
ere objects were tested and conditionally updated.</div><div>In contrast to=
 N3696, we propose atomic maximum/minimum independently of any more general=
 mechanism and follow the behavior of</div><div>existing atomic operations =
in specifying that the operations have the effect of unconditional memory u=
pdates with respect to memory</div><div>ordering.</div><div><br></div><div>=
Background and motivation</div><div><br></div><div>Atomic maximum/minimum o=
perations are useful in a variety of circumstances in multithreaded applica=
tions:</div><div>- optimal implementation of certain lock-free shared data =
structures</div><div>- reductions in data-parallel applications: for exampl=
e, OpenMP supports maximum/minimum as a reduction operation</div><div>- rec=
ording the maximum so far reached in an optimization process, to allow unpr=
oductive threads to terminate</div><div>- collecting statistics, such as th=
e largest item of input encountered.</div><div><br></div><div>These atomic =
operations already exist in everal other languages or programming systems, =
including OpenCL, C++ AMP and CUDA, and are</div><div>offered by some hardw=
are implementations. The combination of an application need, increasing ava=
ilability in other languages, and</div><div>availability in hardware, add u=
p to a strong case for providing these operations in C++.</div><div><br></d=
iv><div>Notes on the proposal</div><div><br></div><div>- An atomic maximum/=
minimum operation has the effect of a read-modify-write operation, irrespec=
tive of whether the value changes.</div><div>=C2=A0 This accords with exist=
ing atomic operations and avoids the need to deal with data-dependent memor=
y effects. Conditional stores,</div><div>=C2=A0 barriers etc. may be used t=
o implement the operations as long as the overall effect with respect to me=
mory order is that of an atomic</div><div>=C2=A0 read-modify-write.</div><d=
iv>- syntactically, max/min are not operators in C++, so there are no compo=
und operators to overload; instead we propose a second set</div><div>=C2=A0=
 of named functions, of the form op_fetch.</div><div>- signed and unsigned =
maxmum/minimum operations have different results (for the existing atomics,=
 signed and unsigned operations</div><div>=C2=A0 will generally differ at m=
ost in overflow behavior). The atomic type determines the type of the opera=
tion.</div><div>- this paper proposes operations on integral and pointer ty=
pes only. If both this proposal and the floating-point atomics as proposed =
in</div><div>=C2=A0 P0020 are adopted then we propose that atomic floating-=
point maximum/minimum operations also be defined, in the obvious way.</div>=
</div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6d3c460a-a6fe-4b66-a44b-3ff58189fb49%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6d3c460a-a6fe-4b66-a44b-3ff58189fb49=
%40isocpp.org</a>.<br />

------=_Part_3641_1142799906.1478122688895--

------=_Part_3640_579137608.1478122688894--

.