QDP++ User Guide:   Front Page   Introduction   Data Types   Functions   Simple IO   Record IO  Compilation   Spin Conventions   Implementation

Implementation Details

Implementation Details

  1. Header Files
  2. Supported Operations
  3. Subsets and Maps
  4. Infix operators
  5. Functions
  6. Additional functions (specific to QDP)
  7. In place functions
  8. Broadcasts
  9. Global reductions
  10. Global comparisons
  11. Accessors
  12. More exotic functions
  13. Operations on subtypes

Header Files

The following table lists some of the QDP headers.

Supported Operations

This section describes in some detail the names and functionality for all functions in the interface involving linear algebra with and without shifts.

All QDP objects are of type QDPType, and QDP functions act on objects of this base class type. Unless otherwise indicated, operations occur on all sites in the specified subset of the target, often an assignment statement or object definition. The indexing of a QDPType returns an lvalue suitable for assignment (but not object definition). It is also used to narrow the lattice sites participating in a global reduction since the result of such a reduction is a lattice scalar, hence are independent of lattice sites.

Supported operations are listed below. Convention: prototypes are basically of the form:

QDPType  unary_function(const QDPType&)
QDPType  binary_function(const QDPType&, const QDPType&)

Subsets and Maps

  • Set::make(const SetFunc&)
    • Set construction of ordinality num subsets. func maps coordinates to a coloring in [0,num)
  • Map::make(const MapFunc&)
    • Construct a map function from source sites to the dest site.

Infix operators

infix

e.g., operator-

  • -
    • negation
  • +
    • unary plus
  • ~
    • bitwise not
  • !
    • boolean not

infix

e.g., operator+

  • +
    • addition
  • -
    • subtraction
  • *
    • multiplication
  • /
    • division
  • %
    • mod
  • &
    • bitwise and
  • |
    • bitwise or
  • ^
    • bitwise exclusive or
  • <<
    • left-shift
  • >>
    • right-shift

Comparisons

Operations returning booleans, e.g., operator<

  • <
    • less than
  • <=
    • less than or equal
  • >
    • greater than
  • >=
    • greater than or equal
  • ==
    • equality
  • !=
    • inequality
  • &&
    • logical and
  • ||
    • logical or

Assignments

e.g., operator+=

  • =,
  • +=,
  • -=,
  • *=,
  • /=

Ternary

  • where(bool,arg1,arg2)
    • the C ternary ? operator (bool) ? arg1 : arg2

Functions

As in the standard C mathematics library.

infix

infix

Additional functions (specific to QDP)

infix

infix

In place functions

Broadcasts

Broadcasts via assignments

i.e. via operator=

  • LHS = constant
    • globally set conforming LHS to constant
  • LHS = zero
    • globally set LHS to zero

Global reductions

Global comparisons

Global checks

Accessors

Peeking and poking (accessors) into various component indices of objects.

  • QDP::peekSite (arg1,multi1d<int> coords)
    • return object located at lattice coords
  • QDP::peekColor (arg1,int row,int col)
    • return color matrix elem row and col
  • QDP::peekColor (arg1,int row)
    • return color vector elem row
  • QDP::peekSpin (arg1,int row,int col)
    • return spin matrix elem row and col
  • QDP::peekSpin (arg1,int row)
    • return spin vector elem row
  • QDP::pokeSite (dest,src,multi1d<int> coords)
    • insert into site given by coords
  • QDP::pokeColor (dest,src,int row,int col)
    • insert into color matrix elem row and col
  • QDP::pokeColor (dest,src,int row)
    • insert into color vector elem row
  • QDP::pokeSpin (dest,src,int row,int col)
    • insert into spin matrix elem row and col
  • QDP::pokeSpin (dest,src,int row)
    • insert into spin vector elem row

More exotic functions

  • QDP::spinProject (QDPType psi, int dir, int isign)
    • Applies spin projection (1 + isign* $\gamma_\mu$)*psi returning a half spin vector or matrix
  • QDP::spinReconstruct (QDPType psi, int dir, int isign)
    • Applies spin reconstruction of (1 + isign* $\gamma_\mu$)*psi returning a full spin vector or matrix
  • QDP::quarkContract13 (a,b)
    • Epsilon contract 2 quark propagators and return a quark propagator. This is used for diquark constructions. Eventually, it could handle larger QDP::Nc. The numbers represent which spin index to sum over.
    • The sources and targets must all be propagators but not necessarily of the same lattice type. Effectively, one can use this to construct an anti-quark from a di-quark contraction. In explicit index form, the operation quarkContract13 does

      \‍[\mathrm{target}^{k' k}_{\alpha\beta} =
 \epsilon^{i j k}\epsilon^{i' j' k'}* \mbox{source1}^{i i'}_{\rho\alpha}* \mbox{source2}^{j j'}_{\rho\beta}\‍]

      and is (currently) only appropriate for QPD::Nc=3 (i.e. SU(3)).
  • QDP::quarkContract14 (a,b)

    • Epsilon contract 2 quark propagators and return a quark propagator:

    \‍[\mbox{target}^{k' k}_{\alpha\beta} =
    \epsilon^{i j k}\epsilon^{i' j' k'}*\mbox{source1}^{i i'}_{\rho\alpha}*\mbox{source2}^{j j'}_{\beta\rho}\‍]

  • QDP::quarkContract23 (a,b)
    • Epsilon contract 2 quark propagators and return a quark propagator.

      \‍[\mbox{target}^{k' k}_{\alpha\beta} =
    \epsilon^{i j k}\epsilon^{i' j' k'}*\mbox{source1}^{i
    i'}_{\alpha\rho}*\mbox{source2}^{j j'}_{\rho\beta}\‍]

  • QDP::quarkContract24 (a,b)
    • Epsilon contract 2 quark propagators and return a quark propagator.

      \‍[\mbox{target}^{k' k}_{\alpha\beta} =
    \epsilon^{i j k}\epsilon^{i' j' k'}*\mbox{source1}^{i i'}_{\rho\alpha}*\mbox{source2}^{j j'}_{\beta\rho}\‍]

  • QDP::quarkContract12 (a,b) Epsilon contract 2 quark propagators and return a quark propagator.

    \‍[\mbox{target}^{k' k}_{\alpha\beta} =
    \epsilon^{i j k}\epsilon^{i' j' k'}*\mbox{source1}^{i
    i'}_{\rho\rho}*\mbox{source2}^{j j'}_{\alpha\beta}\‍]

  • QDP::quarkContract34 (a,b)
    • Epsilon contract 2 quark propagators and return a quark propagator.

      \‍[\mbox{target}^{k' k}_{\alpha\beta} =
    \epsilon^{i j k}\epsilon^{i' j' k'}*\mbox{source1}^{i i'}_{\alpha\beta}*\mbox{source2}^{j j'}_{\rho\rho}\‍]

  • QDP::colorContract (a,b,c)
    • Epsilon contract 3 color primitives and return a primitive scalar.
    • The sources and targets must all be of the same primitive type (a matrix or vector) but not necessarily of the same lattice type. In explicit index form, the operation colorContract does

      \‍[\mbox{target} =
  \epsilon^{i j k}\epsilon^{i' j' k'}* \mbox{source1}^{i i'}* \mbox{source2}^{j j'}*\mbox{source3}^{k k'}
\‍]

    • or

      \‍[\mbox{target} =
 \epsilon^{i j k}* \mbox{source1}^{i}* \mbox{source2}^{j}*\mbox{source3}^{k}
\‍]

      and is (currently) only appropriate for Nc=3 (or SU(3)).

Operations on subtypes

Subtypes

Types in the QDP interface are parameterized by a variety of types, and can look like the following:

typedef OLattice<PScalar<PColorMatrix<RComplex<float>, Nc> > > LatticeColorMatrix
typedef OLattice<PSpinVector<PColorVector<RComplex<float>, Nc>, Ns> > LatticeFermion
machinetype Word type
Basic machine types
  • int
  • float
  • double
  • bool
Reality type
  • RComplex
  • RScalar
Primitive type
  • PScalar
  • PVector
  • PMatrix
  • PSeed
Inner grid type
  • IScalar
  • ILattice.
Outer grid type
  • OScalar
  • OLattice.

Operations

Supported operations for each type level are as follows:

Grid type
  • OScalar
  • OLattice
  • IScalar
  • ILattice

All operations listed in Sections Infix operators - More exotic functions

Primitive type
PScalar
All operations listed in Sections Infix operators - More exotic functions
PMatrix
  • Unary
    • -(PMatrix)
    • +(PMatrix)
  • Binary -(PMatrix,PMatrix)
    • +(PMatrix,PMatrix)
    • *(PMatrix,PScalar)
    • *(PScalar,PMatrix)
    • *(PMatrix,PMatrix)
  • Comparisons
    • none
  • Assignments
    • =(PMatrix)
    • =(PScalar)
    • -=(PMatrix)
    • +=(PMatrix)
    • *=(PScalar)
  • Ternary
  • C-lib funcs
    • none
  • QDP funcs
    • all
  • In place funcs
    • all
  • Reductions
    • all
  • Global Comparisons
    • none
PVector
PSpinMatrix
PSpinVector
PColorMatrix
PColorVector
Reality
  • RScalar
  • RComplex
All operations listed in Sections Infix operators - More exotic functions.
Word
  • int
  • float
  • double
  • bool
All operations listed in Sections Infix operators - More exotic functions. Only boolean operations allowed on bool.

Detailed function description

The purpose of this section is to show some explicit prototypes and usages for the functions described in Section Supported Operations. In that section, all the functions are shown with complete information on which operations and their meaning are supported on some combination of types. The purpose of this section is something like the inverse - namely show all the functions and what are some (selected) usages.

Unary Operations

Elementary unary functions on reals
Elementary unary functions on complex values
Assignment operations
  • Syntax
    • Type operator=(const Type& r, const Type& a)
  • Meaning
    • r = a
  • Type
    • All numeric types
Shifting
  • Syntax
    • Type QDP::shift (const Type& a, int sign, int dir)
  • Meaning
    • r = a
  • Type
    • All numeric types
Hermitian conjugate
Transpose
Transpose of color indices
Transpose of spin indices
Complex conjugate

Type conversion

Convert integer or float to double
Convert double to float
Integer to real
Real to integer
Real to float

The QDP type QDP::Real is not a primitive type, so an explicit conversion is provided.

Double to double

The QDP type QDP::RealD is not a primitive type, so an explicit conversion is provided.

Boolean to bool

The QDP type QDP::Boolean is not a primitive type, so an explicit conversion is provided.

Operations on complex arguments

Convert real and imaginary to complex
  • Syntax
    • Type QDP::cmplx (const Type1& a, const Type2& b)
  • Meaning
    • Re r = a, Im r = b
  • Type1
    • Constant
    • QDP::Real
    • Also corresponding lattice variants
  • Type2
    • Constant
    • QDP::Real
    • Also corresponding lattice variants
  • Type
Real part of complex
  • Syntax
  • Meaning
    • r = Re a
Imaginary part of complex
  • Syntax
  • Meaning
    • r = Im a

Component extraction and insertion

Accessing a site object
  • Syntax
    • Type QDP::peekSite (const LatticeType& a, const multi1d<int>& c)
  • Meaning
    • r = a[x]
Accessing a color matrix element
Inserting a color matrix element
Accessing a color vector element

This function will extract the desired color component with all the other indices unchanged.

A lattice color vector is another name (typedef) for a QDP::LatticeStaggeredFermion. Namely, an object that is vector in color spin and a scalar in spin space. Together with spin accessors, one can build a QPD::LatticeDiracFermion.

Inserting a color vector element

This function will extract the desired color component with all the other indices unchanged.

A lattice color vector is another name (typedef) for a QDP::LatticeStaggeredFermion. Namely, an object that is vector in color spin and a scalar in spin space. Together with spin accessors, one can build a QDP::LatticeDiracFermion{} or a QDP::LatticeDiracPropagator.

Accessing a spin matrix element
Inserting a spin matrix element
Accessing a spin vector element

This function will extract the desired spin component with all the other indices unchanged.

A lattice spin vector is an object that is a vector in spin space and a scalar in color space. Together with color accessors, one can build a QDP::LatticeDiracFermion or a QDP::LatticeDiracPropagator.

Inserting a spin vector element

This function will extract the desired spin component with all the other indices unchanged.

A lattice spin vector is an object that is a vector in spin space and a scalar in color space. Together with color accessors, one can build a QDP::LatticeDiracFermion or a QDP::LatticeDiracPropagator.

Trace of matrix

Traces over all matrix indices. It is an error to trace over a vector index. It will trivially trace a scalar variable.

Color trace of matrix

Traces only over color matrix indices. It is an error to trace over a color vector index. All other indices are left untouched. It will trivially trace a scalar variable.

Spin trace of matrix

Traces only over spin matrix indices. It is an error to trace over a spin vector index. All other indices are left untouched. It will trivially trace a scalar variable.

Dirac spin projection
Dirac spin reconstruction

Binary Operations with Constants

Multiplication by real constant
  • Syntax
    • Type operator*(const QDP::Real& a, const Type& b)
    • Type operator*(const Type& b, const QDP::Real& a)
  • Meaning
    • r = a*b (a real, constant)
  • Type
    • All floating types
Multiplication by complex constant
  • Syntax
    • Type operator*(const QDP::Real& a, const Type& b)\
    • Type operator*( const Type& b, const QDP::Real &a)\
  • Meaning
    • r = a*b (a complex, constant)
  • Type
    • All numeric types
Left multiplication by gamma matrix
Right multiplication by gamma matrix

See Section Spin Conventions for details on $\gamma$-matrix conventions.

Binary Operations with Fields

Division of real fields
  • Syntax
    • Type operator/(const Type& a, const Type& b)
  • Meaning
    • r = a / b
  • Type
    • All numeric types
Addition
  • Syntax
    • Type operator+(const Type& a, const Type& b)
  • Meaning
    • r = a + b
  • Type
    • All numeric types
Subtraction
  • Syntax
    • Type operator-(const Type& a, const Type& b)
  • Meaning
    • r = a - b
  • Type
    • All numeric types
Multiplication: uniform types
ColorMatrix matrix from outer product
Left multiplication by gauge matrix
Right multiplication by gauge matrix

Boolean and Bit Operations

Comparisons
Elementary binary operations on integers
  • Syntax
    • Type2 op(const Type& a, const Type1& b)
  • Meaning
    • r = a op b
    • r = op(a, b)
  • op
    • <<
    • >>
    • &
    • |
    • ^
    • mod
    • max
    • min
Elementary binary operations on reals
  • Syntax
    • Type2 op(const Type& a, const Type1& b)
  • Meaning
    • r = a op b
    • r = op(a, b)
  • op
    • mod
    • max
    • min
  • Type
Boolean Operations
Copymask
  • Syntax
    • void QDP::copymask (const Type2& r, const Type1& a, const Type1& b)
  • Meaning
    • r = b if a is true
  • Type
    • All numeric types

Reductions

Global reductions sum over all lattice sites in the subset specified by the left hand side of the assignment.

Norms
Inner products
Global sums
  • Syntax
  • Meaning
    • $r = \sum a$
  • Type
    • All numeric types

Global comparisons

Find the maximum or minimum of a quantity across the lattice. These operations do not have subset variants.

Global maximum
  • Syntax
  • Meaning
    • $r = max_x a(x)$
  • Type
    • Only reals
Global minimum
  • Syntax
  • Meaning
    • $r = min_x a(x)$
  • Type
    • Only reals

Fills

Coordinate function fills
  • Syntax
  • Meaning
    • r = f(d) for direction d
    • Returns the lattice coordinates in direction d

The call Layout::latticeCoordinate (d) returns an integer lattice field with a value on each site equal to the integer value of the dth space-time coordinate on that site.

Constant fills
  • Syntax
    • LatticeType operator=(LatticeType& r, const Type& a)
  • Meaning
    • r = a for all sites
  • Types
    • All non-lattice objects
  • Example

Constant (or lattice global) fills are always defined for lattice scalar objects broadcasting to all lattice sites. These are broadcasts of a lattice scalar type to a conforming lattice type.

N.B. one cannot fill a QDP::LatticeColorVector with a QDP::Real.

Only sets the diagonal part of a field to a constant a times the identity.

This fill can only be used on primitive types that are scalars or matrices. E.g., it can not be used for a vector field since there is no meaning of diagonal. N.B., a zero cannot be distinguished from a constant like 1. To initialize to zero the zero argument must be used.

Zero fills
  • Syntax
    • Type operator=(Type& r, const Zero& zero)
  • Meaning
    • r = 0
  • Type
    • All numeric types
  • Example

This is the only way to fill a vector field with a constant (like zero).

Uniform random number fills
  • Syntax
  • Meaning
    • r random, uniform on [0,1]
  • Type
    • All floating types
Gaussian random number fills
  • Syntax
  • Meaning
    • r random, normal gaussian
  • Type
    • All floating types
Seeding the random number generator
  • Syntax
    • void RNG::setrn (const QDP::RandomState& a)
  • Meaning
    • Initialize the random number generator with seed state a.
Extracting the random number generator seed
  • Syntax
    • void RNG::savern ( QDP::RandomState& r)
  • Meaning
    • Extract the random number generator into seed state r