C Library Functions  - atomic_fetch_and (3)

NAME

ATOMIC_FETCH_AND(3) - [ATOMIC:BIT MANIPULATION] Atomic bitwise AND operation with prior fetch

SYNOPSIS

call atomic_fetch_and(atom, value, old [,stat] )

         subroutine atomic_fetch_and(atom, value, old, stat)

CHARACTERISTICS

DESCRIPTION

ATOMIC_FETCH_AND(3) atomically fetches and performs a bitwise AND operation.

It is similar to ATOMIC_AND(3), but returns the previous value of ATOM. That is, it atomically stores the value of ATOM in OLD and performs a bitwise AND operation between ATOM and VALUE, storing the result in ATOM.

Useful for bit flag manipulation with feedback.

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 ATOMIC_INT_KIND 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 OLD : Scalar of the same type and kind as ATOM. Receives the value of ATOM before the operation.
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_fetch_and

use iso_fortran_env implicit none integer(atomic_int_kind) :: flags[*], old integer :: stat, me

if (this_image() == 1) flags = int(b’1111’, atomic_int_kind) sync all

me = this_image() call atomic_fetch_and(flags[1], int(b’1010’, atomic_int_kind), old, stat)

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

if (this_image() == 1) print *, "Final flags:", flags end program demo_atomic_fetch_and

Expected Output (4 images, order varies)

        > Image 1: Old = 15
        > Image 2: Old = 10
        > Image 3: Old = 10
        > Image 4: Old = 10
        > Final flags: 10

STANDARD

Fortran 2008 and later, TS 18508

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

SEE ALSO

ATOMIC_DEFINE(3), ATOMIC_AND(3), ISO_FORTRAN_ENV(3),

ATOMIC_FETCH_ADD(3), ATOMIC_FETCH_OR(3),

ATOMIC_FETCH_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_fetch_and (3) June 29, 2025
Generated by manServer 1.08 from 32ddd404-4901-4ce3-a82c-89eaac46ad22 using man macros.