C Library Functions  - atomic_and (3)

NAME

ATOMIC_AND(3) - [ATOMIC:BIT MANIPULATION] Atomic bitwise AND operation

SYNOPSIS

call atomic_and(atom, value [,stat])

         subroutine atomic_and(atom,value,stat)

integer(atomic_int_kind) :: atom[*] integer(atomic_int_kind),intent(in) :: value integer,intent(out),intent(out) :: stat

CHARACTERISTICS

o ATOM is a scalar coarray or coindexed variable of integer type with atomic_int_kind kind.
o VALUE is a scalar of the same type as ATOM. If the kind is different, the value is converted to the kind of ATOM.
o STAT is a Scalar default-kind integer variable.

DESCRIPTION

ATOMIC_AND(ATOM, VALUE, STAT) atomically performs a bitwise AND operation between the value of ATOM and VALUE, storing the result in ATOM. This ensures thread-safe updates in parallel contexts.

Unlike ATOMIC_FETCH_ADD, this procedure does not return the previous value of ATOM.

The result is the bitwise AND of ATOM and VALUE (e.g., 1111 AND 1010 = 1010).

Useful for manipulating bit flags atomically.

Use sync all to ensure consistent coarray state across images.

When STAT is present and the invocation was successful, it is assigned the value 0. If it is present and the invocation has failed, it is assigned a positive value; in particular, for a coindexed ATOM, if the remote image has stopped, it is assigned the value of ISO_FORTRAN_ENV’s STAT_STOPPED_IMAGE and if the remote image has failed, the value STAT_FAILED_IMAGE.

OPTIONS

o ATOM : Scalar coarray or coindexed variable of integer type with kind ATOMIC_INT_KIND .
o VALUE : Scalar of the same type as ATOM. If the kind is different, the value is converted to the kind of ATOM.
o STAT : (optional) Scalar default-kind integer variable. Set to 0 on success, or a positive value on failure.

EXAMPLES

Sample program:

    program demo_atomic_and
    use iso_fortran_env
    implicit none
    integer(atomic_int_kind) :: counter[*]
    integer :: stat, me

if (this_image() == 1) counter = 0 sync all

me = this_image() call atomic_add(counter[1], me, stat)

if (stat /= 0) print *, "Image", me, ": Failed with STAT =", stat sync all

if (this_image() == 1) print *, "Final counter:", counter end program demo_atomic_and

Expected Output (4 images)

        > Final counter: 10

STANDARD

Fortran 2008 and later, per TS 18508

SEE ALSO

ATOMIC_FETCH_AND(3), ATOMIC_DEFINE(3), ATOMIC_REF(3), ATOMIC_CAS(3), ISO_FORTRAN_ENV(3), ATOMIC_ADD(3), ATOMIC_OR(3), ATOMIC_XOR(3)

See ISO_FORTRAN_ENV for constants like ATOMIC_INT_KIND, STAT_STOPPED_IMAGE, and STAT_FAILED_IMAGE.

Fortran intrinsic descriptions


Nemo Release 3.1 atomic_and (3) June 29, 2025
Generated by manServer 1.08 from 0712fb0f-20a7-447d-a92b-c767045c80a2 using man macros.