.. Grid documentation .. highlight:: cpp Welcome to Grid's documentation! ================================================== .. toctree:: :maxdepth: 2 :caption: Contents: Preliminaries ==================================== .. attention:: manual version 1 (CD) Grid is primarily an *application* *development* *interface* (API) for structured Cartesian grid codes and written in C++11. In particular it is aimed at Lattice Field Theory simulations in general gauge theories, but with a particular emphasis on supporting SU(3) and U(1) gauge theories relevant to hadronic physics. Who will use this library --------------------------- As an application development interface *Grid* is primarily a programmers tool providing the building blocks and primitives for constructing lattice gauge theory programmes. Grid functionality includes: * Data parallel primitives, similar to QDP++ * gauge and fermion actions * solvers * gauge and fermion force terms * integrators and (R)HMC. * parallel field I/O * object serialisation (text, XML, JSON...) Grid is intended to enable the rapid and easy development of code with reasonably competitive performance. It is first and foremost a *library* to which people can programme, and develop new algorithms and measurements. As such, it is very much hoped that peoples principle point of contact with Grid will be in the wonderfully rich C++ language. Since import and export procedures are provided for the opaque lattice types it should be possible to call Grid from other code bases. Grid is most tightly coupled to the Hadrons package developed principally by Antonin Portelli. This package is entirely composed against the Grid data parallel interface. Interfacing to other packages is also possible. Several regression tests that combine Grid with Chroma are included in the Grid distribution. Further, Grid has been successfully interfaced to * The Columbia Physics System * The MILC code Data parallel interface ---------------------------------------------------------------------------------- Most users will wish to interact with Grid above the data parallel *Lattice* interface. At this level a programme is simply written as a series of statements, addressing entire lattice objects. Implementation details may be provided to explain how the code works, but are not strictly part of the API. **Example** For example, as an implementation detail, in a single programme multiple data (SPMD) message passing supercomputer the main programme is trivially replicated on each computing node. The data parallel operations are called *collectively* by all nodes. Any scalar values returned by the various reduction routines are the same on each node, resulting in (for example) the same decision being made by all nodes to terminate an iterative solver on the same iteration. Internal development ------------------------------------------ Internal developers may contribute to Grid at a level below the data parallel interface. Specifically, development of new lattice Dirac operators, for example, or any codes directly interacting with the * Communicators * Simd * Tensor * Stencil will make use of facilities provided by to assist the creation of high performance code. The internal data layout complexities will be exposed to some degree and the interfaces are subject to change without notice as HPC architectures change. Since some of the internal implementation details are needed to explain the design strategy of grid these will be documented, but labelled as *implementation dependent* Reasonable endeavours will be made to preserve functionality where practical but no guarantees are made. Reporting Bugs =================================== To help us tracking and solving more efficiently issues with Grid, please report problems using the issue system of GitHub rather than sending emails to Grid developers. When you file an issue, please go though the following checklist: * Check that the code is pointing to the HEAD of develop or any commit in master which is tagged with a version number. * Give a description of the target platform (CPU, network, compiler). Please give the full CPU part description, using for example cat /proc/cpuinfo | grep 'model name' | uniq (Linux) or sysctl machdep.cpu.brand_string (macOS) and the full output the --version option of your compiler. * Give the exact configure command used. * Attach config.log. * Attach grid.config.summary. * Attach the output of make V=1. * Describe the issue and any previous attempt to solve it. If relevant, show how to reproduce the issue using a minimal working example. Download, installation and build ========================================= Required libraries ---------------------------------------- * GMP, * MPFR * Eigen: bootstrapping grid downloads and uses for internal dense matrix (non-QCD operations) the Eigen library. Grid optionally uses: * HDF5 * LIME for ILDG and SciDAC file format support. * FFTW either generic version or via the Intel MKL library. * LAPACK either generic version or Intel MKL library. Compilers --------- * Intel ICPC v17 and later * Clang v3.5 and later (need 3.8 and later for OpenMP) * GCC v4.9.x * GCC v6.3 and later (recommended) **Important:** Some versions of GCC appear to have a bug under high optimisation (-O2, -O3). The safety of these compiler versions cannot be guaranteed at this time. Follow Issue 100 for details and updates. GCC v5.x GCC v6.1, v6.2 Quick start ------------ First, start by cloning the repository:: git clone https://github.com/paboyle/Grid.git Then enter the cloned directory and set up the build system:: cd Grid ./bootstrap.sh Now you can execute the `configure` script to generate makefiles (here from a build directory):: mkdir build; cd build ../configure --enable-precision=double --enable-simd=AVX --enable-comms=mpi-auto \ --prefix= where:: --enable-precision=single|double sets the **default precision**. Since this is largely a benchmarking convenience, it is anticipated that the default precision may be removed in future implementations, and that explicit type selection be made at all points. Naturally, most code will be type templated in any case.:: --enable-simd=GEN|SSE4|AVX|AVXFMA|AVXFMA4|AVX2|AVX512|NEONv8|QPX sets the **SIMD architecture**, :: --enable-comms=mpi|none selects whether to use MPI communication (mpi) or no communication (none). :: --prefix= should be passed the prefix path where you want to install Grid. Other options are detailed in the next section, you can also use :: configure --help to display them. Like with any other program using GNU autotool, the :: CXX, CXXFLAGS, LDFLAGS, ... environment variables can be modified to customise the build. Finally, you can build, check, and install Grid:: make; make check; make install If you want to build all the tests just use `make tests`. Detailed build configuration options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. todo:: CD: The double dash here gets turned into a pdf long dash. Not good. ======================================== ============================================================================================================================== Option usage ======================================== ============================================================================================================================== `--prefix=` installation prefix for Grid. `--with-gmp=` look for GMP in the UNIX prefix `` `--with-mpfr=` look for MPFR in the UNIX prefix `` `--with-fftw=` look for FFTW in the UNIX prefix `` `--with-lime=` look for c-lime in the UNIX prefix `` `--enable-lapack[=]` enable LAPACK support in Lanczos eigensolver. A UNIX prefix containing the library can be specified (optional). `--enable-mkl[=]` use Intel MKL for FFT (and LAPACK if enabled) routines. A UNIX prefix containing the library can be specified (optional). `--enable-simd=` setup Grid for the SIMD target `` (default: `GEN`). A list of possible SIMD targets is detailed in a section below. `--enable-gen-simd-width=` select the size (in bytes) of the generic SIMD vector type (default: 32 bytes). `--enable-precision={single|double}` set the default precision (default: `double`). `--enable-precision=` use `` for message passing (default: `none`). A list of possible SIMD targets is detailed in a section below. `--enable-rng={sitmo|ranlux48|mt19937}` choose the RNG (default: `sitmo`). `--disable-timers` disable system dependent high-resolution timers. `--enable-chroma` enable Chroma regression tests. `--enable-doxygen-doc` enable the Doxygen documentation generation (build with `make doxygen-doc`) ======================================== ============================================================================================================================== .. todo:: CD: Somewhere, please provide more explanation of the --enable--gen-simd-width value .. todo:: CD: Are there really two --enable-precision lines? Possible communication interfaces ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following options can be use with the `--enable-comms=` option to target different communication interfaces: =============== ========================================================================================== Description =============== ========================================================================================== `none` no communications `mpi` MPI communications with compiler CXX `mpi-auto` MPI communications with compiler CXX but clone flags from MPICXX =============== ========================================================================================== For the MPI interfaces the optional `-auto` suffix instructs the `configure` scripts to determine all the necessary compilation and linking flags. This is done by extracting the informations from the MPI wrapper specified in the environment variable `MPICXX` (if not specified `configure` will scan though a list of default names). The `-auto` suffix is not supported by the Cray environment wrapper scripts. Use the standard wrappers ( `CXX=CC` ) set up by Cray `PrgEnv` modules instead. .. todo:: CD: Later below, there is an "mpi3". Should it be listed and explained here? Is there an "mpit"? Possible SIMD types ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following options can be use with the `--enable-simd=` option to target different SIMD instruction sets: ============ ===================================================================================================================== `` Description ============ ===================================================================================================================== `GEN` generic portable vector code `SSE4` SSE 4.2 (128 bit) `AVX` AVX (256 bit) `AVXFMA` AVX (256 bit) + FMA `AVXFMA4` AVX (256 bit) + FMA4 `AVX2` AVX 2 (256 bit) `AVX512` AVX 512 bit `NEONv8` [ARM NEON](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/ch07s03.html) (128 bit) `QPX` IBM QPX (256 bit) ============ ===================================================================================================================== Alternatively, some CPU codenames can be directly used: ============ ===================================================================================================================== `` Description ============ ===================================================================================================================== `KNL` [Intel Xeon Phi codename Knights Landing](http://ark.intel.com/products/codename/48999/Knights-Landing) `SKL` [Intel Skylake with AVX512 extensions](https://ark.intel.com/products/codename/37572/Skylake#@server) `BGQ` Blue Gene/Q ============ ===================================================================================================================== Notes ^^^^^^^ * We currently support AVX512 for the Intel compiler and GCC (KNL and SKL target). Support for clang will appear in future versions of Grid when the AVX512 support in the compiler is more advanced. * For BG/Q only [bgclang](http://trac.alcf.anl.gov/projects/llvm-bgq) is supported. We do not presently plan to support more compilers for this platform. * BG/Q performances are currently rather poor. This is being investigated for future versions. * The vector size for the `GEN` target can be specified with the `configure` script option `--enable-gen-simd-width`. Build setup for Intel Knights Landing platform --------------------------------------------------------------------------------------- The following configuration is recommended for the Intel Knights Landing platform:: ../configure --enable-precision=double\ --enable-simd=KNL \ --enable-comms=mpi-auto \ --enable-mkl \ CXX=icpc MPICXX=mpiicpc The MKL flag enables use of BLAS and FFTW from the Intel Math Kernels Library. If you are working on a Cray machine that does not use the `mpiicpc` wrapper, please use:: ../configure --enable-precision=double\ --enable-simd=KNL \ --enable-comms=mpi \ --enable-mkl \ CXX=CC CC=cc If gmp and mpfr are NOT in standard places (/usr/) these flags may be needed:: --with-gmp= \ --with-mpfr= where `` is the UNIX prefix where GMP and MPFR are installed. Knight's Landing with Intel Omnipath adapters with two adapters per node presently performs better with use of more than one rank per node, using shared memory for interior communication. This is the mpi3 communications implementation. We recommend four ranks per node for best performance, but optimum is local volume dependent. :: ../configure --enable-precision=double\ --enable-simd=KNL \ --enable-comms=mpi3-auto \ --enable-mkl \ CC=icpc MPICXX=mpiicpc Build setup for Intel Haswell Xeon platform --------------------------------------------------------------------------------------- The following configuration is recommended for the Intel Haswell platform:: ../configure --enable-precision=double\ --enable-simd=AVX2 \ --enable-comms=mpi3-auto \ --enable-mkl \ CXX=icpc MPICXX=mpiicpc The MKL flag enables use of BLAS and FFTW from the Intel Math Kernels Library. If gmp and mpfr are NOT in standard places (/usr/) these flags may be needed:: --with-gmp= \ --with-mpfr= where `` is the UNIX prefix where GMP and MPFR are installed. If you are working on a Cray machine that does not use the `mpiicpc` wrapper, please use:: ../configure --enable-precision=double\ --enable-simd=AVX2 \ --enable-comms=mpi3 \ --enable-mkl \ CXX=CC CC=cc Since Dual socket nodes are commonplace, we recommend MPI-3 as the default with the use of one rank per socket. If using the Intel MPI library, threads should be pinned to NUMA domains using:: export I_MPI_PIN=1 This is the default. Build setup for Intel Skylake Xeon platform ---------------------------------------------------------------------------- The following configuration is recommended for the Intel Skylake platform:: ../configure --enable-precision=double\ --enable-simd=AVX512 \ --enable-comms=mpi3 \ --enable-mkl \ CXX=mpiicpc The MKL flag enables use of BLAS and FFTW from the Intel Math Kernels Library. If gmp and mpfr are NOT in standard places (/usr/) these flags may be needed:: --with-gmp= \ --with-mpfr= \ where `` is the UNIX prefix where GMP and MPFR are installed. If you are working on a Cray machine that does not use the `mpiicpc` wrapper, please use:: ../configure --enable-precision=double\ --enable-simd=AVX512 \ --enable-comms=mpi3 \ --enable-mkl \ CXX=CC CC=cc Since Dual socket nodes are commonplace, we recommend MPI-3 as the default with the use of one rank per socket. If using the Intel MPI library, threads should be pinned to NUMA domains using:: export I_MPI_PIN=1 This is the default. Build setup for AMD EPYC / RYZEN ---------------------------------------------------------------------------- The AMD EPYC is a multichip module comprising 32 cores spread over four distinct chips each with 8 cores. So, even with a single socket node there is a quad-chip module. Dual socket nodes with 64 cores total are common. Each chip within the module exposes a separate NUMA domain. There are four NUMA domains per socket and we recommend one MPI rank per NUMA domain. MPI-3 is recommended with the use of four ranks per socket, and 8 threads per rank. The following configuration is recommended for the AMD EPYC platform:: ../configure --enable-precision=double\ --enable-simd=AVX2 \ --enable-comms=mpi3 \ CXX=mpicxx If gmp and mpfr are NOT in standard places (/usr/) these flags may be needed:: --with-gmp= \ --with-mpfr= where `` is the UNIX prefix where GMP and MPFR are installed. Using MPICH and g++ v4.9.2, best performance can be obtained using explicit GOMP_CPU_AFFINITY flags for each MPI rank. This can be done by invoking MPI on a wrapper script omp_bind.sh to handle this. It is recommended to run 8 MPI ranks on a single dual socket AMD EPYC, with 8 threads per rank using MPI3 and shared memory to communicate within this node:: mpirun -np 8 ./omp_bind.sh ./Benchmark_dwf --mpi 2.2.2.1 --dslash-unroll --threads 8 --grid 16.16.16.16 --cacheblocking 4.4.4.4 .. todo:: CD: Maybe need bash highlighting, not cpp below - Generates warning Where omp_bind.sh does the following:: #!/bin/bash numanode=` expr $PMI_RANK % 8 ` basecore=`expr $numanode \* 16` core0=`expr $basecore + 0 ` core1=`expr $basecore + 2 ` core2=`expr $basecore + 4 ` core3=`expr $basecore + 6 ` core4=`expr $basecore + 8 ` core5=`expr $basecore + 10 ` core6=`expr $basecore + 12 ` core7=`expr $basecore + 14 ` export GOMP_CPU_AFFINITY="$core0 $core1 $core2 $core3 $core4 $core5 $core6 $core7" echo GOMP_CUP_AFFINITY $GOMP_CPU_AFFINITY $@ Build setup for laptops, other compilers, non-cluster builds ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Many versions of g++ and clang++ work with Grid, and involve merely replacing CXX (and MPICXX), and omit the enable-mkl flag. Single node builds are enabled with:: --enable-comms=none FFTW support that is not in the default search path may then enabled with:: --with-fftw= BLAS will not be compiled in by default, and Lanczos will default to Eigen diagonalisation. Execution model ============================================ Grid is intended to support performance portability across a many of platforms ranging from single processors to message passing CPU clusters and accelerated computing nodes. The library provides data parallel C++ container classes with internal memory layout that is transformed to map efficiently to SIMD architectures. CSHIFT facilities are provided, similar to HPF and cmfortran, and user control is given over the mapping of array indices to both MPI tasks and SIMD processing elements. Identically shaped arrays then be processed with perfect data parallelisation. Such identically shaped arrays are called conformable arrays. The transformation is based on the observation that Cartesian array processing involves identical processing to be performed on different regions of the Cartesian array. The library will both geometrically decompose into MPI tasks and across SIMD lanes. Local vector loops are parallelised with OpenMP pragmas. Data parallel array operations can then be specified with a SINGLE data parallel paradigm, but optimally use MPI, OpenMP and SIMD parallelism under the hood. This is a significant simplification for most programmers. The two broad optimisation targets are: * MPI, OpenMP, and SIMD parallelism Presently SSE4, ARM NEON (128 bits) AVX, AVX2, QPX (256 bits), and AVX512 (512 bits) targets are supported with aggressive use of architecture vectorisation intrinsic functions. * MPI between nodes with and data parallel offload to GPU's. For the latter generic C++ code is used both on the host and on the GPU, with a common vectorisation granularity. Accelerator memory model ---------------------------------------------- For accelerator targets it is assumed that heap allocations can be shared between the CPU and the accelerator. This corresponds to lattice fields having their memory allocated with *cudaMallocManaged* with Nvidia GPU's. Grid does not assume that stack or data segments share a common address space with an accelerator. * This constraint presently rules out porting Grid to AMD GPU's which do not support managed memory. * At some point in the future a cacheing strategy may be implemented to enable running on AMD GPU's Data parallel API ===================================== Data parallel array indices are divided into two types. * Internal indices, such as complex, colour, spin degrees of freedom * spatial (space-time) indices. The ranges of all internal degrees are determined by template parameters, and known at compile time. The ranges of spatial indices are dynamic, run time values and the Cartesian structure information is contained and accessed via `Grid` objects. Grid objects are the controlling entity for the decomposition of a distributed `Lattice` array across MPI tasks, nodes, SIMD lanes, accelerators. Threaded loops are used as appropriate on host code. (binary) Data parallel operations can only be performed between Lattice objects constructed from the same Grid pointer. These are called `conformable` operations. We will focus initially on the internal indices as these are the building blocks assembled in Lattice container classes. Every Lattice container class constructor requires a Grid object pointer. Tensor classes ---------------------------- The Tensor data structures are built up from fundamental scalar matrix and vector classes:: template class iScalar { private: vobj _internal ; } template class iVector { private: vobj _internal[N] ; } template class iMatrix { private: vobj _internal[N] ; } .. todo:: CD: Why is iMatrix only [N] and not [N][N]? These are template classes and can be passed a fundamental scalar or vector type, or nested to form arbitrarily complicated tensor products of indices. All mathematical expressions are defined to operate recursively, index by index. Presently the constants * Nc * Nd are globally predefined. However, this is planned for changed in future and policy classes for different theories (e.g. QCD, QED, SU2 etc...) will contain these constants and enable multiple theories to coexist more naturally. Arbitrary tensor products of fundamental scalar, vector and matrix objects may be formed in principle by the basic Grid code. For Lattice field theory, we define types according to the following tensor product structure ordering. The suffix "D" indicates either double types, and replacing with "F" gives the corresponding single precision type. .. todo:: CD: The test cases have R, which takes the compiled default. Do we want to expose that and say something here? .. todo:: CD: What is "Lattice" here? This section is about "iXXX" types. Maybe say a few more introductory words. ======= ======= ====== ====== =========== ======================= Lattice Lorentz Spin Colour scalar_type Field ======= ======= ====== ====== =========== ======================= Scalar Scalar Scalar Scalar RealD RealD Scalar Scalar Scalar Scalar ComplexD ComplexD Scalar Scalar Scalar Matrix ComplexD ColourMatrixD Scalar Vector Scalar Matrix ComplexD LorentzColourMatrixD Scalar Scalar Vector Vector ComplexD SpinColourVectorD Scalar Scalar Vector Vector ComplexD HalfSpinColourVectorD Scalar Scalar Matrix Matrix ComplexD SpinColourMatrixD ======= ======= ====== ====== =========== ======================= The types are implemented via a recursive tensor nesting system. .. todo:: CD: What choices are available for vtype? Is the "v" for "variable"? .. todo:: CD: Should we say iLorentzColourMatrix is a Grid-provided typename? Is there a list of similar convenience types? **Example** we declare:: template using iLorentzColourMatrix = iVector >, Nd > ; typedef iLorentzColourMatrix LorentzColourMatrixD; Arbitrarily deep tensor nests may be formed. Grid uses a positional and numerical rule to associate indices for contraction in the Einstein summation sense. ============= ======= ======== Symbolic name Number Position ============= ======= ======== LorentzIndex 0 left SpinIndex 1 middle ColourIndex 2 right ============= ======= ======== The conventions are that the index ordering left to right are: Lorentz, Spin, Colour. A scalar type (either real or complex, single or double precision) is be provided to the innermost structure. Tensor arithmetic rules (lib/tensors/Tensor_arith.h) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Arithmetic rules are defined on these types The multiplication operator follows the natural multiplication table for each index, index level by index level. `Operator *` == == == == x S V M == == == == S S V M V S S V M M V M == == == == The addition and subtraction rules disallow a scalar to be added to a vector, and vector to be added to matrix. A scalar adds to a matrix on the diagonal. *Operator* + and *Operator* - === == == == +/- S V M === == == == S S M V V M M M === == == == The rules for a nested objects are recursively inferred level by level from basic rules of multiplication addition and subtraction for scalar/vector/matrix. Legal expressions can only be formed between objects with the same number of nested internal indices. All the Grid QCD datatypes have precisely three internal indices, some of which may be trivial scalar to enable expressions to be formed. Arithmetic operations are possible where the left or right operand is a scalar type. **Example**:: LatticeColourMatrixD U(grid); LatticeColourMatrixD Udag(grid); Udag = adj(U); RealD unitary_err = norm2(U*adj(U) - 1.0); Will provide a measure of how discrepant from unitarity the matrix U is. Internal index manipulation (lib/tensors/Tensor_index.h) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ General code can access any specific index by number with a peek/poke semantic:: // peek index number "Level" of a vector index template auto peekIndex (const vtype &arg,int i); // peek index number "Level" of a vector index template auto peekIndex (const vtype &arg,int i,int j); // poke index number "Level" of a vector index template void pokeIndex (vtype &pokeme,arg,int i) // poke index number "Level" of a matrix index template void pokeIndex (vtype &pokeme,arg,int i,int j) .. todo:: CD: The are the choices for "vtype"? .. todo:: CD: The example below does not use the template pair shown above. It is good, but perhaps, also show the pair form of the same example if there is one. **Example**:: for (int mu = 0; mu < Nd; mu++) { U[mu] = PeekIndex(Umu, mu); } Similar to the QDP++ package convenience routines are provided to access specific elements of vector and matrix internal index types by physics name or meaning aliases for the above routines with the appropriate index constant. * peekColour * peekSpin * peekLorentz and * pokeColour * pokeSpin * pokeLorentz For example, we often store Gauge Fields with a Lorentz index, but can split them into polarisations in relevant pieces of code. **Example**:: for (int mu = 0; mu < Nd; mu++) { U[mu] = peekLorentz(Umu, mu); } For convenience, direct access as both an l-value and an r-value is provided by the parenthesis operator () on each of the Scalar, Vector and Matrix classes. For example one may write **Example**:: ColourMatrix A, B; A()()(i,j) = B()()(j,i); bearing in mind that empty parentheses are need to address a scalar entry in the tensor index nest. The first (left) empty parentheses move past the (scalar) Lorentz level in the tensor nest, and the second (middle) empty parantheses move past the (scalar) spin level. The (i,j) index the colour matrix. Other examples are easy to form for the many cases, and should be obvious to the reader. This form of addressing is convenient and saves peek, modifying, poke multiple temporary objects when both spin and colour indices are being accessed. There are many cases where multiple lines of code are required with a peek/poke semantic which are easier with direct l-value and r-value addressing. Matrix operations ^^^^^^^^^^^^^^^^^^^^^^^^^^ Transposition and tracing specific internal indices are possible using:: template auto traceIndex (const vtype &arg) template auto transposeIndex (const vtype &arg) These may be used as **Example**:: LatticeColourMatrixD Link(grid); ComplexD link_trace = traceIndex (Link); Again, convenience aliases for QCD naming schemes are provided via * traceColour * traceSpin * transposeColour * transposeSpin **Example**:: ComplexD link_trace = traceColour (Link); The operations only makes sense for matrix and scalar internal indices. The trace and transpose over all indices is also defined for matrix and scalar types:: template auto trace(const iMatrix &arg) -> iScalar template auto transpose(const iMatrix &arg ) -> iMatrix Similar functions are: * conjugate * adjoint The traceless anti-Hermitian part is taken with:: template iMatrix Ta(const iMatrix &arg) Reunitarisation (or reorthogonalisation) is enabled by:: .. todo:: CD: U(3) or SU(3) projection? template iMatrix ProjectOnGroup(const iMatrix &arg) **Example**:: LatticeColourMatrixD Mom(grid); LatticeColourMatrixD TaMom(grid); TaMom = Ta(Mom); Querying internal index structure ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Templated code may find it useful to use query functions on the Grid datatypes they are provided. For example general Serialisation and I/O code can inspect the nature of a type a routine has been asked to read from disk, or even generate descriptive type strings:: //////////////////////////////////////////////////// // Support type queries on template params: //////////////////////////////////////////////////// // int _ColourScalar = isScalar(); // int _ColourVector = isVector(); // int _ColourMatrix = isMatrix(); template int isScalar(void) template int isVector(void) template int isMatrix(void) **Example** (lib/parallelIO/IldgIO.h):: template std::string ScidacRecordTypeString(int &colors, int &spins, int & typesize,int &datacount) { ///////////////////////////////////////// // Encode a generic tensor as a string ///////////////////////////////////////// typedef typename getPrecision::real_scalar_type stype; int _ColourN = indexRank(); int _ColourScalar = isScalar(); int _ColourVector = isVector(); int _ColourMatrix = isMatrix(); int _SpinN = indexRank(); int _SpinScalar = isScalar(); int _SpinVector = isVector(); int _SpinMatrix = isMatrix(); int _LorentzN = indexRank(); int _LorentzScalar = isScalar(); int _LorentzVector = isVector(); int _LorentzMatrix = isMatrix(); std::stringstream stream; stream << "GRID_"; stream << ScidacWordMnemonic(); if ( _LorentzVector ) stream << "_LorentzVector"<<_LorentzN; if ( _LorentzMatrix ) stream << "_LorentzMatrix"<<_LorentzN; if ( _SpinVector ) stream << "_SpinVector"<<_SpinN; if ( _SpinMatrix ) stream << "_SpinMatrix"<<_SpinN; if ( _ColourVector ) stream << "_ColourVector"<<_ColourN; if ( _ColourMatrix ) stream << "_ColourMatrix"<<_ColourN; if ( _ColourScalar && _LorentzScalar && _SpinScalar ) stream << "_Complex"; typesize = sizeof(typename vobj::scalar_type); if ( _ColourMatrix ) typesize*= _ColourN*_ColourN; else typesize*= _ColourN; if ( _SpinMatrix ) typesize*= _SpinN*_SpinN; else typesize*= _SpinN; }; Inner and outer products ^^^^^^^^^^^^^^^^^^^^^^^^^ We recursively define (tensors/Tensor_inner.h), ultimately returning scalar in all indices:: ///////////////////////////////////////////////////////////////////////// // innerProduct Scalar x Scalar -> Scalar // innerProduct Vector x Vector -> Scalar // innerProduct Matrix x Matrix -> Scalar ///////////////////////////////////////////////////////////////////////// template auto innerProductD (const iScalar& lhs,const iScalar& rhs) template auto innerProductD (const iVector& lhs,const iVector& rhs) template auto innerProductD (const iMatrix& lhs,const iMatrix& rhs) template auto innerProduct (const iScalar& lhs,const iScalar& rhs) template auto innerProduct (const iVector& lhs,const iVector& rhs) template auto innerProduct (const iMatrix& lhs,const iMatrix& rhs) The sum is always performed in double precision for the innerProductD variant. We recursively define (tensors/Tensor_outer.h):: ///////////////////////////////////////////////////////////////////////// // outerProduct Scalar x Scalar -> Scalar // Vector x Vector -> Matrix ///////////////////////////////////////////////////////////////////////// template auto outerProduct (const iScalar& lhs,const iScalar& rhs) template auto outerProduct (const iVector& lhs,const iVector& rhs) Functions of Tensor ^^^^^^^^^^^^^^^^^^^^^^^^^ The following unary functions are defined, which operate element by element on a tensor data structure:: sqrt(); rsqrt(); sin(); cos(); asin(); acos(); log(); exp(); abs(); Not(); toReal(); toComplex(); Element wise functions are defined for:: div(tensor,Integer); mod(tensor,Integer); pow(tensor,RealD); Matrix exponentiation (as opposed to element wise exponentiation is implemented via power series in:: Exponentiate(const Tensor &r ,RealD alpha, Integer Nexp = DEFAULT_MAT_EXP) the exponentiation is distributive across vector indices (i.e. proceeds component by component for a LorentzColourMatrix). Determinant is similar:: iScalar Determinant(const Tensor &r ) Vectorisation -------------- Internally, Grid defines a portable abstraction SIMD vectorisation, via the following types: * vRealF * vRealD * vComplexF * vComplexD .. todo:: CD: Maybe say something about how SIMD vectorization works here. Does a vRealF collect values for several SIMD lanes at once? These have the usual range of arithmetic operators and functions acting upon them. They do not form part of the API, but are mentioned to (partially) explain the need for controlling the layout transformation in lattice objects. They are documented further in the Internals chapter. .. todo:: CD: Might they be needed for interfacing with external code? Coordinates ------------ The Grid is define on a N-dimensional set of integer coordinates. The maximum dimension is eight, and indexes in this space make use of the Coordinate class. The coordinate class shares a similar interface to `std::vector`, but contains all data within the object, and has a fixed maximum length (template parameter). **Example**:: const int Nd=4; Coordinate point(Nd); for(int i=0;i