<ATOMIC_FETCH_XOR Example Program>

Program atomic_fetch_xor_example
  Use iso_fortran_env
  Implicit None
  Integer(atomic_int_kind) :: result[*] = 0
  ! Exclusive-or all the integers from 1 to 1000,000,000,
  ! sharing the work across all images.
  Integer(atomic_int_kind),Parameter :: target = 1000000000
  Integer(atomic_int_kind) :: i,from,to,n,was,tmp
  n = target / Num_Images()
  from = (This_Image()-1)*n + 1
  If (This_Image()==Num_Images()) Then
    to = target
  Else
    to = This_Image()*n
  End If
  tmp = from
  Do i=from+1,to
    tmp =Ieor(tmp,i)
  End Do
  Call atomic_fetch_xor(result[1],tmp,was)
  Print 1,This_Image(),tmp,was,Ieor(was,tmp)
1 Format(1X,'Image ',I0,' x-or ',Z0,' changing ',Z0,' to ',Z0)
  Sync All
  If (This_Image()==1) Print 2,result
2 Format(1X,'Final result was ',Z0)
End Program

■ Execution Results

(Possible results with four images.)
 Image 3 x-or 31797280 changing 0 to 31797280
 Image 4 x-or 172EDD80 changing 31797280 to 2657AF00
 Image 2 x-or 132BD780 changing 2657AF00 to 357C7880
 Image 1 x-or EE6B280 changing 357C7880 to 3B9ACA00
 Final result was 3B9ACA00