#ifndef GRID_LATTICE_TRANSFER_H #define GRID_LATTICE_TRANSFER_H namespace Grid { inline void subdivides(GridBase *coarse,GridBase *fine) { assert(coarse->_ndimension == fine->_ndimension); int _ndimension = coarse->_ndimension; // local and global volumes subdivide cleanly after SIMDization for(int d=0;d<_ndimension;d++){ assert(coarse->_processors[d] == fine->_processors[d]); assert(coarse->_simd_layout[d] == fine->_simd_layout[d]); assert((fine->_rdimensions[d] / coarse->_rdimensions[d])* coarse->_rdimensions[d]==fine->_rdimensions[d]); } } //////////////////////////////////////////////////////////////////////////////////////////// // remove and insert a half checkerboard //////////////////////////////////////////////////////////////////////////////////////////// template inline void pickCheckerboard(int cb,Lattice &half,const Lattice &full){ half.checkerboard = cb; int ssh=0; PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ std::vector coor; int cbos; full._grid->oCoorFromOindex(coor,ss); cbos=half._grid->CheckerBoard(coor); if (cbos==cb) { half._odata[ssh] = full._odata[ss]; ssh++; } } } template inline void setCheckerboard(Lattice &full,const Lattice &half){ int cb = half.checkerboard; int ssh=0; PARALLEL_FOR_LOOP for(int ss=0;ssoSites();ss++){ std::vector coor; int cbos; full._grid->oCoorFromOindex(coor,ss); cbos=half._grid->CheckerBoard(coor); if (cbos==cb) { full._odata[ss]=half._odata[ssh]; ssh++; } } } template inline void blockProject(Lattice > &coarseData, const Lattice &fineData, const std::vector > &Basis) { GridBase * fine = fineData._grid; GridBase * coarse= coarseData._grid; int _ndimension = coarse->_ndimension; // checks assert( nbasis == Basis.size() ); subdivides(coarse,fine); for(int i=0;i block_r (_ndimension); for(int d=0 ; d<_ndimension;d++){ block_r[d] = fine->_rdimensions[d] / coarse->_rdimensions[d]; assert(block_r[d]*coarse->_rdimensions[d] == fine->_rdimensions[d]); } coarseData=zero; // Loop with a cache friendly loop ordering for(int sf=0;sfoSites();sf++){ int sc; std::vector coor_c(_ndimension); std::vector coor_f(_ndimension); GridBase::CoorFromIndex(coor_f,sf,fine->_rdimensions); for(int d=0;d<_ndimension;d++) coor_c[d]=coor_f[d]/block_r[d]; GridBase::IndexFromCoor(coor_c,sc,coarse->_rdimensions); for(int i=0;i inline void blockZAXPY(Lattice &fineZ, const Lattice &coarseA, const Lattice &fineX, const Lattice &fineY) { GridBase * fine = fineZ._grid; GridBase * coarse= coarseA._grid; fineZ.checkerboard=fineX.checkerboard; subdivides(coarse,fine); // require they map conformable(fineX,fineY); conformable(fineX,fineZ); int _ndimension = coarse->_ndimension; std::vector block_r (_ndimension); // FIXME merge with subdivide checking routine as this is redundant for(int d=0 ; d<_ndimension;d++){ block_r[d] = fine->_rdimensions[d] / coarse->_rdimensions[d]; assert(block_r[d]*coarse->_rdimensions[d]==fine->_rdimensions[d]); } PARALLEL_FOR_LOOP for(int sf=0;sfoSites();sf++){ int sc; std::vector coor_c(_ndimension); std::vector coor_f(_ndimension); GridBase::CoorFromIndex(coor_f,sf,fine->_rdimensions); for(int d=0;d<_ndimension;d++) coor_c[d]=coor_f[d]/block_r[d]; GridBase::IndexFromCoor(coor_c,sc,coarse->_rdimensions); // z = A x + y fineZ._odata[sf]=coarseA._odata[sc]*fineX._odata[sf]+fineY._odata[sf]; } return; } template inline void blockInnerProduct(Lattice &CoarseInner, const Lattice &fineX, const Lattice &fineY) { typedef decltype(innerProduct(fineX._odata[0],fineY._odata[0])) dotp; GridBase *coarse(CoarseInner._grid); GridBase *fine (fineX._grid); Lattice fine_inner(fine); Lattice coarse_inner(coarse); fine_inner = localInnerProduct(fineX,fineY); blockSum(coarse_inner,fine_inner); for(int ss=0;ssoSites();ss++){ CoarseInner._odata[ss] = coarse_inner._odata[ss]; } } template inline void blockNormalise(Lattice &ip,Lattice &fineX) { GridBase *coarse = ip._grid; blockInnerProduct(ip,fineX,fineX); ip = rsqrt(ip); blockZAXPY(fineX,ip,fineX,fineX); } // useful in multigrid project; // Generic name : Coarsen? template inline void blockSum(Lattice &coarseData,const Lattice &fineData) { GridBase * fine = fineData._grid; GridBase * coarse= coarseData._grid; subdivides(coarse,fine); // require they map int _ndimension = coarse->_ndimension; std::vector block_r (_ndimension); for(int d=0 ; d<_ndimension;d++){ block_r[d] = fine->_rdimensions[d] / coarse->_rdimensions[d]; } coarseData=zero; for(int sf=0;sfoSites();sf++){ int sc; std::vector coor_c(_ndimension); std::vector coor_f(_ndimension); GridBase::CoorFromIndex(coor_f,sf,fine->_rdimensions); for(int d=0;d<_ndimension;d++) coor_c[d]=coor_f[d]/block_r[d]; GridBase::IndexFromCoor(coor_c,sc,coarse->_rdimensions); coarseData._odata[sc]=coarseData._odata[sc]+fineData._odata[sf]; } return; } template inline void blockOrthogonalise(Lattice &ip,std::vector > &Basis) { GridBase *coarse = ip._grid; GridBase *fine = Basis[0]._grid; int nbasis = Basis.size() ; int _ndimension = coarse->_ndimension; // checks subdivides(coarse,fine); for(int i=0;i (Basis[v],ip,Basis[u],Basis[v]); } blockNormalise(ip,Basis[v]); } } template inline void blockPromote(const Lattice > &coarseData, Lattice &fineData, const std::vector > &Basis) { GridBase * fine = fineData._grid; GridBase * coarse= coarseData._grid; int _ndimension = coarse->_ndimension; // checks assert( nbasis == Basis.size() ); subdivides(coarse,fine); for(int i=0;i block_r (_ndimension); for(int d=0 ; d<_ndimension;d++){ block_r[d] = fine->_rdimensions[d] / coarse->_rdimensions[d]; } // Loop with a cache friendly loop ordering for(int sf=0;sfoSites();sf++){ int sc; std::vector coor_c(_ndimension); std::vector coor_f(_ndimension); GridBase::CoorFromIndex(coor_f,sf,fine->_rdimensions); for(int d=0;d<_ndimension;d++) coor_c[d]=coor_f[d]/block_r[d]; GridBase::IndexFromCoor(coor_c,sc,coarse->_rdimensions); for(int i=0;i