/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/lattice/Lattice_base.h Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle Author: paboyle 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 */ #ifndef GRID_LATTICE_BASE_H #define GRID_LATTICE_BASE_H #define STREAMING_STORES namespace Grid { // TODO: // mac,real,imag // Functionality: // -=,+=,*=,() // add,+,sub,-,mult,mac,* // adj,conjugate // 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 using Vector = std::vector >; // Aligned allocator?? template using Matrix = std::vector > >; // Aligned allocator?? 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) {}; }; void inline conformable(GridBase *lhs,GridBase *rhs) { assert(lhs == rhs); } template class Lattice : public LatticeBase { public: GridBase *_grid; int checkerboard; Vector _odata; // 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]; }; public: typedef typename vobj::scalar_type scalar_type; typedef typename vobj::vector_type vector_type; typedef vobj vector_object; //////////////////////////////////////////////////////////////////////////////// // Expression Template closure support //////////////////////////////////////////////////////////////////////////////// template strong_inline Lattice & operator=(const LatticeUnaryExpression &expr) { 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; PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ #ifdef STREAMING_STORES vobj tmp = eval(ss,expr); vstream(_odata[ss] ,tmp); #else _odata[ss]=eval(ss,expr); #endif } return *this; } template strong_inline Lattice & operator=(const LatticeBinaryExpression &expr) { 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; PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ #ifdef STREAMING_STORES vobj tmp = eval(ss,expr); vstream(_odata[ss] ,tmp); #else _odata[ss]=eval(ss,expr); #endif } return *this; } template strong_inline Lattice & operator=(const LatticeTrinaryExpression &expr) { 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; PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ #ifdef STREAMING_STORES //vobj tmp = eval(ss,expr); vstream(_odata[ss] ,eval(ss,expr)); #else _odata[ss] = eval(ss,expr); #endif } return *this; } //GridFromExpression is tricky to do template Lattice(const LatticeUnaryExpression & expr): _grid(nullptr){ GridFromExpression(_grid,expr); assert(_grid!=nullptr); int cb=-1; CBFromExpression(cb,expr); assert( (cb==Odd) || (cb==Even)); checkerboard=cb; _odata.resize(_grid->oSites()); PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ #ifdef STREAMING_STORES vobj tmp = eval(ss,expr); vstream(_odata[ss] ,tmp); #else _odata[ss]=eval(ss,expr); #endif } }; template Lattice(const LatticeBinaryExpression & expr): _grid(nullptr){ GridFromExpression(_grid,expr); assert(_grid!=nullptr); int cb=-1; CBFromExpression(cb,expr); assert( (cb==Odd) || (cb==Even)); checkerboard=cb; _odata.resize(_grid->oSites()); PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ #ifdef STREAMING_STORES vobj tmp = eval(ss,expr); vstream(_odata[ss] ,tmp); #else _odata[ss]=eval(ss,expr); #endif } }; template Lattice(const LatticeTrinaryExpression & expr): _grid(nullptr){ GridFromExpression(_grid,expr); assert(_grid!=nullptr); int cb=-1; CBFromExpression(cb,expr); assert( (cb==Odd) || (cb==Even)); checkerboard=cb; _odata.resize(_grid->oSites()); PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ vstream(_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()); // std::cout << "Constructing lattice object with Grid pointer "<<_grid< strong_inline Lattice & operator = (const sobj & r){ PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){ this->_odata[ss]=r; } return *this; } template strong_inline Lattice & operator = (const Lattice & r){ this->checkerboard = r.checkerboard; conformable(*this,r); std::cout< #define GRID_LATTICE_EXPRESSION_TEMPLATES #ifdef GRID_LATTICE_EXPRESSION_TEMPLATES #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif