#ifndef GRID_LATTICE_H #define GRID_LATTICE_H namespace Grid { // TODO: // mac,real,imag // Functionality: // -=,+=,*=,() // add,+,sub,-,mult,mac,* // adj,conj // 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 {}; template class LatticeUnaryExpression : public std::pair > , public LatticeExpressionBase { public: LatticeUnaryExpression(const std::pair > &arg): std::pair >(arg) {}; }; template class LatticeBinaryExpression : public std::pair > , public LatticeExpressionBase { public: LatticeBinaryExpression(const std::pair > &arg): std::pair >(arg) {}; }; template class LatticeTrinaryExpression :public std::pair >, public LatticeExpressionBase { public: LatticeTrinaryExpression(const std::pair > &arg): std::pair >(arg) {}; }; template class Lattice : public LatticeBase { public: GridBase *_grid; int checkerboard; std::vector > _odata; public: typedef typename vobj::scalar_type scalar_type; typedef typename vobj::vector_type vector_type; typedef vobj vector_object; //////////////////////////////////////////////////////////////////////////////// // Expression Template closure support //////////////////////////////////////////////////////////////////////////////// template inline Lattice & operator=(const LatticeUnaryExpression &expr) { #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ vobj tmp= eval(ss,expr); vstream(_odata[ss] ,tmp); } return *this; } template inline Lattice & operator=(const LatticeBinaryExpression &expr) { #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ vobj tmp= eval(ss,expr); vstream(_odata[ss] ,tmp); } return *this; } template inline Lattice & operator=(const LatticeTrinaryExpression &expr) { #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ vobj tmp= eval(ss,expr); vstream(_odata[ss] ,tmp); } return *this; } //GridFromExpression is tricky to do template Lattice(const LatticeUnaryExpression & expr): _grid(nullptr){ GridFromExpression(_grid,expr); assert(_grid!=nullptr); _odata.resize(_grid->oSites()); #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ _odata[ss] = eval(ss,expr); } }; template Lattice(const LatticeBinaryExpression & expr): _grid(nullptr){ GridFromExpression(_grid,expr); assert(_grid!=nullptr); _odata.resize(_grid->oSites()); #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ _odata[ss] = eval(ss,expr); } }; template Lattice(const LatticeTrinaryExpression & expr): _grid(nullptr){ GridFromExpression(_grid,expr); assert(_grid!=nullptr); _odata.resize(_grid->oSites()); #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ _odata[ss] = eval(ss,expr); } }; ////////////////////////////////////////////////////////////////// // Constructor requires "grid" passed. // what about a default grid? ////////////////////////////////////////////////////////////////// Lattice(GridBase *grid) : _grid(grid), _odata(_grid->oSites()) { // _odata.reserve(_grid->oSites()); // _odata.resize(_grid->oSites()); assert((((uint64_t)&_odata[0])&0xF) ==0); checkerboard=0; } template inline Lattice & operator = (const sobj & r){ #pragma omp parallel for for(int ss=0;ss<_grid->oSites();ss++){ this->_odata[ss]=r; } return *this; } template inline Lattice & operator = (const Lattice & r){ conformable(*this,r); std::cout<<"Lattice operator ="<oSites();ss++){ this->_odata[ss]=r._odata[ss]; } return *this; } // *=,+=,-= operators inherit behvour from correspond */+/- operation template inline Lattice &operator *=(const T &r) { *this = (*this)*r; return *this; } template inline Lattice &operator -=(const T &r) { *this = (*this)-r; return *this; } template inline Lattice &operator +=(const T &r) { *this = (*this)+r; return *this; } inline friend Lattice operator / (const Lattice &lhs,const Lattice &rhs){ conformable(lhs,rhs); Lattice ret(lhs._grid); #pragma omp parallel for for(int ss=0;ssoSites();ss++){ ret._odata[ss] = lhs._odata[ss]/rhs._odata[ss]; } return ret; }; }; // class Lattice } #undef GRID_LATTICE_EXPRESSION_TEMPLATES #include #ifdef GRID_LATTICE_EXPRESSION_TEMPLATES #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #endif