From 7007d6a17618f5b68c1ababb916b41acad33d631 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Thu, 23 Apr 2015 11:04:19 +0100 Subject: [PATCH] Consolidate index to coor in a single routine --- lib/cartesian/Grid_cartesian_base.h | 30 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/cartesian/Grid_cartesian_base.h b/lib/cartesian/Grid_cartesian_base.h index aff9375a..6ccfd175 100644 --- a/lib/cartesian/Grid_cartesian_base.h +++ b/lib/cartesian/Grid_cartesian_base.h @@ -90,20 +90,26 @@ public: for(int d=0;d<_ndimension;d++) idx+=_ostride[d]*ocoor[d]; return idx; } - inline void CoorFromIndex (std::vector& coor,int index,std::vector &dims){ - coor.resize(_ndimension); + static inline void CoorFromIndex (std::vector& coor,int index,std::vector &dims){ + int nd= dims.size(); + coor.resize(nd); for(int d=0;d<_ndimension;d++){ coor[d] = index % dims[d]; index = index / dims[d]; } } - inline void oCoorFromOindex (std::vector& coor,int Oindex){ - coor.resize(_ndimension); + static inline void IndexFromCoor (std::vector& coor,int &index,std::vector &dims){ + int nd=dims.size(); + int stride=1; + index=0; for(int d=0;d<_ndimension;d++){ - coor[d] = Oindex % _rdimensions[d]; - Oindex = Oindex / _rdimensions[d]; + index = index+stride*coor[d]; + stride=stride*dims[d]; } } + inline void oCoorFromOindex (std::vector& coor,int Oindex){ + CoorFromIndex(coor,Oindex,_rdimensions); + } ////////////////////////////////////////////////////////// // SIMD lane addressing @@ -116,11 +122,7 @@ public: } inline void iCoorFromIindex(std::vector &coor,int lane) { - coor.resize(_ndimension); - for(int d=0;d<_ndimension;d++){ - coor[d] = lane % _simd_layout[d]; - lane = lane / _simd_layout[d]; - } + CoorFromIndex(coor,lane,_simd_layout); } inline int PermuteDim(int dimension){ return _simd_layout[dimension]>1; @@ -152,11 +154,7 @@ public: // Global addressing //////////////////////////////////////////////////////////////// void GlobalIndexToGlobalCoor(int gidx,std::vector &gcoor){ - gcoor.resize(_ndimension); - for(int d=0;d<_ndimension;d++){ - gcoor[d] = gidx % _gdimensions[d]; - gidx = gidx / _gdimensions[d]; - } + CoorFromIndex(gcoor,gidx,_gdimensions); } void GlobalCoorToGlobalIndex(const std::vector & gcoor,int & gidx){ gidx=0;