2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: ./lib/lattice/Lattice_base.h
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
Author: paboyle <paboyle@ph.ed.ac.uk>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2015-05-11 19:09:49 +01:00
|
|
|
#ifndef GRID_LATTICE_BASE_H
|
|
|
|
#define GRID_LATTICE_BASE_H
|
|
|
|
|
2015-05-21 06:47:05 +01:00
|
|
|
#define STREAMING_STORES
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
namespace Grid {
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// mac,real,imag
|
|
|
|
|
|
|
|
// Functionality:
|
|
|
|
// -=,+=,*=,()
|
|
|
|
// add,+,sub,-,mult,mac,*
|
2015-05-19 13:57:35 +01:00
|
|
|
// adj,conjugate
|
2015-05-11 19:09:49 +01:00
|
|
|
// real,imag
|
|
|
|
// transpose,transposeIndex
|
|
|
|
// trace,traceIndex
|
|
|
|
// peekIndex
|
|
|
|
// innerProduct,outerProduct,
|
|
|
|
// localNorm2
|
|
|
|
// localInnerProduct
|
|
|
|
|
|
|
|
extern int GridCshiftPermuteMap[4][16];
|
|
|
|
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
// Basic expressions used in Expression Template
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class LatticeBase {};
|
|
|
|
class LatticeExpressionBase {};
|
|
|
|
|
2015-09-23 13:23:45 +01:00
|
|
|
template<class T> using Vector = std::vector<T,alignedAllocator<T> >; // Aligned allocator??
|
|
|
|
template<class T> using Matrix = std::vector<std::vector<T,alignedAllocator<T> > >; // Aligned allocator??
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
template <typename Op, typename T1>
|
|
|
|
class LatticeUnaryExpression : public std::pair<Op,std::tuple<T1> > , public LatticeExpressionBase {
|
|
|
|
public:
|
|
|
|
LatticeUnaryExpression(const std::pair<Op,std::tuple<T1> > &arg): std::pair<Op,std::tuple<T1> >(arg) {};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Op, typename T1, typename T2>
|
|
|
|
class LatticeBinaryExpression : public std::pair<Op,std::tuple<T1,T2> > , public LatticeExpressionBase {
|
|
|
|
public:
|
|
|
|
LatticeBinaryExpression(const std::pair<Op,std::tuple<T1,T2> > &arg): std::pair<Op,std::tuple<T1,T2> >(arg) {};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Op, typename T1, typename T2, typename T3>
|
|
|
|
class LatticeTrinaryExpression :public std::pair<Op,std::tuple<T1,T2,T3> >, public LatticeExpressionBase {
|
|
|
|
public:
|
|
|
|
LatticeTrinaryExpression(const std::pair<Op,std::tuple<T1,T2,T3> > &arg): std::pair<Op,std::tuple<T1,T2,T3> >(arg) {};
|
|
|
|
};
|
|
|
|
|
2015-05-26 19:54:03 +01:00
|
|
|
void inline conformable(GridBase *lhs,GridBase *rhs)
|
|
|
|
{
|
|
|
|
assert(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
template<class vobj>
|
|
|
|
class Lattice : public LatticeBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GridBase *_grid;
|
|
|
|
int checkerboard;
|
2015-09-23 13:23:45 +01:00
|
|
|
Vector<vobj> _odata;
|
2015-07-26 02:54:38 +01:00
|
|
|
|
|
|
|
// to pthread need a computable loop where loop induction is not required
|
|
|
|
int begin(void) { return 0;};
|
|
|
|
int end(void) { return _odata.size(); }
|
|
|
|
vobj & operator[](int i) { return _odata[i]; };
|
2015-05-11 19:09:49 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
typedef vobj vector_object;
|
2015-05-26 19:54:03 +01:00
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Expression Template closure support
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-05-16 04:36:22 +01:00
|
|
|
template <typename Op, typename T1> strong_inline Lattice<vobj> & operator=(const LatticeUnaryExpression<Op,T1> &expr)
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
2015-05-25 13:45:08 +01:00
|
|
|
GridBase *egrid(nullptr);
|
|
|
|
GridFromExpression(egrid,expr);
|
|
|
|
assert(egrid!=nullptr);
|
|
|
|
conformable(_grid,egrid);
|
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
|
|
|
checkerboard=cb;
|
|
|
|
|
2015-05-15 11:48:04 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
|
|
|
vobj tmp = eval(ss,expr);
|
2015-05-11 19:09:49 +01:00
|
|
|
vstream(_odata[ss] ,tmp);
|
2015-05-21 06:47:05 +01:00
|
|
|
#else
|
|
|
|
_odata[ss]=eval(ss,expr);
|
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2015-06-14 01:06:56 +01:00
|
|
|
template <typename Op, typename T1,typename T2> strong_inline Lattice<vobj> & operator=(const LatticeBinaryExpression<Op,T1,T2> &expr)
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
2015-05-25 13:45:08 +01:00
|
|
|
GridBase *egrid(nullptr);
|
|
|
|
GridFromExpression(egrid,expr);
|
|
|
|
assert(egrid!=nullptr);
|
|
|
|
conformable(_grid,egrid);
|
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
|
|
|
checkerboard=cb;
|
|
|
|
|
2015-05-15 11:48:04 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
|
|
|
vobj tmp = eval(ss,expr);
|
2015-05-11 19:09:49 +01:00
|
|
|
vstream(_odata[ss] ,tmp);
|
2015-05-21 06:47:05 +01:00
|
|
|
#else
|
|
|
|
_odata[ss]=eval(ss,expr);
|
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2015-05-16 04:36:22 +01:00
|
|
|
template <typename Op, typename T1,typename T2,typename T3> strong_inline Lattice<vobj> & operator=(const LatticeTrinaryExpression<Op,T1,T2,T3> &expr)
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
2015-05-25 13:45:08 +01:00
|
|
|
GridBase *egrid(nullptr);
|
|
|
|
GridFromExpression(egrid,expr);
|
|
|
|
assert(egrid!=nullptr);
|
|
|
|
conformable(_grid,egrid);
|
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
|
|
|
checkerboard=cb;
|
|
|
|
|
2015-05-15 11:48:04 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-06-14 01:06:56 +01:00
|
|
|
//vobj tmp = eval(ss,expr);
|
|
|
|
vstream(_odata[ss] ,eval(ss,expr));
|
2015-05-21 06:47:05 +01:00
|
|
|
#else
|
|
|
|
_odata[ss] = eval(ss,expr);
|
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
//GridFromExpression is tricky to do
|
|
|
|
template<class Op,class T1>
|
|
|
|
Lattice(const LatticeUnaryExpression<Op,T1> & expr): _grid(nullptr){
|
2015-05-25 13:45:08 +01:00
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
GridFromExpression(_grid,expr);
|
|
|
|
assert(_grid!=nullptr);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
|
|
|
checkerboard=cb;
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
_odata.resize(_grid->oSites());
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
|
|
|
vobj tmp = eval(ss,expr);
|
|
|
|
vstream(_odata[ss] ,tmp);
|
|
|
|
#else
|
2015-06-16 14:06:31 +01:00
|
|
|
_odata[ss]=eval(ss,expr);
|
2015-05-21 06:47:05 +01:00
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template<class Op,class T1, class T2>
|
|
|
|
Lattice(const LatticeBinaryExpression<Op,T1,T2> & expr): _grid(nullptr){
|
|
|
|
GridFromExpression(_grid,expr);
|
|
|
|
assert(_grid!=nullptr);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
|
|
|
checkerboard=cb;
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
_odata.resize(_grid->oSites());
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-06-01 12:26:20 +01:00
|
|
|
vobj tmp = eval(ss,expr);
|
2015-05-21 06:47:05 +01:00
|
|
|
vstream(_odata[ss] ,tmp);
|
|
|
|
#else
|
|
|
|
_odata[ss]=eval(ss,expr);
|
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template<class Op,class T1, class T2, class T3>
|
|
|
|
Lattice(const LatticeTrinaryExpression<Op,T1,T2,T3> & expr): _grid(nullptr){
|
|
|
|
GridFromExpression(_grid,expr);
|
|
|
|
assert(_grid!=nullptr);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
|
|
|
checkerboard=cb;
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
_odata.resize(_grid->oSites());
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
2015-06-16 14:06:31 +01:00
|
|
|
vstream(_odata[ss] ,eval(ss,expr));
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Constructor requires "grid" passed.
|
|
|
|
// what about a default grid?
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2015-10-08 23:42:21 +01:00
|
|
|
Lattice(GridBase *grid) : _grid(grid), _odata(_grid->oSites()) {
|
2015-12-20 02:29:51 +00:00
|
|
|
// _odata.reserve(_grid->oSites());
|
|
|
|
// _odata.resize(_grid->oSites());
|
2015-10-08 23:42:21 +01:00
|
|
|
// std::cout << "Constructing lattice object with Grid pointer "<<_grid<<std::endl;
|
2015-05-11 19:09:49 +01:00
|
|
|
assert((((uint64_t)&_odata[0])&0xF) ==0);
|
|
|
|
checkerboard=0;
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:36:22 +01:00
|
|
|
template<class sobj> strong_inline Lattice<vobj> & operator = (const sobj & r){
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
|
|
|
this->_odata[ss]=r;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2015-05-16 04:36:22 +01:00
|
|
|
template<class robj> strong_inline Lattice<vobj> & operator = (const Lattice<robj> & r){
|
2015-05-25 13:45:08 +01:00
|
|
|
this->checkerboard = r.checkerboard;
|
2015-05-11 19:09:49 +01:00
|
|
|
conformable(*this,r);
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<<"Lattice operator ="<<std::endl;
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<_grid->oSites();ss++){
|
|
|
|
this->_odata[ss]=r._odata[ss];
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *=,+=,-= operators inherit behvour from correspond */+/- operation
|
2015-05-16 04:36:22 +01:00
|
|
|
template<class T> strong_inline Lattice<vobj> &operator *=(const T &r) {
|
2015-05-11 19:09:49 +01:00
|
|
|
*this = (*this)*r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:36:22 +01:00
|
|
|
template<class T> strong_inline Lattice<vobj> &operator -=(const T &r) {
|
2015-05-11 19:09:49 +01:00
|
|
|
*this = (*this)-r;
|
|
|
|
return *this;
|
|
|
|
}
|
2015-05-16 04:36:22 +01:00
|
|
|
template<class T> strong_inline Lattice<vobj> &operator +=(const T &r) {
|
2015-05-11 19:09:49 +01:00
|
|
|
*this = (*this)+r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:36:22 +01:00
|
|
|
strong_inline friend Lattice<vobj> operator / (const Lattice<vobj> &lhs,const Lattice<vobj> &rhs){
|
2015-05-11 19:09:49 +01:00
|
|
|
conformable(lhs,rhs);
|
|
|
|
Lattice<vobj> ret(lhs._grid);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-11 19:09:49 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-06-14 01:06:56 +01:00
|
|
|
ret._odata[ss] = lhs._odata[ss]*pow(rhs._odata[ss],-1.0);
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
2015-05-13 09:24:10 +01:00
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
}; // class Lattice
|
2015-05-13 09:24:10 +01:00
|
|
|
|
2015-05-16 04:36:22 +01:00
|
|
|
template<class vobj> std::ostream& operator<< (std::ostream& stream, const Lattice<vobj> &o){
|
2015-05-13 09:24:10 +01:00
|
|
|
std::vector<int> gcoor;
|
|
|
|
typedef typename vobj::scalar_object sobj;
|
|
|
|
sobj ss;
|
|
|
|
for(int g=0;g<o._grid->_gsites;g++){
|
|
|
|
o._grid->GlobalIndexToGlobalCoor(g,gcoor);
|
|
|
|
peekSite(ss,o,gcoor);
|
|
|
|
stream<<"[";
|
|
|
|
for(int d=0;d<gcoor.size();d++){
|
|
|
|
stream<<gcoor[d];
|
|
|
|
if(d!=gcoor.size()-1) stream<<",";
|
|
|
|
}
|
|
|
|
stream<<"]\t";
|
|
|
|
stream<<ss<<std::endl;
|
|
|
|
}
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_conformable.h>
|
2015-05-12 20:41:44 +01:00
|
|
|
#define GRID_LATTICE_EXPRESSION_TEMPLATES
|
|
|
|
#ifdef GRID_LATTICE_EXPRESSION_TEMPLATES
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_ET.h>
|
2015-05-11 19:09:49 +01:00
|
|
|
#else
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_overload.h>
|
2015-05-11 19:09:49 +01:00
|
|
|
#endif
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_arith.h>
|
|
|
|
#include <lattice/Lattice_trace.h>
|
|
|
|
#include <lattice/Lattice_transpose.h>
|
|
|
|
#include <lattice/Lattice_local.h>
|
|
|
|
#include <lattice/Lattice_reduction.h>
|
|
|
|
#include <lattice/Lattice_peekpoke.h>
|
|
|
|
#include <lattice/Lattice_reality.h>
|
2015-06-09 10:26:19 +01:00
|
|
|
#include <lattice/Lattice_comparison_utils.h>
|
|
|
|
#include <lattice/Lattice_comparison.h>
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_coordinate.h>
|
2015-06-09 10:26:19 +01:00
|
|
|
#include <lattice/Lattice_where.h>
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_rng.h>
|
2015-06-08 12:04:59 +01:00
|
|
|
#include <lattice/Lattice_unary.h>
|
2015-06-03 12:47:05 +01:00
|
|
|
#include <lattice/Lattice_transfer.h>
|
2015-05-11 19:09:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|