Skip to content

Commit 1725d7b

Browse files
Robadobptheywood
andauthored
Update Env Macro atomic documentation (#193)
Co-authored-by: Peter Heywood <p.heywood@sheffield.ac.uk>
1 parent 94d2134 commit 1725d7b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/guide/agent-functions/interacting-with-environment.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ Environmental macro properties can be read, via the returned :class:`DeviceMacro
7676

7777
They can also be updated with a selection of functions, which execute atomically. These functions will update a single variable and return information related to it's old or new state. This can be useful, for simple actions such as conflict resolution and counting. However, if a basic read is subsequently required, a separate host or agent function in a following layer must be used (otherwise there would be a race condition). If running with ``FLAMEGPU_SEATBELTS`` error checking enabled, an exception should be thrown where potential race conditions are detected.
7878

79-
Macro properties support the normal :func:`+<flamegpu::DeviceMacroProperty::operator+>`, :func:`-<flamegpu::DeviceMacroProperty::operator->`, :func:`+=<flamegpu::DeviceMacroProperty::operator+=>`, :func:`-=<flamegpu::DeviceMacroProperty::operator-=>`, :func:`++<flamegpu::DeviceMacroProperty::operator++>` (only C++ supports pre and post increment), :func:`--<flamegpu::DeviceMacroProperty::operator-->` (only C++ supports pre and post decrement) operations. They also have access to a limited set of additional functions, explained in the table below.
79+
Macro properties support the normal :func:`+=<flamegpu::DeviceMacroProperty::operator+=>`, :func:`-=<flamegpu::DeviceMacroProperty::operator-=>`, :func:`++<flamegpu::DeviceMacroProperty::operator++>` (only C++ supports pre and post increment), :func:`--<flamegpu::DeviceMacroProperty::operator-->` (only C++ supports pre and post decrement) operations. They also have access to a limited set of additional functions, explained in the table below.
80+
81+
They can also make use of :func:`+<flamegpu::DeviceMacroProperty::operator+>`, :func:`-<flamegpu::DeviceMacroProperty::operator->`, however, these do not operate atomically as they do not mutate the macro environment property.
8082

8183
.. note::
8284

@@ -90,6 +92,8 @@ Method Supported Typ
9092
:func:`max(val)<flamegpu::DeviceMacroProperty::max>` ``int32_t``, ``uint32_t``, ``uint64_t`` Update property according to ``val > old ? val : old`` and return it's new value.
9193
:func:`CAS(compare, val)<flamegpu::DeviceMacroProperty::CAS>` ``int32_t``, ``uint32_t``, ``uint64_t``, ``uint16_t`` Update property according to ``old == compare ? val : old`` and return ``old``.
9294
:func:`exchange(val)<flamegpu::DeviceMacroProperty::exchange>` ``int32_t``, ``uint32_t``, ``float`` Update property to match val, and return ``old``.
95+
:func:`addAtomic(val)<flamegpu::DeviceMacroProperty::addAtomic>` ``int32_t``, ``uint32_t``, ``uint64_t``, ``float``, ``double`` Atomically add val and return the result.
96+
:func:`subAtomic(val)<flamegpu::DeviceMacroProperty::addAtomic>` ``int32_t``, ``uint32_t``, ``uint64_t``, ``float``, ``double`` Atomically subtract val and return the result.
9397
================================================================== ===================================================== ============================
9498

9599

@@ -125,8 +129,8 @@ Example usage is shown below:
125129
def ExampleFn(message_in: pyflamegpu.MessageNone, message_out: pyflamegpu.MessageNone):
126130
# Get the root of the 3x3x3 environment macro property 'location' and store it in a variable of the same name
127131
location = pyflamegpu.environment.getMacroPropertyUInt("location", 3, 3, 3)
128-
# Notify our location, of our presence and store how many other agents were there before us in `location_count`
129-
location_count = location[0][1][2]+=1
132+
# Notify our location, of our presence and store our arrival index to `location_count`
133+
location_count = location[0][1][2].addAtomic(1)
130134

131135

132136
# Get the root of the float environment macro property 'swap' and store it in a variable of the same name

0 commit comments

Comments
 (0)