Implementation of Gauge and Spinor Fields
This section describes the core field types in MetaQCD and how to create and initialize them for lattice QCD calculations.
AbstractField Type Architecture
Core Field Types
MetaQCD implements three main matrix field container types:
Gaugefield
- Purpose: Standard gauge field for lattice QCD simulations
- Contains: Main array
Uplus gauge action information - Usage: Standard gauge field operations and measurements
Colorfield
- Purpose: Simplified gauge field without action metadata
- Contains: Main array
Uonly (no gauge action information) - Usage: Intermediate calculations where action type is irrelevant
Expfield
- Purpose: Extended field for advanced smearing algorithms
- Contains: 3×3 matrices plus additional "Q" matrices for Stout algorithm
- Usage: Stout smearing and recursive smearing operations
Data Storage Structure
On CPUs all field types use a 5-dimensional array structure:
- Dimensions:
[μ, x, y, z, t]whereμ(fastest/first index) indexes the 4 spacetime directions - Elements: Statically sized 3×3 complex matrices or 3ND-element complex vectors (
SMatrix/SVectorfrom StaticArrays.jl)
On GPUs we found that performance improved when making μ the slowest index. Additionally we enforce vectorized loads and stores by not storing the matrices and vectors as is but using the SIMD.jl type Vec to either group 2 or 4 floating point numbers together. This essentially mimics the C++ types float2, float4 etc.
Example 1: In the 12 element representation of SU(3) we store the matrices as 3
SVec{4,T}whereTis the floating point precision Example 2: We store staggered spinors as 3SVec{2,T}
When a field is indexed into, the getindex function automatically reconstructs the SMatrix or SVec from these SIMD vectors.
Performance Benefits
The use of StaticArrays provides several advantages:
- Zero Allocations: No memory allocation during linear algebra operations
- Immutable Operations: Matrices are always replaced rather than mutated
- Optimized Storage: Compile-time known sizes enable aggressive optimization
Backend Support
Different computing backends (CPU, GPU) are handled through Julia extensions, as detailed in the parallelization section. This allows the same code to run efficiently on various hardware while only loading GPU-specific code when needed.
Future Optimizations
More memory-efficient storage schemes for SU(3) and su(3) elements (8 floating point representations) may be implemented in future versions to further reduce memory footprint.
Spinor Fields
Data Structure
Fermion fields (spinors) are stored as 4-dimensional arrays containing n_color × n_dirac complex-valued SVectors.
Design Choice: Using 4 dimensions instead of 5 enables writing routines that process all Dirac components simultaneously, improving computational efficiency.
Creating Spinor Fields
# Create spinor field (n_dirac replaces gauge action parameter)
ψ = Spinorfield{backend,prec,n_dirac}(Ns, Ns, Ns, Nt)Initialization Methods
- Unit field:
ones!(ψ)- Sets all components to 1 - Random field:
gaussian_pseudofermions!(ψ)- Generates Gaussian random pseudofermions
Even-Odd Preconditioning
EvenOdd Wrapper
For even-odd preconditioned Dirac operators, spinor fields are wrapped in an EvenOdd struct:
ψ_eo = EvenOdd(ψ)This wrapper allows overloading all relevant functions to work with the preconditioned structure.
Memory Layout Optimization
Convention: Fields are defined on even sites, with all even sites mapped to the first half of the array for contiguous memory access.
Implementation: The map_to_half function handles the mapping between full lattice indices and the compressed even-site storage.
Benefits
- Reduced Memory: Only stores even sites explicitly
- Cache Efficiency: Contiguous memory layout improves cache performance
- Algorithmic Efficiency: Enables optimized even-odd preconditioned algorithms
API Documentation
The following types are available with full documentation:
MetaQCD.Fields.Gaugefield — TypeWrapper around a dense array or arrays of SU3 objects containing information about the global MPI-topology.
Gaugefield{B,T,GA,NFLOAT}(NX, NY, NZ, NT, β)
Gaugefield{B,T,GA,NFLOAT}(NX, NY, NZ, NT, β; numprocs_cart, halo_width)
Gaugefield(U::Gaugefield; no_halo, hw)
Gaugefield(parameters::ParameterSet)Creates a Gaugefield on backend B, i.e. an array of link-variables (SU3 matrices with T precision) of size 4 × NX × NY × NZ × NT with coupling parameter β and gauge action GA or a zero-initialized copy of U. NFLOAT specifies the number of floating point numbers per SU3 element (12, or 18) but for now it is bound to 18 on CPU backends.
The data layout of the field is dependent on the backend B: If B = CPU, then it is a 5D array of SMatrix{3,3,Complex{T},9} else, it is a 4-tuple of 5D arrays of SIMD.Vec{L,N} with L = {4, 2} for NFLOAT = {12, 18} with the component index being the slowest to improve coalescing on GPUs
Supported backends
CPU CUDABackend (provided CUDA.jl is loaded) ROCBackend (provided AMDGPU.jl is loaded)
Supported gauge actions
WilsonGaugeAction SymanzikTreeGaugeAction (Lüscher-Weisz) IwasakiGaugeAction DBW2GaugeAction
MetaQCD.Fields.Colorfield — TypeWrapper around a 5-dimensional dense array of statically sized 3x3 matrices contatining information about the global MPI-topology.
Colorfield{B,T}(NX, NY, NZ, NT)
Colorfield{B,T}(NX, NY, NZ, NT; numprocs_cart, halo_width)
Colorfield(u::AbstractField)Creates a Colorfield on B, i.e. an array of 3-by-3 T-precision matrices of size 4 × NX × NY × NZ × NT or a zero-initialized Colorfield of the same size as u
Supported backends
CPU CUDABackend (provided CUDA.jl is loaded) ROCBackend (provided AMDGPU.jl is loaded)
MetaQCD.Fields.Expfield — TypeWrapper around a 5-dimensional dense array of ExpiQCoeffs objects contatining information about the global MPI-topology. The array holds the Q-matrices and all the exponential parameters needed for stout-force recursion.
Expfield{B,T}(NX, NY, NZ, NT)
Expfield{B,T}(NX, NY, NZ, NT; numprocs_cart, halo_width)
Expfield(u::AbstractField)Creates a Expfield on B, i.e. an array of T-precison ExpiQCoeffs objects of size 4 × NX × NY × NZ × NT or of the same size as u.
Supported backends
CPU CUDABackend (provided CUDA.jl is loaded) ROCBackend (provided AMDGPU.jl is loaded)
MetaQCD.Fields.Spinorfield — TypeWrapper around a dense array or arrays of spinor/vector objects containing information about the global MPI-topology.
Spinorfield{B,T,ND}(NX, NY, NZ, NT)
Spinorfield{B,T,ND}(NX, NY, NZ, NT; numprocs_cart, halo_width)
Spinorfield(ψ::Spinorfield)
Spinorfield(f::AbstractField; staggered=false)Creates a Spinorfield on B, i.e. an array of link-variables (numcolors×ND complex vectors with T precision) of size NX × NY × NZ × NT or a zero-initialized copy of ψ. If staggered=true, the number of Dirac degrees of freedom (ND) is reduced to 1 instead of 4.
The data layout of the field is dependent on the backend B: If B = CPU, then it is a 4D array of SVector{3ND,Complex{T}} else, it is a 5D array of SIMD.Vec{L,N} with L = {2, 4} for ND = {1, 4} with the component index being the slowest to improve coalescing on GPUs
Supported backends
CPU CUDABackend (provided CUDA.jl is loaded) ROCBackend (provided AMDGPU.jl is loaded)