amo

Date:

11-26-2018

NAME

_amo_aadd, _amo_aadd_upc, _amo_aaddf, _amo_aaddf_upc, _amo_afadd, _amo_afadd_upc, _amo_aax, _amo_aax_upc, _amo_afax, _amo_afax_upc, _amo_aandf, _amo_aandf_upc, _amo_afand, _amo_afand_upc, _amo_amax_upc, _amo_afmax_upc, _amo_amaxf_upc, _amo_amin_upc, _amo_afmin_upc, _amo_aminf_upc, _amo_anandf, _amo_anandf_upc, _amo_afnand, _amo_afnand_upc, _amo_aorf, _amo_aorf_upc, _amo_afor, _amo_afor_upc, _amo_axorf, _amo_axorf_upc, _amo_afxor, _amo_afxor_upc, _amo_acswap, _amo_acswap_upc, _amo_aswap, _amo_aswap_upc, _amo_aflush, _amo_aflush_upc, __builtin_ia32_lfence, __builtin_ia32_mfence, __builtin_ia32_sfence, __sync_fetch_and_add, __sync_fetch_and_sub, __sync_fetch_and_or, __sync_fetch_and_and, __sync_fetch_and_xor, __sync_fetch_and_nand, __sync_add_and_fetch, __sync_sub_and_fetch, __sync_or_and_fetch, __sync_and_and_fetch, __sync_xor_and_fetch, __sync_nand_and_fetch, __sync_val_compare_and_swap, __sync_lock_test_and_swap, amo_aadd, amo_aaddf, amo_afadd, amo_aax, amo_afax, amo_aandf, amo_afand, amo_anandf, amo_afnand, amo_aorf, amo_afor, amo_axorf, amo_afxor, amo_acswap, amo_aswap, amo_aflush - Perform various atomic memory operations

SYNOPSIS

C Synopsis

/* Prototyped functions */

#include <intrinsics.h>

void _amo_aadd(volatile long *ptr, long value);
void _amo_aadd_upc(shared volatile long *ptr, long value);

long _amo_aaddf(volatile long *ptr, long value);
long _amo_aaddf_upc(shared volatile long *ptr, long value);

long _amo_afadd(volatile long *ptr, long value);
long _amo_afadd_upc(shared volatile long *ptr, long value);

void _amo_aax(volatile unsigned long *ptr, unsigned long andMask,
     unsigned long xorMask);
void _amo_aax_upc(shared volatile unsigned long *ptr, unsigned long andMask,
     unsigned long xorMask);

unsigned long _amo_afax(volatile unsigned long *ptr,
     unsigned long andMask, unsigned long xorMask);
unsigned long _amo_afax_upc(shared volatile unsigned long *ptr,
     unsigned long andMask, unsigned long xorMask);

long _amo_aandf(volatile long *ptr, long value);
long _amo_aandf_upc(shared volatile long *ptr, long value);

long _amo_afand(volatile long *ptr, long value);
long _amo_afand_upc(shared volatile long *ptr, long value);

void _amo_amax_upc(shared volatile long *ptr, long value);
long _amo_afmax_upc(shared volatile long *ptr, long value);
long _amo_amaxf_upc(shared volatile long *ptr, long value);

void _amo_amin_upc(shared volatile long *ptr, long value);
long _amo_afmin_upc(shared volatile long *ptr, long value);
long _amo_aminf_upc(shared volatile long *ptr, long value);

long _amo_anandf(volatile long *ptr, long value);
long _amo_anandf_upc(shared volatile long *ptr, long value);

long _amo_afnand(volatile long *ptr, long value);
long _amo_afnand_upc(shared volatile long *ptr, long value);

long _amo_aorf(volatile long *ptr, long value);
long _amo_aorf_upc(shared volatile long *ptr, long value);

long _amo_afor(volatile long *ptr, long value);
long _amo_afor_upc(shared volatile long *ptr, long value);

long _amo_axorf(volatile long *ptr, long value);
long _amo_axorf_upc(shared volatile long *ptr, long value);

long _amo_afxor(volatile long *ptr, long value);
long _amo_afxor_upc(shared volatile long *ptr, long value);

long _amo_acswap(volatile long *ptr,
     long compareValue, long replacementValue);
long _amo_acswap_upc(shared volatile long *ptr,
     long compareValue, long replacementValue);

long _amo_aswap(volatile long *ptr,
     long replacementValue);
long _amo_aswap_upc(shared volatile long *ptr,
     long replacementValue);

void _amo_aflush(volatile long *ptr);
void _amo_aflush_upc(shared volatile long *ptr);

void __builtin_ia32_lfence(void);
void __builtin_ia32_mfence(void);
void __builtin_ia32_sfence(void);

/* Non-prototyped functions */

/* The following functions are built-in to the compiler, */
/* not defined in intrinsics.h                           */

/*  type can be signed and unsigned integer types,         */
/* 1, 2, 4, or 8 bytes in length                         */

type __sync_fetch_and_add (type *ptr, type value, ...)
type __sync_fetch_and_sub (type *ptr, type value, ...)
type __sync_fetch_and_or (type *ptr, type value, ...)
type __sync_fetch_and_and (type *ptr, type value, ...)
type __sync_fetch_and_xor (type *ptr, type value, ...)
type __sync_fetch_and_nand (type *ptr, type value, ...)
type __sync_add_and_fetch (type *ptr, type value, ...)
type __sync_sub_and_fetch (type *ptr, type value, ...)
type __sync_or_and_fetch (type *ptr, type value, ...)
type __sync_and_and_fetch (type *ptr, type value, ...)
type __sync_xor_and_fetch (type *ptr, type value, ...)
type __sync_nand_and_fetch (type *ptr, type value, ...)
type __sync_val_compare_and_swap (type  *ptr, type  oldval  type newval, ...)
type __sync_lock_test_and_set (type *ptr, type value, ...)

Fortran Synopsis

call amo_aadd( var, value)
  integer (kind=8) var, value

integer function amo_aaddf( var, value)
  integer (kind=8) var, value

integer function amo_afadd( var, value)
  integer (kind=8) var, value

call amo_aax( var, andMask, xorMask )
  integer (kind=8) var, andMask, xorMask

integer function amo_afax( var, andMask, xorMask )
  integer (kind=8) var, andMask, xorMask

integer function amo_aandf( var, value)
  integer (kind=8) var, value

integer function amo_afand( var, value)
  integer (kind=8) var, value

integer function amo_anandf( var, value)
  integer (kind=8) var, value

integer function amo_afnand( var, value)
  integer (kind=8) var, value

integer function amo_aorf( var, value)
  integer (kind=8) var, value

integer function amo_afor( var, value)
  integer (kind=8) var, value

integer function amo_axorf( var, value)
  integer (kind=8) var, value

integer function amo_afxor( var, value)
  integer (kind=8) var, value

integer function amo_acswap( var, compareValue, replacementValue )
  integer (kind=8) var, compareValue, replacementValue

integer function amo_aswap( var, replacementValue )
  integer (kind=8) var, replacementValue

call amo_aflush( var )
  integer (kind=8) var

DESCRIPTION

Atomic memory operations (AMOs), unlike other functions, cannot be interrupted by the system and can allow multiple threads to safely modify the same variable under certain conditions. The AMO intrinsics allow you to add, subtract, AND, NAND, OR, and XOR values together, or compare and swap values.

It is possible to safely modify a variable using both atomic and non-atomic operations within a single thread; however, if a thread modifies a variable with an atomic operation and a different thread concurrently modifies the same variable with a non-atomic operation, the result is indeterminate.

Local AMOs operate on variables in the processor’s local memory (cache domain); they do not use the network interface to access memory. Multiple threads using local atomic memory operations to access the same variable need to be running within the same processor cache domain, which implies that they must be running on the same node. Local AMOs are atomic with respect to each other.

Global AMOs do use the network interface to access variables in memory. The variables may or may not be in the processor’s local cache domain. Global AMOs are atomic with respect to each other. Global AMOs are used to modify a Unified Parallel C (UPC) shared variable or Fortran coarray and are available only when compiling UPC (-hupc) or coarray Fortran (-hcaf).

A global AMO uses a different mechanism for achieving atomicity than a local AMO, so local and global AMOs are not atomic with respect to each other. Global and local AMOs should not be used concurrently on the same memory location, without synchronization.

These are the C Global AMO intrinsics defined in intrinsics.h. Functions without the _upc suffix accept both shared and non-shared pointers as the first argument. Functions with the _upc suffix accept only shared pointers as the first argument.

  • The _amo_aadd and _amo_aadd_upc functions (atomic add) add value to the object pointed to by ptr.

  • The _amo_aaddf and _amo_aaddf functions (atomic add and fetch) add value to the object pointed to by ptr and return the new value.

  • The _amo_afadd and _amo_afadd_upc functions (atomic fetch and add) add value to the object pointed to by ptr and return the old value of the object.

  • The _amo_aax and _amo_aax_upc functions (atomic AND and XOR) AND the object pointed to by ptr with andMask, XOR the result with xorMask, and place the result into the object.

  • The _amo_afax and _amo_afax_upc functions (atomic fetch and AND and XOR) AND the object pointed to by ptr with andMask, XOR the result with xorMask, place the result into the object, and return the old value of the object.

  • The _amo_aandf and _amo_aandf_upc functions (atomic AND and fetch) AND the object pointed to by ptr with value, place the result into the object, and return the new value of the object.

  • The _amo_afand and _amo_afand_upc functions (atomic fetch and AND) AND the object pointed to by ptr with value, place the result into the object, and return the old value of the object.

  • The _amo_amax_upc function (atomic MAX) places the larger of value and the object pointed to by ptr in ptr.

  • The _amo_afmax_upc function (atomic fetch and MAX) places the larger of value and the object pointed to by ptr in ptr, and returns the old value of the object.

  • The _amo_amaxf_upc function (atomic MAX and fetch) places the larger of value and the object pointed to by ptr in ptr, and returns the new value of the object.

  • The _amo_amin_upc function (atomic MIN) places the lesser of value and the object pointed to by ptr in ptr.

  • The _amo_afmin_upc function (atomic fetch and MIN) places the lesser of value and the object pointed to by ptr in ptr, and returns the old value of the object.

  • The _amo_aminf_upc function (atomic MIN and fetch) places the lesser of value and the object pointed to by ptr in ptr, and returns the new value of the object.

  • The _amo_anandf and _amo_anandf_upc functions (atomic NAND and fetch) NAND the object pointed to by ptr with value, place the result into the object, and return the new value of the object.

  • The _amo_afnand and _amo_afnand_upc functions (atomic fetch and NAND) NAND the object pointed to by ptr with value, place the result into the object, and return the old value of the object.

  • The _amo_aorf and _amo_aorf_upc functions (atomic OR and fetch) OR the object pointed to by ptr with value, place the result into the object, and return the new value of the object.

  • The _amo_afor and _amo_afor_upc functions (atomic fetch and OR) OR the object pointed to by ptr with value, place the result into the object, and return the old value of the object.

  • The _amo_axorf and _amo_axorf_upc functions (atomic XOR and fetch) XOR the object pointed to by ptr with value, place the result into the object, and return the new value of the object.

  • The _amo_afxor and _amo_afxor_upc functions (atomic fetch and XOR) XOR the object pointed to by ptr with value, place the result into the object, and return the old value of the object.

  • The _amo_acswap and _amo_acswap_upc functions (atomic compare and swap) compare and swap a value by replacing the contents of the object pointed to by ptr with replacementValue if compareValue is equal to the object pointed to by ptr and return the old value of the object.

  • The _amo_aswap and _amo_aswap_upc functions (atomic swap) swap a value by replacing the contents of the object pointed to by ptr with replacementValue. These functions always returns the old value.

  • The _amo_aflush and _amo_aflush_upc functions (atomic flush) force *ptr to be written to memory.

These are the C Local AMO intrinsics defined in intrinsics.h.

  • The __builtin_ia32_lfence function guarantees that all load instructions that were previously issued are globally visible in local memory before any subsequent loads are executed.

  • The __builtin_ia32_mfence function is the equivalent of both sfence and lfence functions executed concurrently.

  • The __builtin_ia32_sfence function guarantees that all store instructions that were previously issued are globally visible in local memory before any subsequent stores are executed.

These are the C built-in, local atomic functions that return the value of the object before the named operation occurs:

  • The __sync_fetch_and_add function fetches the object pointed to by ptr, adds value, places the result into the object pointed to by ptr, and returns the old value of the object pointed to by ptr.

  • The __sync_fetch_and_sub function fetches the object pointed to by ptr, subtracts value, places the result into the object pointed to by ptr, and returns the old value of the object pointed to by ptr.

  • The __sync_fetch_and_or function fetches the object pointed to by ptr, ORs value, places the result into the object pointed to by ptr, and returns the old value of the object pointed to by ptr.

  • The __sync_fetch_and_and function fetches the object pointed to by ptr, ANDs value, places the result into the object pointed to by ptr, and returns the old value of the object pointed to by ptr.

  • The __sync_fetch_and_xor function fetches the object pointed to by *ptr, XORs value, places the result into the object pointed to by ptr, and returns the old value of the object pointed to by ptr.

  • The __sync_fetch_and_nand function fetches the object pointed to by ptr, NANDs value, places the result into the object pointed to by ptr, and returns the old value of the object pointed to by ptr.

These are the C built-in, local atomic functions that return the value of the object after the named operation occurs:

  • The __sync_add_and_fetch function adds value to the object pointed to by ptr and returns the new value of the object pointed to by ptr.

  • The __sync_sub_and_fetch function subtracts value from the object pointed to by ptr and returns the new value of the object pointed to byptr.

  • The __sync_or_and_fetch function ORs value with the object pointed to by ptr and returns the new value of the object pointed to by ptr.

  • The __sync_and_and_fetch function ANDs value with the object pointed to by ptr and returns the new value of the object pointed to by ptr.

  • The __sync_xor_and_fetch function XORs value with the object pointed to by ptr and returns the new value of the object pointed to by ptr.

  • The __sync_nand_and_fetch function NANDs value with the current value of ptr and returns the new contents of ptr.

This built-in function performs a compare and swap:

  • The __sync_val_compare_and_swap function performs an atomic compare and swap. If the current value of *ptr is compareValue, then write replacementValue into *ptr and return the contents of *ptr before the operation.

This built-in function performs an atomic exchange operation:

  • The __sync_lock_test_and_set function writes value into *ptr, and returns the previous contents of *ptr.

These are the Fortran Global AMO intrinsics:

  • The amo_aadd subroutine (atomic add) adds value to the var object.

  • The amo_aaddf function (atomic add and fetch) adds value to the var object and returns the new value.

  • The amo_afadd function (atomic fetch and add) adds value to the var object and returns the old value.

  • The amo_aax subroutine (atomic AND and XOR) ANDs value with andMask, XORs the result with xorMask, and places the result into the var object.

  • The amo_afax function (atomic fetch and AND and XOR) ANDs value with andMask, XORs the result with xorMask, places the result into the var object, and returns the old value of var.

  • The amo_aandf function (atomic AND and fetch) ANDs value with var, places the result into the var object, and returns the new value of var.

  • The amo_afand function (atomic fetch and AND) ANDs value with var, places the result into the var object, and returns the old value of var.

  • The amo_anandf function (atomic NAND and fetch) NANDs value with var, places the result into the var object, and returns the new value of var.

  • The amo_afnand function (atomic fetch and NAND) NANDs value with var, places the result into the var object, and returns the old value of var.

  • The amo_aorf function (atomic OR and fetch) ORs value with var, places the result into the var object, and returns the new value of var.

  • The amo_afor function (atomic fetch and OR) ORs value with var, places the result into the var object, and returns the old value of var.

  • The amo_axorf function (atomic XOR and fetch) XORs value with var, places the result into the var object, and returns the new value of var.

  • The amo_afxor function (atomic fetch and XOR) XORs value with var, places the result into the var object, and returns the old value of var.

  • The amo_acswap function (atomic compare and swap) compares and swaps a value by replacing var with replacementValue if compareValue is equal to var. This function always returns the old value.

  • The amo_aswap function (atomic swap) swaps a value by replacing var with replacementValue. This function always returns the old value.

  • The amo_aflush function (atomic flush) forces var to be written to memory.

SEE ALSO

Cray C and C++ Reference Manual