1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Consolidate index to coor in a single routine

This commit is contained in:
Peter Boyle 2015-04-23 11:04:19 +01:00
parent a37a9789c9
commit 7007d6a176

View File

@ -90,20 +90,26 @@ public:
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 CoorFromIndex (std::vector<int>& coor,int index,std::vector<int> &dims){ static inline void CoorFromIndex (std::vector<int>& coor,int index,std::vector<int> &dims){
coor.resize(_ndimension); int nd= dims.size();
coor.resize(nd);
for(int d=0;d<_ndimension;d++){ for(int d=0;d<_ndimension;d++){
coor[d] = index % dims[d]; coor[d] = index % dims[d];
index = index / dims[d]; index = index / dims[d];
} }
} }
inline void oCoorFromOindex (std::vector<int>& coor,int Oindex){ static inline void IndexFromCoor (std::vector<int>& coor,int &index,std::vector<int> &dims){
coor.resize(_ndimension); int nd=dims.size();
int stride=1;
index=0;
for(int d=0;d<_ndimension;d++){ for(int d=0;d<_ndimension;d++){
coor[d] = Oindex % _rdimensions[d]; index = index+stride*coor[d];
Oindex = Oindex / _rdimensions[d]; stride=stride*dims[d];
} }
} }
inline void oCoorFromOindex (std::vector<int>& coor,int Oindex){
CoorFromIndex(coor,Oindex,_rdimensions);
}
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
// SIMD lane addressing // SIMD lane addressing
@ -116,11 +122,7 @@ public:
} }
inline void iCoorFromIindex(std::vector<int> &coor,int lane) inline void iCoorFromIindex(std::vector<int> &coor,int lane)
{ {
coor.resize(_ndimension); CoorFromIndex(coor,lane,_simd_layout);
for(int d=0;d<_ndimension;d++){
coor[d] = lane % _simd_layout[d];
lane = lane / _simd_layout[d];
}
} }
inline int PermuteDim(int dimension){ inline int PermuteDim(int dimension){
return _simd_layout[dimension]>1; return _simd_layout[dimension]>1;
@ -152,11 +154,7 @@ public:
// Global addressing // Global addressing
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
void GlobalIndexToGlobalCoor(int gidx,std::vector<int> &gcoor){ void GlobalIndexToGlobalCoor(int gidx,std::vector<int> &gcoor){
gcoor.resize(_ndimension); CoorFromIndex(gcoor,gidx,_gdimensions);
for(int d=0;d<_ndimension;d++){
gcoor[d] = gidx % _gdimensions[d];
gidx = gidx / _gdimensions[d];
}
} }
void GlobalCoorToGlobalIndex(const std::vector<int> & gcoor,int & gidx){ void GlobalCoorToGlobalIndex(const std::vector<int> & gcoor,int & gidx){
gidx=0; gidx=0;