mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Format, NAMESPACE
This commit is contained in:
parent
59b31b6bb8
commit
0b8a88978b
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_CARTESIAN_H
|
#ifndef GRID_CARTESIAN_H
|
||||||
#define GRID_CARTESIAN_H
|
#define GRID_CARTESIAN_H
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -25,265 +25,264 @@
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_CARTESIAN_BASE_H
|
#ifndef GRID_CARTESIAN_BASE_H
|
||||||
#define GRID_CARTESIAN_BASE_H
|
#define GRID_CARTESIAN_BASE_H
|
||||||
|
|
||||||
|
|
||||||
namespace Grid{
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Commicator provides information on the processor grid
|
// Commicator provides information on the processor grid
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// unsigned long _ndimension;
|
// unsigned long _ndimension;
|
||||||
// std::vector<int> _processors; // processor grid
|
// std::vector<int> _processors; // processor grid
|
||||||
// int _processor; // linear processor rank
|
// int _processor; // linear processor rank
|
||||||
// std::vector<int> _processor_coor; // linear processor rank
|
// std::vector<int> _processor_coor; // linear processor rank
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
class GridBase : public CartesianCommunicator , public GridThread {
|
class GridBase : public CartesianCommunicator , public GridThread {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int dummy;
|
int dummy;
|
||||||
// Give Lattice access
|
// Give Lattice access
|
||||||
template<class object> friend class Lattice;
|
template<class object> friend class Lattice;
|
||||||
|
|
||||||
GridBase(const std::vector<int> & processor_grid) : CartesianCommunicator(processor_grid) {};
|
GridBase(const std::vector<int> & processor_grid) : CartesianCommunicator(processor_grid) {};
|
||||||
GridBase(const std::vector<int> & processor_grid,
|
GridBase(const std::vector<int> & processor_grid,
|
||||||
const CartesianCommunicator &parent,
|
const CartesianCommunicator &parent,
|
||||||
int &split_rank)
|
int &split_rank)
|
||||||
: CartesianCommunicator(processor_grid,parent,split_rank) {};
|
: CartesianCommunicator(processor_grid,parent,split_rank) {};
|
||||||
GridBase(const std::vector<int> & processor_grid,
|
GridBase(const std::vector<int> & processor_grid,
|
||||||
const CartesianCommunicator &parent)
|
const CartesianCommunicator &parent)
|
||||||
: CartesianCommunicator(processor_grid,parent,dummy) {};
|
: CartesianCommunicator(processor_grid,parent,dummy) {};
|
||||||
|
|
||||||
virtual ~GridBase() = default;
|
virtual ~GridBase() = default;
|
||||||
|
|
||||||
// Physics Grid information.
|
// Physics Grid information.
|
||||||
std::vector<int> _simd_layout;// Which dimensions get relayed out over simd lanes.
|
std::vector<int> _simd_layout;// Which dimensions get relayed out over simd lanes.
|
||||||
std::vector<int> _fdimensions;// (full) Global dimensions of array prior to cb removal
|
std::vector<int> _fdimensions;// (full) Global dimensions of array prior to cb removal
|
||||||
std::vector<int> _gdimensions;// Global dimensions of array after cb removal
|
std::vector<int> _gdimensions;// Global dimensions of array after cb removal
|
||||||
std::vector<int> _ldimensions;// local dimensions of array with processor images removed
|
std::vector<int> _ldimensions;// local dimensions of array with processor images removed
|
||||||
std::vector<int> _rdimensions;// Reduced local dimensions with simd lane images and processor images removed
|
std::vector<int> _rdimensions;// Reduced local dimensions with simd lane images and processor images removed
|
||||||
std::vector<int> _ostride; // Outer stride for each dimension
|
std::vector<int> _ostride; // Outer stride for each dimension
|
||||||
std::vector<int> _istride; // Inner stride i.e. within simd lane
|
std::vector<int> _istride; // Inner stride i.e. within simd lane
|
||||||
int _osites; // _isites*_osites = product(dimensions).
|
int _osites; // _isites*_osites = product(dimensions).
|
||||||
int _isites;
|
int _isites;
|
||||||
int _fsites; // _isites*_osites = product(dimensions).
|
int _fsites; // _isites*_osites = product(dimensions).
|
||||||
int _gsites;
|
int _gsites;
|
||||||
std::vector<int> _slice_block;// subslice information
|
std::vector<int> _slice_block;// subslice information
|
||||||
std::vector<int> _slice_stride;
|
std::vector<int> _slice_stride;
|
||||||
std::vector<int> _slice_nblock;
|
std::vector<int> _slice_nblock;
|
||||||
|
|
||||||
std::vector<int> _lstart; // local start of array in gcoors _processor_coor[d]*_ldimensions[d]
|
std::vector<int> _lstart; // local start of array in gcoors _processor_coor[d]*_ldimensions[d]
|
||||||
std::vector<int> _lend ; // local end of array in gcoors _processor_coor[d]*_ldimensions[d]+_ldimensions_[d]-1
|
std::vector<int> _lend ; // local end of array in gcoors _processor_coor[d]*_ldimensions[d]+_ldimensions_[d]-1
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
// Checkerboarding interface is virtual and overridden by
|
// Checkerboarding interface is virtual and overridden by
|
||||||
// GridCartesian / GridRedBlackCartesian
|
// GridCartesian / GridRedBlackCartesian
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
virtual int CheckerBoarded(int dim)=0;
|
virtual int CheckerBoarded(int dim)=0;
|
||||||
virtual int CheckerBoard(const std::vector<int> &site)=0;
|
virtual int CheckerBoard(const std::vector<int> &site)=0;
|
||||||
virtual int CheckerBoardDestination(int source_cb,int shift,int dim)=0;
|
virtual int CheckerBoardDestination(int source_cb,int shift,int dim)=0;
|
||||||
virtual int CheckerBoardShift(int source_cb,int dim,int shift,int osite)=0;
|
virtual int CheckerBoardShift(int source_cb,int dim,int shift,int osite)=0;
|
||||||
virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift,int cb)=0;
|
virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift,int cb)=0;
|
||||||
virtual int CheckerBoardFromOindex (int Oindex)=0;
|
virtual int CheckerBoardFromOindex (int Oindex)=0;
|
||||||
virtual int CheckerBoardFromOindexTable (int Oindex)=0;
|
virtual int CheckerBoardFromOindexTable (int Oindex)=0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Local layout calculations
|
// Local layout calculations
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// These routines are key. Subdivide the linearised cartesian index into
|
// These routines are key. Subdivide the linearised cartesian index into
|
||||||
// "inner" index identifying which simd lane of object<vFcomplex> is associated with coord
|
// "inner" index identifying which simd lane of object<vFcomplex> is associated with coord
|
||||||
// "outer" index identifying which element of _odata in class "Lattice" is associated with coord.
|
// "outer" index identifying which element of _odata in class "Lattice" is associated with coord.
|
||||||
//
|
//
|
||||||
// Compared to, say, Blitz++ we simply need to store BOTH an inner stride and an outer
|
// Compared to, say, Blitz++ we simply need to store BOTH an inner stride and an outer
|
||||||
// stride per dimension. The cost of evaluating the indexing information is doubled for an n-dimensional
|
// stride per dimension. The cost of evaluating the indexing information is doubled for an n-dimensional
|
||||||
// coordinate. Note, however, for data parallel operations the "inner" indexing cost is not paid and all
|
// coordinate. Note, however, for data parallel operations the "inner" indexing cost is not paid and all
|
||||||
// lanes are operated upon simultaneously.
|
// lanes are operated upon simultaneously.
|
||||||
|
|
||||||
virtual int oIndex(std::vector<int> &coor)
|
virtual int oIndex(std::vector<int> &coor)
|
||||||
{
|
{
|
||||||
int idx=0;
|
int idx=0;
|
||||||
// Works with either global or local coordinates
|
// Works with either global or local coordinates
|
||||||
for(int d=0;d<_ndimension;d++) idx+=_ostride[d]*(coor[d]%_rdimensions[d]);
|
for(int d=0;d<_ndimension;d++) idx+=_ostride[d]*(coor[d]%_rdimensions[d]);
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
virtual int iIndex(std::vector<int> &lcoor)
|
virtual int iIndex(std::vector<int> &lcoor)
|
||||||
{
|
{
|
||||||
int idx=0;
|
int idx=0;
|
||||||
for(int d=0;d<_ndimension;d++) idx+=_istride[d]*(lcoor[d]/_rdimensions[d]);
|
for(int d=0;d<_ndimension;d++) idx+=_istride[d]*(lcoor[d]/_rdimensions[d]);
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
inline int oIndexReduced(std::vector<int> &ocoor)
|
inline int oIndexReduced(std::vector<int> &ocoor)
|
||||||
{
|
{
|
||||||
int idx=0;
|
int idx=0;
|
||||||
// ocoor is already reduced so can eliminate the modulo operation
|
// ocoor is already reduced so can eliminate the modulo operation
|
||||||
// for fast indexing and inline the routine
|
// for fast indexing and inline the routine
|
||||||
for(int d=0;d<_ndimension;d++) idx+=_ostride[d]*ocoor[d];
|
for(int d=0;d<_ndimension;d++) idx+=_ostride[d]*ocoor[d];
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
inline void oCoorFromOindex (std::vector<int>& coor,int Oindex){
|
inline void oCoorFromOindex (std::vector<int>& coor,int Oindex){
|
||||||
Lexicographic::CoorFromIndex(coor,Oindex,_rdimensions);
|
Lexicographic::CoorFromIndex(coor,Oindex,_rdimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void InOutCoorToLocalCoor (std::vector<int> &ocoor, std::vector<int> &icoor, std::vector<int> &lcoor) {
|
inline void InOutCoorToLocalCoor (std::vector<int> &ocoor, std::vector<int> &icoor, std::vector<int> &lcoor) {
|
||||||
lcoor.resize(_ndimension);
|
lcoor.resize(_ndimension);
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
lcoor[d] = ocoor[d] + _rdimensions[d] * icoor[d];
|
lcoor[d] = ocoor[d] + _rdimensions[d] * icoor[d];
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
// SIMD lane addressing
|
// SIMD lane addressing
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
inline void iCoorFromIindex(std::vector<int> &coor,int lane)
|
inline void iCoorFromIindex(std::vector<int> &coor,int lane)
|
||||||
{
|
{
|
||||||
Lexicographic::CoorFromIndex(coor,lane,_simd_layout);
|
Lexicographic::CoorFromIndex(coor,lane,_simd_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int PermuteDim(int dimension){
|
inline int PermuteDim(int dimension){
|
||||||
return _simd_layout[dimension]>1;
|
return _simd_layout[dimension]>1;
|
||||||
}
|
}
|
||||||
inline int PermuteType(int dimension){
|
inline int PermuteType(int dimension){
|
||||||
int permute_type=0;
|
int permute_type=0;
|
||||||
//
|
//
|
||||||
// FIXME:
|
// FIXME:
|
||||||
//
|
//
|
||||||
// Best way to encode this would be to present a mask
|
// Best way to encode this would be to present a mask
|
||||||
// for which simd dimensions are rotated, and the rotation
|
// for which simd dimensions are rotated, and the rotation
|
||||||
// size. If there is only one simd dimension rotated, this is just
|
// size. If there is only one simd dimension rotated, this is just
|
||||||
// a permute.
|
// a permute.
|
||||||
//
|
//
|
||||||
// Cases: PermuteType == 1,2,4,8
|
// Cases: PermuteType == 1,2,4,8
|
||||||
// Distance should be either 0,1,2..
|
// Distance should be either 0,1,2..
|
||||||
//
|
//
|
||||||
if ( _simd_layout[dimension] > 2 ) {
|
if ( _simd_layout[dimension] > 2 ) {
|
||||||
for(int d=0;d<_ndimension;d++){
|
for(int d=0;d<_ndimension;d++){
|
||||||
if ( d != dimension ) assert ( (_simd_layout[d]==1) );
|
if ( d != dimension ) assert ( (_simd_layout[d]==1) );
|
||||||
}
|
|
||||||
permute_type = RotateBit; // How to specify distance; this is not just direction.
|
|
||||||
return permute_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int d=_ndimension-1;d>dimension;d--){
|
|
||||||
if (_simd_layout[d]>1 ) permute_type++;
|
|
||||||
}
|
}
|
||||||
|
permute_type = RotateBit; // How to specify distance; this is not just direction.
|
||||||
return permute_type;
|
return permute_type;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
// Array sizing queries
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
inline int iSites(void) const { return _isites; };
|
for(int d=_ndimension-1;d>dimension;d--){
|
||||||
inline int Nsimd(void) const { return _isites; };// Synonymous with iSites
|
if (_simd_layout[d]>1 ) permute_type++;
|
||||||
inline int oSites(void) const { return _osites; };
|
|
||||||
inline int lSites(void) const { return _isites*_osites; };
|
|
||||||
inline int gSites(void) const { return _isites*_osites*_Nprocessors; };
|
|
||||||
inline int Nd (void) const { return _ndimension;};
|
|
||||||
|
|
||||||
inline const std::vector<int> LocalStarts(void) { return _lstart; };
|
|
||||||
inline const std::vector<int> &FullDimensions(void) { return _fdimensions;};
|
|
||||||
inline const std::vector<int> &GlobalDimensions(void) { return _gdimensions;};
|
|
||||||
inline const std::vector<int> &LocalDimensions(void) { return _ldimensions;};
|
|
||||||
inline const std::vector<int> &VirtualLocalDimensions(void) { return _ldimensions;};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
// Utility to print the full decomposition details
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void show_decomposition(){
|
|
||||||
std::cout << GridLogMessage << "\tFull Dimensions : " << _fdimensions << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tSIMD layout : " << _simd_layout << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tGlobal Dimensions : " << _gdimensions << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tLocal Dimensions : " << _ldimensions << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tReduced Dimensions : " << _rdimensions << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tOuter strides : " << _ostride << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tInner strides : " << _istride << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tiSites : " << _isites << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\toSites : " << _osites << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tlSites : " << lSites() << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tgSites : " << gSites() << std::endl;
|
|
||||||
std::cout << GridLogMessage << "\tNd : " << _ndimension << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
// Global addressing
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
void GlobalIndexToGlobalCoor(int gidx,std::vector<int> &gcoor){
|
|
||||||
assert(gidx< gSites());
|
|
||||||
Lexicographic::CoorFromIndex(gcoor,gidx,_gdimensions);
|
|
||||||
}
|
}
|
||||||
void LocalIndexToLocalCoor(int lidx,std::vector<int> &lcoor){
|
return permute_type;
|
||||||
assert(lidx<lSites());
|
}
|
||||||
Lexicographic::CoorFromIndex(lcoor,lidx,_ldimensions);
|
////////////////////////////////////////////////////////////////
|
||||||
|
// Array sizing queries
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
inline int iSites(void) const { return _isites; };
|
||||||
|
inline int Nsimd(void) const { return _isites; };// Synonymous with iSites
|
||||||
|
inline int oSites(void) const { return _osites; };
|
||||||
|
inline int lSites(void) const { return _isites*_osites; };
|
||||||
|
inline int gSites(void) const { return _isites*_osites*_Nprocessors; };
|
||||||
|
inline int Nd (void) const { return _ndimension;};
|
||||||
|
|
||||||
|
inline const std::vector<int> LocalStarts(void) { return _lstart; };
|
||||||
|
inline const std::vector<int> &FullDimensions(void) { return _fdimensions;};
|
||||||
|
inline const std::vector<int> &GlobalDimensions(void) { return _gdimensions;};
|
||||||
|
inline const std::vector<int> &LocalDimensions(void) { return _ldimensions;};
|
||||||
|
inline const std::vector<int> &VirtualLocalDimensions(void) { return _ldimensions;};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
// Utility to print the full decomposition details
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void show_decomposition(){
|
||||||
|
std::cout << GridLogMessage << "\tFull Dimensions : " << _fdimensions << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tSIMD layout : " << _simd_layout << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tGlobal Dimensions : " << _gdimensions << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tLocal Dimensions : " << _ldimensions << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tReduced Dimensions : " << _rdimensions << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tOuter strides : " << _ostride << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tInner strides : " << _istride << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tiSites : " << _isites << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\toSites : " << _osites << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tlSites : " << lSites() << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tgSites : " << gSites() << std::endl;
|
||||||
|
std::cout << GridLogMessage << "\tNd : " << _ndimension << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
// Global addressing
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
void GlobalIndexToGlobalCoor(int gidx,std::vector<int> &gcoor){
|
||||||
|
assert(gidx< gSites());
|
||||||
|
Lexicographic::CoorFromIndex(gcoor,gidx,_gdimensions);
|
||||||
|
}
|
||||||
|
void LocalIndexToLocalCoor(int lidx,std::vector<int> &lcoor){
|
||||||
|
assert(lidx<lSites());
|
||||||
|
Lexicographic::CoorFromIndex(lcoor,lidx,_ldimensions);
|
||||||
|
}
|
||||||
|
void GlobalCoorToGlobalIndex(const std::vector<int> & gcoor,int & gidx){
|
||||||
|
gidx=0;
|
||||||
|
int mult=1;
|
||||||
|
for(int mu=0;mu<_ndimension;mu++) {
|
||||||
|
gidx+=mult*gcoor[mu];
|
||||||
|
mult*=_gdimensions[mu];
|
||||||
}
|
}
|
||||||
void GlobalCoorToGlobalIndex(const std::vector<int> & gcoor,int & gidx){
|
}
|
||||||
gidx=0;
|
void GlobalCoorToProcessorCoorLocalCoor(std::vector<int> &pcoor,std::vector<int> &lcoor,const std::vector<int> &gcoor)
|
||||||
int mult=1;
|
{
|
||||||
for(int mu=0;mu<_ndimension;mu++) {
|
pcoor.resize(_ndimension);
|
||||||
gidx+=mult*gcoor[mu];
|
lcoor.resize(_ndimension);
|
||||||
mult*=_gdimensions[mu];
|
for(int mu=0;mu<_ndimension;mu++){
|
||||||
}
|
int _fld = _fdimensions[mu]/_processors[mu];
|
||||||
|
pcoor[mu] = gcoor[mu]/_fld;
|
||||||
|
lcoor[mu] = gcoor[mu]%_fld;
|
||||||
}
|
}
|
||||||
void GlobalCoorToProcessorCoorLocalCoor(std::vector<int> &pcoor,std::vector<int> &lcoor,const std::vector<int> &gcoor)
|
}
|
||||||
{
|
void GlobalCoorToRankIndex(int &rank, int &o_idx, int &i_idx ,const std::vector<int> &gcoor)
|
||||||
pcoor.resize(_ndimension);
|
{
|
||||||
lcoor.resize(_ndimension);
|
std::vector<int> pcoor;
|
||||||
for(int mu=0;mu<_ndimension;mu++){
|
std::vector<int> lcoor;
|
||||||
int _fld = _fdimensions[mu]/_processors[mu];
|
GlobalCoorToProcessorCoorLocalCoor(pcoor,lcoor,gcoor);
|
||||||
pcoor[mu] = gcoor[mu]/_fld;
|
rank = RankFromProcessorCoor(pcoor);
|
||||||
lcoor[mu] = gcoor[mu]%_fld;
|
/*
|
||||||
}
|
|
||||||
}
|
|
||||||
void GlobalCoorToRankIndex(int &rank, int &o_idx, int &i_idx ,const std::vector<int> &gcoor)
|
|
||||||
{
|
|
||||||
std::vector<int> pcoor;
|
|
||||||
std::vector<int> lcoor;
|
|
||||||
GlobalCoorToProcessorCoorLocalCoor(pcoor,lcoor,gcoor);
|
|
||||||
rank = RankFromProcessorCoor(pcoor);
|
|
||||||
/*
|
|
||||||
std::vector<int> cblcoor(lcoor);
|
std::vector<int> cblcoor(lcoor);
|
||||||
for(int d=0;d<cblcoor.size();d++){
|
for(int d=0;d<cblcoor.size();d++){
|
||||||
if( this->CheckerBoarded(d) ) {
|
if( this->CheckerBoarded(d) ) {
|
||||||
cblcoor[d] = lcoor[d]/2;
|
cblcoor[d] = lcoor[d]/2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
i_idx= iIndex(lcoor);
|
*/
|
||||||
o_idx= oIndex(lcoor);
|
i_idx= iIndex(lcoor);
|
||||||
}
|
o_idx= oIndex(lcoor);
|
||||||
|
}
|
||||||
|
|
||||||
void RankIndexToGlobalCoor(int rank, int o_idx, int i_idx , std::vector<int> &gcoor)
|
void RankIndexToGlobalCoor(int rank, int o_idx, int i_idx , std::vector<int> &gcoor)
|
||||||
{
|
{
|
||||||
gcoor.resize(_ndimension);
|
gcoor.resize(_ndimension);
|
||||||
std::vector<int> coor(_ndimension);
|
std::vector<int> coor(_ndimension);
|
||||||
|
|
||||||
ProcessorCoorFromRank(rank,coor);
|
ProcessorCoorFromRank(rank,coor);
|
||||||
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] = _ldimensions[mu]*coor[mu];
|
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] = _ldimensions[mu]*coor[mu];
|
||||||
|
|
||||||
iCoorFromIindex(coor,i_idx);
|
iCoorFromIindex(coor,i_idx);
|
||||||
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] += _rdimensions[mu]*coor[mu];
|
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] += _rdimensions[mu]*coor[mu];
|
||||||
|
|
||||||
oCoorFromOindex (coor,o_idx);
|
oCoorFromOindex (coor,o_idx);
|
||||||
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] += coor[mu];
|
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] += coor[mu];
|
||||||
|
|
||||||
|
}
|
||||||
|
void RankIndexCbToFullGlobalCoor(int rank, int o_idx, int i_idx, int cb,std::vector<int> &fcoor)
|
||||||
|
{
|
||||||
|
RankIndexToGlobalCoor(rank,o_idx,i_idx ,fcoor);
|
||||||
|
if(CheckerBoarded(0)){
|
||||||
|
fcoor[0] = fcoor[0]*2+cb;
|
||||||
}
|
}
|
||||||
void RankIndexCbToFullGlobalCoor(int rank, int o_idx, int i_idx, int cb,std::vector<int> &fcoor)
|
}
|
||||||
{
|
void ProcessorCoorLocalCoorToGlobalCoor(std::vector<int> &Pcoor,std::vector<int> &Lcoor,std::vector<int> &gcoor)
|
||||||
RankIndexToGlobalCoor(rank,o_idx,i_idx ,fcoor);
|
{
|
||||||
if(CheckerBoarded(0)){
|
gcoor.resize(_ndimension);
|
||||||
fcoor[0] = fcoor[0]*2+cb;
|
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] = Pcoor[mu]*_ldimensions[mu]+Lcoor[mu];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void ProcessorCoorLocalCoorToGlobalCoor(std::vector<int> &Pcoor,std::vector<int> &Lcoor,std::vector<int> &gcoor)
|
|
||||||
{
|
|
||||||
gcoor.resize(_ndimension);
|
|
||||||
for(int mu=0;mu<_ndimension;mu++) gcoor[mu] = Pcoor[mu]*_ldimensions[mu]+Lcoor[mu];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,12 +23,12 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_CARTESIAN_FULL_H
|
#ifndef GRID_CARTESIAN_FULL_H
|
||||||
#define GRID_CARTESIAN_FULL_H
|
#define GRID_CARTESIAN_FULL_H
|
||||||
|
|
||||||
namespace Grid{
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Grid Support.
|
// Grid Support.
|
||||||
@ -38,81 +38,81 @@ namespace Grid{
|
|||||||
class GridCartesian: public GridBase {
|
class GridCartesian: public GridBase {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int dummy;
|
int dummy;
|
||||||
virtual int CheckerBoardFromOindexTable (int Oindex) {
|
virtual int CheckerBoardFromOindexTable (int Oindex) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoardFromOindex (int Oindex)
|
virtual int CheckerBoardFromOindex (int Oindex)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoarded(int dim){
|
virtual int CheckerBoarded(int dim){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoard(const std::vector<int> &site){
|
virtual int CheckerBoard(const std::vector<int> &site){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoardDestination(int cb,int shift,int dim){
|
virtual int CheckerBoardDestination(int cb,int shift,int dim){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift, int ocb){
|
virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift, int ocb){
|
||||||
return shift;
|
return shift;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoardShift(int source_cb,int dim,int shift, int osite){
|
virtual int CheckerBoardShift(int source_cb,int dim,int shift, int osite){
|
||||||
return shift;
|
return shift;
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor takes a parent grid and possibly subdivides communicator.
|
// Constructor takes a parent grid and possibly subdivides communicator.
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
GridCartesian(const std::vector<int> &dimensions,
|
GridCartesian(const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid,
|
const std::vector<int> &processor_grid,
|
||||||
const GridCartesian &parent) : GridBase(processor_grid,parent,dummy)
|
const GridCartesian &parent) : GridBase(processor_grid,parent,dummy)
|
||||||
{
|
{
|
||||||
Init(dimensions,simd_layout,processor_grid);
|
Init(dimensions,simd_layout,processor_grid);
|
||||||
}
|
}
|
||||||
GridCartesian(const std::vector<int> &dimensions,
|
GridCartesian(const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid,
|
const std::vector<int> &processor_grid,
|
||||||
const GridCartesian &parent,int &split_rank) : GridBase(processor_grid,parent,split_rank)
|
const GridCartesian &parent,int &split_rank) : GridBase(processor_grid,parent,split_rank)
|
||||||
{
|
{
|
||||||
Init(dimensions,simd_layout,processor_grid);
|
Init(dimensions,simd_layout,processor_grid);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// Construct from comm world
|
// Construct from comm world
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
GridCartesian(const std::vector<int> &dimensions,
|
GridCartesian(const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid) : GridBase(processor_grid)
|
const std::vector<int> &processor_grid) : GridBase(processor_grid)
|
||||||
{
|
{
|
||||||
Init(dimensions,simd_layout,processor_grid);
|
Init(dimensions,simd_layout,processor_grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~GridCartesian() = default;
|
virtual ~GridCartesian() = default;
|
||||||
|
|
||||||
void Init(const std::vector<int> &dimensions,
|
void Init(const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid)
|
const std::vector<int> &processor_grid)
|
||||||
{
|
{
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// Grid information
|
// Grid information
|
||||||
///////////////////////
|
///////////////////////
|
||||||
_ndimension = dimensions.size();
|
_ndimension = dimensions.size();
|
||||||
|
|
||||||
_fdimensions.resize(_ndimension);
|
_fdimensions.resize(_ndimension);
|
||||||
_gdimensions.resize(_ndimension);
|
_gdimensions.resize(_ndimension);
|
||||||
_ldimensions.resize(_ndimension);
|
_ldimensions.resize(_ndimension);
|
||||||
_rdimensions.resize(_ndimension);
|
_rdimensions.resize(_ndimension);
|
||||||
_simd_layout.resize(_ndimension);
|
_simd_layout.resize(_ndimension);
|
||||||
_lstart.resize(_ndimension);
|
_lstart.resize(_ndimension);
|
||||||
_lend.resize(_ndimension);
|
_lend.resize(_ndimension);
|
||||||
|
|
||||||
_ostride.resize(_ndimension);
|
_ostride.resize(_ndimension);
|
||||||
_istride.resize(_ndimension);
|
_istride.resize(_ndimension);
|
||||||
|
|
||||||
_fsites = _gsites = _osites = _isites = 1;
|
_fsites = _gsites = _osites = _isites = 1;
|
||||||
|
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
_fdimensions[d] = dimensions[d]; // Global dimensions
|
_fdimensions[d] = dimensions[d]; // Global dimensions
|
||||||
_gdimensions[d] = _fdimensions[d]; // Global dimensions
|
_gdimensions[d] = _fdimensions[d]; // Global dimensions
|
||||||
@ -134,30 +134,30 @@ public:
|
|||||||
|
|
||||||
// Addressing support
|
// Addressing support
|
||||||
if (d == 0)
|
if (d == 0)
|
||||||
{
|
{
|
||||||
_ostride[d] = 1;
|
_ostride[d] = 1;
|
||||||
_istride[d] = 1;
|
_istride[d] = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_ostride[d] = _ostride[d - 1] * _rdimensions[d - 1];
|
_ostride[d] = _ostride[d - 1] * _rdimensions[d - 1];
|
||||||
_istride[d] = _istride[d - 1] * _simd_layout[d - 1];
|
_istride[d] = _istride[d - 1] * _simd_layout[d - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// subplane information
|
// subplane information
|
||||||
///////////////////////
|
///////////////////////
|
||||||
_slice_block.resize(_ndimension);
|
_slice_block.resize(_ndimension);
|
||||||
_slice_stride.resize(_ndimension);
|
_slice_stride.resize(_ndimension);
|
||||||
_slice_nblock.resize(_ndimension);
|
_slice_nblock.resize(_ndimension);
|
||||||
|
|
||||||
int block = 1;
|
int block = 1;
|
||||||
int nblock = 1;
|
int nblock = 1;
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
nblock *= _rdimensions[d];
|
nblock *= _rdimensions[d];
|
||||||
|
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
nblock /= _rdimensions[d];
|
nblock /= _rdimensions[d];
|
||||||
_slice_block[d] = block;
|
_slice_block[d] = block;
|
||||||
@ -165,7 +165,8 @@ public:
|
|||||||
_slice_nblock[d] = nblock;
|
_slice_nblock[d] = nblock;
|
||||||
block = block * _rdimensions[d];
|
block = block * _rdimensions[d];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,179 +24,179 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_CARTESIAN_RED_BLACK_H
|
#ifndef GRID_CARTESIAN_RED_BLACK_H
|
||||||
#define GRID_CARTESIAN_RED_BLACK_H
|
#define GRID_CARTESIAN_RED_BLACK_H
|
||||||
|
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
static const int CbRed =0;
|
static const int CbRed =0;
|
||||||
static const int CbBlack=1;
|
static const int CbBlack=1;
|
||||||
static const int Even =CbRed;
|
static const int Even =CbRed;
|
||||||
static const int Odd =CbBlack;
|
static const int Odd =CbBlack;
|
||||||
|
|
||||||
// Specialise this for red black grids storing half the data like a chess board.
|
// Specialise this for red black grids storing half the data like a chess board.
|
||||||
class GridRedBlackCartesian : public GridBase
|
class GridRedBlackCartesian : public GridBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<int> _checker_dim_mask;
|
std::vector<int> _checker_dim_mask;
|
||||||
int _checker_dim;
|
int _checker_dim;
|
||||||
std::vector<int> _checker_board;
|
std::vector<int> _checker_board;
|
||||||
|
|
||||||
virtual int CheckerBoarded(int dim){
|
virtual int CheckerBoarded(int dim){
|
||||||
if( dim==_checker_dim) return 1;
|
if( dim==_checker_dim) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
virtual int CheckerBoard(const std::vector<int> &site){
|
virtual int CheckerBoard(const std::vector<int> &site){
|
||||||
int linear=0;
|
int linear=0;
|
||||||
assert(site.size()==_ndimension);
|
assert(site.size()==_ndimension);
|
||||||
for(int d=0;d<_ndimension;d++){
|
for(int d=0;d<_ndimension;d++){
|
||||||
if(_checker_dim_mask[d])
|
if(_checker_dim_mask[d])
|
||||||
linear=linear+site[d];
|
linear=linear+site[d];
|
||||||
}
|
|
||||||
return (linear&0x1);
|
|
||||||
}
|
}
|
||||||
|
return (linear&0x1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Depending on the cb of site, we toggle source cb.
|
// Depending on the cb of site, we toggle source cb.
|
||||||
// for block #b, element #e = (b, e)
|
// for block #b, element #e = (b, e)
|
||||||
// we need
|
// we need
|
||||||
virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift,int ocb){
|
virtual int CheckerBoardShiftForCB(int source_cb,int dim,int shift,int ocb){
|
||||||
if(dim != _checker_dim) return shift;
|
if(dim != _checker_dim) return shift;
|
||||||
|
|
||||||
int fulldim =_fdimensions[dim];
|
int fulldim =_fdimensions[dim];
|
||||||
shift = (shift+fulldim)%fulldim;
|
shift = (shift+fulldim)%fulldim;
|
||||||
|
|
||||||
// Probably faster with table lookup;
|
// Probably faster with table lookup;
|
||||||
// or by looping over x,y,z and multiply rather than computing checkerboard.
|
// or by looping over x,y,z and multiply rather than computing checkerboard.
|
||||||
|
|
||||||
if ( (source_cb+ocb)&1 ) {
|
if ( (source_cb+ocb)&1 ) {
|
||||||
return (shift)/2;
|
return (shift)/2;
|
||||||
} else {
|
} else {
|
||||||
return (shift+1)/2;
|
return (shift+1)/2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
virtual int CheckerBoardFromOindexTable (int Oindex) {
|
}
|
||||||
return _checker_board[Oindex];
|
virtual int CheckerBoardFromOindexTable (int Oindex) {
|
||||||
}
|
return _checker_board[Oindex];
|
||||||
virtual int CheckerBoardFromOindex (int Oindex)
|
}
|
||||||
{
|
virtual int CheckerBoardFromOindex (int Oindex)
|
||||||
std::vector<int> ocoor;
|
{
|
||||||
oCoorFromOindex(ocoor,Oindex);
|
std::vector<int> ocoor;
|
||||||
return CheckerBoard(ocoor);
|
oCoorFromOindex(ocoor,Oindex);
|
||||||
}
|
return CheckerBoard(ocoor);
|
||||||
virtual int CheckerBoardShift(int source_cb,int dim,int shift,int osite){
|
}
|
||||||
|
virtual int CheckerBoardShift(int source_cb,int dim,int shift,int osite){
|
||||||
|
|
||||||
if(dim != _checker_dim) return shift;
|
if(dim != _checker_dim) return shift;
|
||||||
|
|
||||||
int ocb=CheckerBoardFromOindex(osite);
|
int ocb=CheckerBoardFromOindex(osite);
|
||||||
|
|
||||||
return CheckerBoardShiftForCB(source_cb,dim,shift,ocb);
|
return CheckerBoardShiftForCB(source_cb,dim,shift,ocb);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int CheckerBoardDestination(int source_cb,int shift,int dim){
|
virtual int CheckerBoardDestination(int source_cb,int shift,int dim){
|
||||||
if ( _checker_dim_mask[dim] ) {
|
if ( _checker_dim_mask[dim] ) {
|
||||||
// If _fdimensions[checker_dim] is odd, then shifting by 1 in other dims
|
// If _fdimensions[checker_dim] is odd, then shifting by 1 in other dims
|
||||||
// does NOT cause a parity hop.
|
// does NOT cause a parity hop.
|
||||||
int add=(dim==_checker_dim) ? 0 : _fdimensions[_checker_dim];
|
int add=(dim==_checker_dim) ? 0 : _fdimensions[_checker_dim];
|
||||||
if ( (shift+add) &0x1) {
|
if ( (shift+add) &0x1) {
|
||||||
return 1-source_cb;
|
return 1-source_cb;
|
||||||
} else {
|
|
||||||
return source_cb;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return source_cb;
|
return source_cb;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
|
return source_cb;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Create Redblack from original grid; require full grid pointer ?
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
GridRedBlackCartesian(const GridBase *base) : GridBase(base->_processors,*base)
|
|
||||||
{
|
|
||||||
int dims = base->_ndimension;
|
|
||||||
std::vector<int> checker_dim_mask(dims,1);
|
|
||||||
int checker_dim = 0;
|
|
||||||
Init(base->_fdimensions,base->_simd_layout,base->_processors,checker_dim_mask,checker_dim);
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Create redblack from original grid, with non-trivial checker dim mask
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
GridRedBlackCartesian(const GridBase *base,
|
|
||||||
const std::vector<int> &checker_dim_mask,
|
|
||||||
int checker_dim
|
|
||||||
) : GridBase(base->_processors,*base)
|
|
||||||
{
|
|
||||||
Init(base->_fdimensions,base->_simd_layout,base->_processors,checker_dim_mask,checker_dim) ;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~GridRedBlackCartesian() = default;
|
////////////////////////////////////////////////////////////
|
||||||
|
// Create Redblack from original grid; require full grid pointer ?
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GridRedBlackCartesian(const GridBase *base) : GridBase(base->_processors,*base)
|
||||||
|
{
|
||||||
|
int dims = base->_ndimension;
|
||||||
|
std::vector<int> checker_dim_mask(dims,1);
|
||||||
|
int checker_dim = 0;
|
||||||
|
Init(base->_fdimensions,base->_simd_layout,base->_processors,checker_dim_mask,checker_dim);
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Create redblack from original grid, with non-trivial checker dim mask
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GridRedBlackCartesian(const GridBase *base,
|
||||||
|
const std::vector<int> &checker_dim_mask,
|
||||||
|
int checker_dim
|
||||||
|
) : GridBase(base->_processors,*base)
|
||||||
|
{
|
||||||
|
Init(base->_fdimensions,base->_simd_layout,base->_processors,checker_dim_mask,checker_dim) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~GridRedBlackCartesian() = default;
|
||||||
#if 0
|
#if 0
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Create redblack grid ;; deprecate these. Should not
|
// Create redblack grid ;; deprecate these. Should not
|
||||||
// need direct creation of redblack without a full grid to base on
|
// need direct creation of redblack without a full grid to base on
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
GridRedBlackCartesian(const GridBase *base,
|
GridRedBlackCartesian(const GridBase *base,
|
||||||
const std::vector<int> &dimensions,
|
const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid,
|
const std::vector<int> &processor_grid,
|
||||||
const std::vector<int> &checker_dim_mask,
|
const std::vector<int> &checker_dim_mask,
|
||||||
int checker_dim
|
int checker_dim
|
||||||
) : GridBase(processor_grid,*base)
|
) : GridBase(processor_grid,*base)
|
||||||
{
|
{
|
||||||
Init(dimensions,simd_layout,processor_grid,checker_dim_mask,checker_dim);
|
Init(dimensions,simd_layout,processor_grid,checker_dim_mask,checker_dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Create redblack grid
|
// Create redblack grid
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
GridRedBlackCartesian(const GridBase *base,
|
GridRedBlackCartesian(const GridBase *base,
|
||||||
const std::vector<int> &dimensions,
|
const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid) : GridBase(processor_grid,*base)
|
const std::vector<int> &processor_grid) : GridBase(processor_grid,*base)
|
||||||
{
|
{
|
||||||
std::vector<int> checker_dim_mask(dimensions.size(),1);
|
std::vector<int> checker_dim_mask(dimensions.size(),1);
|
||||||
int checker_dim = 0;
|
int checker_dim = 0;
|
||||||
Init(dimensions,simd_layout,processor_grid,checker_dim_mask,checker_dim);
|
Init(dimensions,simd_layout,processor_grid,checker_dim_mask,checker_dim);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Init(const std::vector<int> &dimensions,
|
void Init(const std::vector<int> &dimensions,
|
||||||
const std::vector<int> &simd_layout,
|
const std::vector<int> &simd_layout,
|
||||||
const std::vector<int> &processor_grid,
|
const std::vector<int> &processor_grid,
|
||||||
const std::vector<int> &checker_dim_mask,
|
const std::vector<int> &checker_dim_mask,
|
||||||
int checker_dim)
|
int checker_dim)
|
||||||
{
|
{
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// Grid information
|
// Grid information
|
||||||
///////////////////////
|
///////////////////////
|
||||||
_checker_dim = checker_dim;
|
_checker_dim = checker_dim;
|
||||||
assert(checker_dim_mask[checker_dim] == 1);
|
assert(checker_dim_mask[checker_dim] == 1);
|
||||||
_ndimension = dimensions.size();
|
_ndimension = dimensions.size();
|
||||||
assert(checker_dim_mask.size() == _ndimension);
|
assert(checker_dim_mask.size() == _ndimension);
|
||||||
assert(processor_grid.size() == _ndimension);
|
assert(processor_grid.size() == _ndimension);
|
||||||
assert(simd_layout.size() == _ndimension);
|
assert(simd_layout.size() == _ndimension);
|
||||||
|
|
||||||
_fdimensions.resize(_ndimension);
|
_fdimensions.resize(_ndimension);
|
||||||
_gdimensions.resize(_ndimension);
|
_gdimensions.resize(_ndimension);
|
||||||
_ldimensions.resize(_ndimension);
|
_ldimensions.resize(_ndimension);
|
||||||
_rdimensions.resize(_ndimension);
|
_rdimensions.resize(_ndimension);
|
||||||
_simd_layout.resize(_ndimension);
|
_simd_layout.resize(_ndimension);
|
||||||
_lstart.resize(_ndimension);
|
_lstart.resize(_ndimension);
|
||||||
_lend.resize(_ndimension);
|
_lend.resize(_ndimension);
|
||||||
|
|
||||||
_ostride.resize(_ndimension);
|
_ostride.resize(_ndimension);
|
||||||
_istride.resize(_ndimension);
|
_istride.resize(_ndimension);
|
||||||
|
|
||||||
_fsites = _gsites = _osites = _isites = 1;
|
_fsites = _gsites = _osites = _isites = 1;
|
||||||
|
|
||||||
_checker_dim_mask = checker_dim_mask;
|
_checker_dim_mask = checker_dim_mask;
|
||||||
|
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
_fdimensions[d] = dimensions[d];
|
_fdimensions[d] = dimensions[d];
|
||||||
_gdimensions[d] = _fdimensions[d];
|
_gdimensions[d] = _fdimensions[d];
|
||||||
@ -204,11 +204,11 @@ public:
|
|||||||
_gsites = _gsites * _gdimensions[d];
|
_gsites = _gsites * _gdimensions[d];
|
||||||
|
|
||||||
if (d == _checker_dim)
|
if (d == _checker_dim)
|
||||||
{
|
{
|
||||||
assert((_gdimensions[d] & 0x1) == 0);
|
assert((_gdimensions[d] & 0x1) == 0);
|
||||||
_gdimensions[d] = _gdimensions[d] / 2; // Remove a checkerboard
|
_gdimensions[d] = _gdimensions[d] / 2; // Remove a checkerboard
|
||||||
_gsites /= 2;
|
_gsites /= 2;
|
||||||
}
|
}
|
||||||
_ldimensions[d] = _gdimensions[d] / _processors[d];
|
_ldimensions[d] = _gdimensions[d] / _processors[d];
|
||||||
assert(_ldimensions[d] * _processors[d] == _gdimensions[d]);
|
assert(_ldimensions[d] * _processors[d] == _gdimensions[d]);
|
||||||
_lstart[d] = _processor_coor[d] * _ldimensions[d];
|
_lstart[d] = _processor_coor[d] * _ldimensions[d];
|
||||||
@ -223,42 +223,42 @@ public:
|
|||||||
// all elements of a simd vector must have same checkerboard.
|
// all elements of a simd vector must have same checkerboard.
|
||||||
// If Ls vectorised, this must still be the case; e.g. dwf rb5d
|
// If Ls vectorised, this must still be the case; e.g. dwf rb5d
|
||||||
if (_simd_layout[d] > 1)
|
if (_simd_layout[d] > 1)
|
||||||
{
|
{
|
||||||
if (checker_dim_mask[d])
|
if (checker_dim_mask[d])
|
||||||
{
|
{
|
||||||
assert((_rdimensions[d] & 0x1) == 0);
|
assert((_rdimensions[d] & 0x1) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_osites *= _rdimensions[d];
|
_osites *= _rdimensions[d];
|
||||||
_isites *= _simd_layout[d];
|
_isites *= _simd_layout[d];
|
||||||
|
|
||||||
// Addressing support
|
// Addressing support
|
||||||
if (d == 0)
|
if (d == 0)
|
||||||
{
|
{
|
||||||
_ostride[d] = 1;
|
_ostride[d] = 1;
|
||||||
_istride[d] = 1;
|
_istride[d] = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_ostride[d] = _ostride[d - 1] * _rdimensions[d - 1];
|
_ostride[d] = _ostride[d - 1] * _rdimensions[d - 1];
|
||||||
_istride[d] = _istride[d - 1] * _simd_layout[d - 1];
|
_istride[d] = _istride[d - 1] * _simd_layout[d - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// subplane information
|
// subplane information
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
_slice_block.resize(_ndimension);
|
_slice_block.resize(_ndimension);
|
||||||
_slice_stride.resize(_ndimension);
|
_slice_stride.resize(_ndimension);
|
||||||
_slice_nblock.resize(_ndimension);
|
_slice_nblock.resize(_ndimension);
|
||||||
|
|
||||||
int block = 1;
|
int block = 1;
|
||||||
int nblock = 1;
|
int nblock = 1;
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
nblock *= _rdimensions[d];
|
nblock *= _rdimensions[d];
|
||||||
|
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
nblock /= _rdimensions[d];
|
nblock /= _rdimensions[d];
|
||||||
_slice_block[d] = block;
|
_slice_block[d] = block;
|
||||||
@ -267,55 +267,55 @@ public:
|
|||||||
block = block * _rdimensions[d];
|
block = block * _rdimensions[d];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Create a checkerboard lookup table
|
// Create a checkerboard lookup table
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
int rvol = 1;
|
int rvol = 1;
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
rvol = rvol * _rdimensions[d];
|
rvol = rvol * _rdimensions[d];
|
||||||
}
|
}
|
||||||
_checker_board.resize(rvol);
|
_checker_board.resize(rvol);
|
||||||
for (int osite = 0; osite < _osites; osite++)
|
for (int osite = 0; osite < _osites; osite++)
|
||||||
{
|
{
|
||||||
_checker_board[osite] = CheckerBoardFromOindex(osite);
|
_checker_board[osite] = CheckerBoardFromOindex(osite);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int oIndex(std::vector<int> &coor)
|
virtual int oIndex(std::vector<int> &coor)
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
if (d == _checker_dim)
|
if (d == _checker_dim)
|
||||||
{
|
{
|
||||||
idx += _ostride[d] * ((coor[d] / 2) % _rdimensions[d]);
|
idx += _ostride[d] * ((coor[d] / 2) % _rdimensions[d]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
idx += _ostride[d] * (coor[d] % _rdimensions[d]);
|
idx += _ostride[d] * (coor[d] % _rdimensions[d]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return idx;
|
return idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual int iIndex(std::vector<int> &lcoor)
|
virtual int iIndex(std::vector<int> &lcoor)
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (int d = 0; d < _ndimension; d++)
|
for (int d = 0; d < _ndimension; d++)
|
||||||
{
|
{
|
||||||
if (d == _checker_dim)
|
if (d == _checker_dim)
|
||||||
{
|
{
|
||||||
idx += _istride[d] * (lcoor[d] / (2 * _rdimensions[d]));
|
idx += _istride[d] * (lcoor[d] / (2 * _rdimensions[d]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
idx += _istride[d] * (lcoor[d] / _rdimensions[d]);
|
idx += _istride[d] * (lcoor[d] / _rdimensions[d]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
NAMESPACE_END(Grid);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user