From 3358a77c7a111193b6310ed7b68b2cee48d34775 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Mon, 25 May 2015 13:45:08 +0100 Subject: [PATCH] Better checkerboard tracking. --- lib/lattice/Grid_lattice_ET.h | 41 ++++++++++++++++++++++++++ lib/lattice/Grid_lattice_arith.h | 28 ++++++++++++++++-- lib/lattice/Grid_lattice_base.h | 50 ++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/lib/lattice/Grid_lattice_ET.h b/lib/lattice/Grid_lattice_ET.h index b0205f2f..2a7172ea 100644 --- a/lib/lattice/Grid_lattice_ET.h +++ b/lib/lattice/Grid_lattice_ET.h @@ -91,6 +91,47 @@ inline void GridFromExpression( GridBase * &grid,const LatticeTrinaryExpression< GridFromExpression(grid,std::get<2>(expr.second)); } + +////////////////////////////////////////////////////////////////////////// +// Obtain the CB from an expression, ensuring conformable. This must follow a tree recursion +////////////////////////////////////////////////////////////////////////// +template::value, T1>::type * =nullptr > +inline void CBFromExpression(int &cb,const T1& lat) // Lattice leaf +{ + if ( (cb==Odd) || (cb==Even) ) { + assert(cb==lat.checkerboard); + } + cb=lat.checkerboard; + // std::cout<<"Lattice leaf cb "<::value, T1>::type * = nullptr > +inline void CBFromExpression(int &cb,const T1& notlat) // non-lattice leaf +{ + // std::cout<<"Non lattice leaf cb"< +inline void CBFromExpression(int &cb,const LatticeUnaryExpression &expr) +{ + CBFromExpression(cb,std::get<0>(expr.second));// recurse + // std::cout<<"Unary node cb "< +inline void CBFromExpression(int &cb,const LatticeBinaryExpression &expr) +{ + CBFromExpression(cb,std::get<0>(expr.second));// recurse + CBFromExpression(cb,std::get<1>(expr.second)); + // std::cout<<"Binary node cb "< +inline void CBFromExpression( int &cb,const LatticeTrinaryExpression &expr) +{ + CBFromExpression(cb,std::get<0>(expr.second));// recurse + CBFromExpression(cb,std::get<1>(expr.second)); + CBFromExpression(cb,std::get<2>(expr.second)); + // std::cout<<"Trinary node cb "< strong_inline void mult(Lattice &ret,const Lattice &lhs,const Lattice &rhs){ + ret.checkerboard = lhs.checkerboard; + conformable(ret,rhs); conformable(lhs,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -24,6 +26,8 @@ PARALLEL_FOR_LOOP template strong_inline void mac(Lattice &ret,const Lattice &lhs,const Lattice &rhs){ + ret.checkerboard = lhs.checkerboard; + conformable(ret,rhs); conformable(lhs,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -39,6 +43,8 @@ PARALLEL_FOR_LOOP template strong_inline void sub(Lattice &ret,const Lattice &lhs,const Lattice &rhs){ + ret.checkerboard = lhs.checkerboard; + conformable(ret,rhs); conformable(lhs,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -53,6 +59,8 @@ PARALLEL_FOR_LOOP } template strong_inline void add(Lattice &ret,const Lattice &lhs,const Lattice &rhs){ + ret.checkerboard = lhs.checkerboard; + conformable(ret,rhs); conformable(lhs,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -71,6 +79,7 @@ PARALLEL_FOR_LOOP ////////////////////////////////////////////////////////////////////////////////////////////////////// template strong_inline void mult(Lattice &ret,const Lattice &lhs,const obj3 &rhs){ + ret.checkerboard = lhs.checkerboard; conformable(lhs,ret); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -82,7 +91,8 @@ PARALLEL_FOR_LOOP template strong_inline void mac(Lattice &ret,const Lattice &lhs,const obj3 &rhs){ - conformable(lhs,ret); + ret.checkerboard = lhs.checkerboard; + conformable(ret,lhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ obj1 tmp; @@ -93,7 +103,8 @@ PARALLEL_FOR_LOOP template strong_inline void sub(Lattice &ret,const Lattice &lhs,const obj3 &rhs){ - conformable(lhs,ret); + ret.checkerboard = lhs.checkerboard; + conformable(ret,lhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ #ifdef STREAMING_STORES @@ -107,6 +118,7 @@ PARALLEL_FOR_LOOP } template strong_inline void add(Lattice &ret,const Lattice &lhs,const obj3 &rhs){ + ret.checkerboard = lhs.checkerboard; conformable(lhs,ret); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -125,6 +137,7 @@ PARALLEL_FOR_LOOP ////////////////////////////////////////////////////////////////////////////////////////////////////// template strong_inline void mult(Lattice &ret,const obj2 &lhs,const Lattice &rhs){ + ret.checkerboard = rhs.checkerboard; conformable(ret,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -140,6 +153,7 @@ PARALLEL_FOR_LOOP template strong_inline void mac(Lattice &ret,const obj2 &lhs,const Lattice &rhs){ + ret.checkerboard = rhs.checkerboard; conformable(ret,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -155,6 +169,7 @@ PARALLEL_FOR_LOOP template strong_inline void sub(Lattice &ret,const obj2 &lhs,const Lattice &rhs){ + ret.checkerboard = rhs.checkerboard; conformable(ret,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -169,6 +184,7 @@ PARALLEL_FOR_LOOP } template strong_inline void add(Lattice &ret,const obj2 &lhs,const Lattice &rhs){ + ret.checkerboard = rhs.checkerboard; conformable(ret,rhs); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -184,6 +200,8 @@ PARALLEL_FOR_LOOP template strong_inline void axpy(Lattice &ret,sobj a,const Lattice &x,const Lattice &y){ + ret.checkerboard = x.checkerboard; + conformable(ret,x); conformable(x,y); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -197,6 +215,8 @@ PARALLEL_FOR_LOOP } template strong_inline void axpby(Lattice &ret,sobj a,sobj b,const Lattice &x,const Lattice &y){ + ret.checkerboard = x.checkerboard; + conformable(ret,x); conformable(x,y); PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ @@ -211,12 +231,16 @@ PARALLEL_FOR_LOOP template strong_inline RealD axpy_norm(Lattice &ret,sobj a,const Lattice &x,const Lattice &y){ + ret.checkerboard = x.checkerboard; + conformable(ret,x); conformable(x,y); axpy(ret,a,x,y); return norm2(ret); } template strong_inline RealD axpby_norm(Lattice &ret,sobj a,sobj b,const Lattice &x,const Lattice &y){ + ret.checkerboard = x.checkerboard; + conformable(ret,x); conformable(x,y); axpby(ret,a,b,x,y); return norm2(ret); // FIXME implement parallel norm in ss loop diff --git a/lib/lattice/Grid_lattice_base.h b/lib/lattice/Grid_lattice_base.h index 41f349b7..1d3b1efb 100644 --- a/lib/lattice/Grid_lattice_base.h +++ b/lib/lattice/Grid_lattice_base.h @@ -66,6 +66,16 @@ public: //////////////////////////////////////////////////////////////////////////////// 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 @@ -79,6 +89,16 @@ PARALLEL_FOR_LOOP } 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 @@ -92,6 +112,16 @@ PARALLEL_FOR_LOOP } 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 @@ -106,8 +136,15 @@ PARALLEL_FOR_LOOP //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++){ @@ -123,6 +160,12 @@ PARALLEL_FOR_LOOP 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++){ @@ -138,6 +181,12 @@ PARALLEL_FOR_LOOP 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++){ @@ -169,6 +218,7 @@ PARALLEL_FOR_LOOP return *this; } template strong_inline Lattice & operator = (const Lattice & r){ + this->checkerboard = r.checkerboard; conformable(*this,r); std::cout<<"Lattice operator ="<