QDP++
qdp_scalarvec_layout.cc
Go to the documentation of this file.
1
14
15#include "qdp_diagnostics.h"
16
17#include "qdp.h"
18#include "qdp_util.h"
19
20namespace QDP
21{
22
23 //-----------------------------------------------------------------------------
24 // Layout stuff specific to a scalarvec architecture
25 namespace Layout
26 {
27 //-----------------------------------------------------
29
34 struct LocalLayout_t
35 {
37 int vol;
38
40 multi1d<int> nrow;
41
43 int subgrid_vol;
44
46 int olattice_vol;
47
49 multi1d<int> logical_coord;
50
52 multi1d<int> logical_size;
53
54 } _layout;
55
56
57 //-----------------------------------------------------
58 // Functions
59
61 void destroy() {RNG::finalizeRNG();}
62
64 void setLattSize(const multi1d<int>& nrows) {_layout.nrow = nrows;}
65
67
68 void setSMPFlag(bool flag) {}
69
71
72 void setNumProc(int N) {}
73
75 const multi1d<int>& lattSize() {return _layout.nrow;}
76
78 int vol() {return _layout.vol;}
79
81 int sitesOnNode() {return _layout.subgrid_vol;}
82
84 int outerSitesOnNode() {return _layout.olattice_vol;}
85
87
88 bool primaryNode() {return true;}
89
91 const multi1d<int>& subgridLattSize() {return _layout.nrow;}
92
94 int nodeNumber() {return 0;}
95
97 int nodeNumber(const multi1d<int>& coord) {return 0;}
98
100 int numNodes() {return 1;}
101
103 const multi1d<int>& nodeCoord() {return _layout.logical_coord;}
104
106 const multi1d<int>& logicalSize() {return _layout.logical_size;}
107
109
110 int getNodeNumberFrom(const multi1d<int>& node_coord) {return 0;}
111
113
114 multi1d<int> getLogicalCoordFrom(int node)
115 {
116 multi1d<int> node_coord(Nd);
117 node_coord = 0;
118 return node_coord;
119 }
120
122 void init() {}
123
125 int linearSiteIndex(int lexicosite)
126 {
127 return linearSiteIndex(crtesn(lexicosite, lattSize()));
128 }
129
131 void initDefaults()
132 {
133 // Default set and subsets
135
136 // Default maps
138
139 // Initialize RNG
141
142 // Set default profile level
144 }
145
147 void create()
148 {
149 if ( ! QDP_isInitialized() )
150 QDP_error_exit("QDP is not initialized");
151
152 if (_layout.nrow.size() != Nd)
153 QDP_error_exit("dimension of lattice size not the same as the default");
154
155 _layout.vol=1;
156 for(int i=0; i < Nd; ++i)
157 _layout.vol *= _layout.nrow[i];
158 _layout.subgrid_vol = _layout.vol;
159 _layout.olattice_vol = _layout.vol >> INNER_LOG;
160
161 _layout.logical_coord.resize(Nd);
162 _layout.logical_size.resize(Nd);
163
164 _layout.logical_coord = 0;
165 _layout.logical_size = 1;
166
167#if QDP_DEBUG >= 2
168 fprintf(stderr,"vol=%d\n",_layout.vol);
169#endif
170
171 // This implementation requires there be a multiple of INNER_LEN sites
172 if (_layout.vol % INNER_LEN != 0)
173 QDP_error_exit("Layout::create() - this scalarvec implementation requires there be a multiple of %d sites", INNER_LEN);
174
175
176 // Sanity check - check the layout functions make sense
177 for(int i=0; i < vol(); ++i)
178 {
180 if (i != ii)
181 QDP_error_exit("Layout::create - Layout problems, the layout functions do not work correctly with this lattice size");
182 }
183
184 // Initialize various defaults
185 initDefaults();
186
187 QDP_info("Finished lattice layout");
188 }
189 }
190
191
192 //-----------------------------------------------------------------------------
193#if QDP_USE_LEXICO_LAYOUT == 1
194
195QDPXX_MESSAGE("Using a lexicographic layout")
196
197 namespace Layout
198 {
200
204 multi1d<int> siteCoords(int node, int linearsite) // ignore node
205 {
206 return crtesn(linearsite, lattSize());
207 }
208
210
211 int linearSiteIndex(const multi1d<int>& coord)
212 {
213 return local_site(coord, lattSize());
214 }
215 }
216
217
218 //-----------------------------------------------------------------------------
219
220#elif QDP_USE_CB2_LAYOUT == 1
221
222QDPXX_MESSAGE("Using a 2 checkerboard (red/black) layout")
223
224 namespace Layout
225 {
227
231 multi1d<int> siteCoords(int node, int linearsite) // ignore node
232 {
233 int vol_cb = vol() >> 1;
234 multi1d<int> cb_nrow = lattSize();
235 cb_nrow[0] >>= 1;
236
237 int cb = linearsite / vol_cb;
238 multi1d<int> coord = crtesn(linearsite % vol_cb, cb_nrow);
239
240 int cbb = cb;
241 for(int m=1; m<coord.size(); ++m)
242 cbb += coord[m];
243 cbb = cbb & 1;
244
245 coord[0] = 2*coord[0] + cbb;
246
247 return coord;
248 }
249
251
252 int linearSiteIndex(const multi1d<int>& coord)
253 {
254 int vol_cb = vol() >> 1;
255 multi1d<int> cb_nrow = lattSize();
256 cb_nrow[0] >>= 1;
257
258 multi1d<int> cb_coord = coord;
259
260 cb_coord[0] >>= 1; // Number of checkerboards
261
262 int cb = 0;
263 for(int m=0; m<coord.size(); ++m)
264 cb += coord[m];
265 cb = cb & 1;
266
267 return local_site(cb_coord, cb_nrow) + cb*vol_cb;
268 }
269 }
270
271 //-----------------------------------------------------------------------------
272
273#elif QDP_USE_CB32_LAYOUT == 1
274
275QDPXX_MESSAGE("Using a 32 checkerboard layout")
276
277 namespace Layout
278 {
280
284 multi1d<int> siteCoords(int node, int linearsite) // ignore node
285 {
286 int vol_cb = vol() >> (Nd+1);
287 multi1d<int> cb_nrow(Nd);
288 cb_nrow[0] = lattSize()[0] >> 2;
289 for(int i=1; i < Nd; ++i)
290 cb_nrow[i] = lattSize()[i] >> 1;
291
292 int subl = linearsite / vol_cb;
293 multi1d<int> coord = crtesn(linearsite % vol_cb, cb_nrow);
294
295 int cb = 0;
296 for(int m=1; m<Nd; ++m)
297 cb += coord[m];
298 cb &= 1;
299
300 coord[0] <<= 2;
301 for(int m=1; m<Nd; ++m)
302 coord[m] <<= 1;
303
304 subl ^= (cb << Nd);
305 for(int m=0; m<Nd; ++m)
306 coord[m] ^= (subl & (1 << m)) >> m;
307 coord[0] ^= (subl & (1 << Nd)) >> (Nd-1); // this gets the hypercube cb
308
309 return coord;
310 }
311
313
314 int linearSiteIndex(const multi1d<int>& coord)
315 {
316 int vol_cb = vol() >> (Nd+1);
317 multi1d<int> cb_nrow(Nd);
318 cb_nrow[0] = lattSize()[0] >> 2;
319 for(int i=1; i < Nd; ++i)
320 cb_nrow[i] = lattSize()[i] >> 1;
321
322 int subl = coord[Nd-1] & 1;
323 for(int m=Nd-2; m >= 0; --m)
324 subl = (subl << 1) + (coord[m] & 1);
325
326 int cb = 0;
327 for(int m=0; m < Nd; ++m)
328 cb += coord[m] >> 1;
329
330 subl += (cb & 1) << Nd; // Final color or checkerboard
331
332 // Construct the checkerboard lattice coord
333 multi1d<int> cb_coord(Nd);
334
335 cb_coord[0] = coord[0] >> 2;
336 for(int m=1; m < Nd; ++m)
337 cb_coord[m] = coord[m] >> 1;
338
339 return local_site(cb_coord, cb_nrow) + subl*vol_cb;
340 }
341 }
342
343#else
344
345#error "no appropriate layout defined"
346
347#endif
348
349 //-----------------------------------------------------------------------------
350
351
352} // namespace QDP;
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
#define INNER_LEN
#define INNER_LOG
const int Nd
Definition qdp_params.h:24
Layout namespace holding info on problem size and machine info.
Definition qdp_layout.cc:16
int nodeNumber()
Returns the node number of this node.
struct QDP::Layout::LocalLayout_t _layout
const multi1d< int > & logicalSize()
Returns the logical size of this machine.
void setLattSize(const multi1d< int > &nrows)
Set virtual grid (problem grid) lattice size.
int linearSiteIndex(int site)
The linearized site index for the corresponding lexicographic site.
int sitesOnNode()
Subgrid lattice volume.
multi1d< int > siteCoords(int node, int index) QDP_CONST
Reconstruct the lattice coordinate from the node and site number.
void create()
Main lattice creation routine.
int outerSitesOnNode()
Subgrid lattice volume.
void initDefaults()
Initializer for all the layout defaults.
int getNodeNumberFrom(const multi1d< int > &node_coord)
Returns the node number given some logical node coordinate.
void init()
Initializer for layout.
int numNodes()
Returns the number of nodes.
const multi1d< int > & lattSize()
Virtual grid (problem grid) lattice size.
const multi1d< int > & subgridLattSize()
Subgrid (grid on each node) lattice size.
void setNumProc(int N)
Set number of processors in a multi-threaded implementation.
multi1d< int > getLogicalCoordFrom(int node)
Returns the logical node coordinates given some node number.
void setSMPFlag(bool flag)
Set SMP flag – true if using smp/multiprocessor mode on a node.
int vol()
Total lattice volume.
bool primaryNode()
Returns whether this is the primary node.
void destroy()
Main destruction routine.
const multi1d< int > & nodeCoord()
Returns the logical node coordinates for this node.
void initDefaultRNG()
Initialize the random number generator with a default seed.
Definition qdp_random.cc:44
void finalizeRNG()
Yet another random number generator.
int getProgramProfileLevel()
bool QDP_isInitialized()
Is the machine initialized?
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
int local_site(const multi1d< int > &coord, const multi1d< int > &latt_size)
Calculates the lexicographic site index from the coordinate of a site.
void initDefaultMaps()
Initializer for maps.
Definition qdp_map.cc:42
void initDefaultSets()
Initializer for sets.
int setProfileLevel(int n)
multi1d< int > crtesn(int ipos, const multi1d< int > &latt_size)
Decompose a lexicographic site into coordinates.
int QDP_info(const char *format,...)
Simple information display routine.
Definition qdp_util.cc:43
Primary include file for QDP.
#define QDPXX_MESSAGE(s)
Local data specific to all architectures.
int subgrid_vol
Subgrid lattice volume.
int olattice_vol
Outer-subgrid lattice volume.
multi1d< int > logical_size
Logical system size.
int vol
Total lattice volume.
multi1d< int > nrow
Lattice size.
multi1d< int > logical_coord
Logical node coordinates.