FLUE_philox_helpers
Helper utilities for the Philox-based heatbath implementation.
This module provides:
- a uniform 64-bit integer kind alias (C64),
- deterministic derivation of a stage-specific key from a master key,
- a linear site index for mapping a lattice site to a Philox counter,
- colouring rules for Wilson (2-colour) and Symanzik (4-colour) updates.
Source: src/FLUE_philox_helpers.f90
Dependencies
Contents
Subroutines
derive_stage_key
Create a separated key for each stage
Construct t1 by packing (sweep_id, mu, colour) into a 64-bit integer
shiftl(x, n) ≡ x * 2^n
So: shiftl(int(sweep_id), 32) ≡ sweep_id * 2^32 shiftl(int(mu), 16) ≡ mu * 2^16
Therefore: t1 = sweep_id * 2^32 + mu * 2^16 + colour
Bit layout: [ sweep_id (upper 32 bits) | mu (next 16 bits) | colour (low 16 bits) ]
Construct t2 by packing (stage_tag, mu, colour) into a different layout
shiftl(int(stage_tag), 40) ≡ stage_tag * 2^40 shiftl(int(mu), 20) ≡ mu * 2^20
Therefore: t2 = stage_tag * 2^40 + mu * 2^20 + colour
Bit layout: [ stage_tag (upper bits) | mu (next 20 bits) | colour (low 20 bits) ]
Note: different shifts from t1 intentionally decorrelate fields.
Mix into final 128-bit key using XOR
key(1): key(1) = master_key(1) XOR t1
key(2): shiftl(t1, 7) ≡ t1 * 2^7 = t1 * 128
key(2) = master_key(2) XOR [ t2 XOR (t1 * 128) ]
The shift by 7 spreads t1 bits into different positions before mixing, reducing linear correlation between key(1) and key(2).
subroutine derive_stage_key(master_key, sweep_id, stage_tag, mu, colour, key)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
master_key | integer(kind=C64) | in | dimension(2) | 128-bit base key (2 x 64-bit words) |
sweep_id | integer | in | trajectory / sweep index | |
stage_tag | integer | in | algorithm stage identifier | |
mu | integer | in | link direction | |
colour | integer | in | checkerboard subset | |
key | integer(kind=C64) | out | dimension(2) | derived 128-bit Philox key |
Call graph
Functions
ncolours_for_action
Return the number of independent colour classes needed for the action.
Wilson -> 2 colours Symanzik -> 4 colours
The Symanzik rectangles couple same-checkerboard sites, so 2 colours are not sufficient there.
Attributes: pure
Returns: integer
function ncolours_for_action(use_symanzik) result(ncolours)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
use_symanzik | logical | in | Whether we use a symanzik improved action or not |
Call graph
site_colour
Compute the colour class of a site for a fixed link direction mu.
coord = [it, ix, iy, iz]
Wilson: Use the ordinary checkerboard parity: colour = mod(it + ix + iy + iz, 2)
Symanzik: Use a 4-colour partition that separates the displacements which appear in the rectangular loops: colour = 2*mod(coord(mu),2) + mod(sum(other coords),2)
Attributes: pure
Returns: integer
function site_colour(coord, mu, use_symanzik) result(colour)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
coord | integer | in | dimension(4) | coordinate of the link |
mu | integer | in | integer direction of link | |
use_symanzik | logical | in | The actioin type |
Call graph
site_linear_index
Convert a 4D lattice coordinate to a unique 1-based linear site index.
coord = [it, ix, iy, iz] dims = [nt, nx, ny, nz]
This linear index is used as counter(1) for the Philox stream so each site has its own independent random-number namespace.
Attributes: pure
Returns: integer(kind=C64)
function site_linear_index(coord, dims) result(idx)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
coord | integer | in | dimension(4) | site coordinate [it, ix, iy, iz] |
dims | integer | in | dimension(4) | total size of lattice [nt, nx, ny, nz] |
Call graph