QDP++
qdp_scalar_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#include "qdp_allocator.h"
20
21namespace QDP
22{
23 float pool_size_in_gb = 8.0;
24
25 //-----------------------------------------------------------------------------
26 // Layout stuff specific to a scalar architecture
27 namespace Layout
28 {
29 //-----------------------------------------------------
31
36 struct LocalLayout_t
37 {
39 int vol;
40
42 multi1d<int> nrow;
43
45 int subgrid_vol;
46
48 multi1d<int> logical_coord;
49
51 multi1d<int> logical_size;
52
54 multi1d<int> iogrid;
55
56 } _layout;
57
58
59 //-----------------------------------------------------
60 // Functions
61
63 void destroy() {RNG::finalizeRNG();}
64
66 void setLattSize(const multi1d<int>& nrows) {_layout.nrow = nrows;}
67
69
70 void setSMPFlag(bool flag) {}
71
73
74 void setNumProc(int N) {}
75
77 const multi1d<int>& lattSize() {return _layout.nrow;}
78
80 int vol() {return _layout.vol;}
81
83 int sitesOnNode() {return _layout.subgrid_vol;}
84
86
87 bool primaryNode() {return true;}
88
90 const multi1d<int>& subgridLattSize() {return _layout.nrow;}
91
93 int nodeNumber() {return 0;}
94
96 int nodeNumber(const multi1d<int>& coord) {return 0;}
97
99 int numNodes() {return 1;}
100
102 const multi1d<int>& nodeCoord() {return _layout.logical_coord;}
103
105 const multi1d<int>& logicalSize() {return _layout.logical_size;}
106
108
109 int getNodeNumberFrom(const multi1d<int>& node_coord) {return 0;}
110
112
113 multi1d<int> getLogicalCoordFrom(int node)
114 {
115 multi1d<int> node_coord(Nd);
116 node_coord = 0;
117 return node_coord;
118 }
119
120
121
123
124 bool isIOGridDefined(void) QDP_CONST
125 {
126 return true;
127 }
128
130 int numIONodeGrid(void) QDP_CONST
131 {
132 return 1;
133 }
134
137 {
138 // Scalar machine: It's 1x1x1x1
139 _layout.iogrid.resize(Nd);
140 for(int i=0; i < Nd; i++) {
141 _layout.iogrid[i] = 1;
142 }
143 }
144
146 void setIONodeGrid(const multi1d<int>& io_grid)
147 {
148 // Completely ignore user supplied grid :)
149 // Its scalar
151 }
152
154 const multi1d<int>& getIONodeGrid() QDP_CONST
155 {
156 return _layout.iogrid;
157 }
158
160 void init() {}
161
163 int linearSiteIndex(int lexicosite)
164 {
165 return linearSiteIndex(crtesn(lexicosite, lattSize()));
166 }
167
169 void initDefaults()
170 {
171 // Default set and subsets
173
174 // Default maps
176
177 // Initialize RNG
179
180 // Set default profile level
182
183 // Set IO node grid defaults.
185 }
186
188 void create()
189 {
190 if ( ! QDP_isInitialized() )
191 QDP_error_exit("QDP is not initialized");
192
193 if (_layout.nrow.size() != Nd)
194 QDP_error_exit("dimension of lattice size not the same as the default");
195
196 _layout.vol=1;
197
198 for(int i=0; i < Nd; ++i)
199 _layout.vol *= _layout.nrow[i];
200
201 _layout.subgrid_vol = _layout.vol;
202
203 _layout.logical_coord.resize(Nd);
204 _layout.logical_size.resize(Nd);
205
206 _layout.logical_coord = 0;
207 _layout.logical_size = 1;
208
209#if QDP_DEBUG >= 2
210 fprintf(stderr,"vol=%d\n",_layout.vol);
211#endif
212
213 // Diagnostics
214 QDPIO::cout << "Lattice initialized:\n";
215 QDPIO::cout << " problem size =";
216 for(int i=0; i < Nd; ++i)
217 QDPIO::cout << " " << _layout.nrow[i];
218 QDPIO::cout << std::endl;
219
220 // Same as the problem size... we are scalar
221 QDPIO::cout << " layout size =";
222 for(int i=0; i < Nd; ++i)
223 QDPIO::cout << " " << _layout.nrow[i];
224 QDPIO::cout << std::endl;
225
226 QDPIO::cout << " logical machine size =";
227 for(int i=0; i < Nd; ++i)
228 QDPIO::cout << " " << (int)1;
229 QDPIO::cout << std::endl;
230
231 QDPIO::cout << " subgrid size =";
232 for(int i=0; i < Nd; ++i)
233 QDPIO::cout << " " << _layout.nrow[i];
234 QDPIO::cout << std::endl;
235
236 QDPIO::cout << " total number of nodes = " << 1 << std::endl;
237 QDPIO::cout << " total volume = " << _layout.vol << std::endl;
238 QDPIO::cout << " subgrid volume = " << _layout.vol << std::endl;
239
240
241 // Sanity check - check the layout functions make sense
242#pragma omp parallel for
243 for(int i=0; i < _layout.vol; ++i)
244 {
246
247#if QDP_DEBUG >= 3
248 {
249 fprintf(stderr,"call nodenumber\n");
250 int noden = Layout::nodeNumber();
251 fprintf(stderr,"call sitecoords\n");
252 multi1d<int> coord = Layout::siteCoords(noden,i);
253 fprintf(stderr,"call linearsiteindex\n");
254 int j = Layout::linearSiteIndex(coord);
255 fprintf(stderr,"site= %d coord= %d %d %d %d j= %d node=%d\n",
256 i,coord[0],coord[1],coord[2],coord[3],
257 j,noden);
258 }
259#endif
260
261 if (i != j)
262 QDP_error_exit("Layout::create - Layout problems, the layout functions do not work correctly with this lattice size");
263 }
264 size_t pool_size_in_MB = static_cast<size_t>(floor(pool_size_in_gb*1024.0));
265
267 // Initialize various defaults
268 initDefaults();
269
270 QDPIO::cout << "Finished lattice layout" << std::endl;
271 }
272 }
273
274
275 //-----------------------------------------------------------------------------
276#if QDP_USE_LEXICO_LAYOUT == 1
277
278QDPXX_MESSAGE("Using a lexicographic layout")
279
280 namespace Layout
281 {
283
287 multi1d<int> siteCoords(int node, int linearsite) // ignore node
288 {
289 return crtesn(linearsite, lattSize());
290 }
291
293
294 int linearSiteIndex(const multi1d<int>& coord)
295 {
296 return local_site(coord, lattSize());
297 }
298 }
299
300
301 //-----------------------------------------------------------------------------
302
303#elif QDP_USE_CB2_LAYOUT == 1
304
305QDPXX_MESSAGE("Using a 2 checkerboard (red/black) layout")
306
307 namespace Layout
308 {
310
314 multi1d<int> siteCoords(int node, int linearsite) // ignore node
315 {
316 int vol_cb = vol() >> 1;
317 multi1d<int> cb_nrow = lattSize();
318 cb_nrow[0] >>= 1;
319
320 int cb = linearsite / vol_cb;
321 multi1d<int> coord = crtesn(linearsite % vol_cb, cb_nrow);
322
323 int cbb = cb;
324 for(int m=1; m<coord.size(); ++m)
325 cbb += coord[m];
326 cbb = cbb & 1;
327
328 coord[0] = 2*coord[0] + cbb;
329
330 return coord;
331 }
332
334
335 int linearSiteIndex(const multi1d<int>& coord)
336 {
337 int vol_cb = vol() >> 1;
338 multi1d<int> cb_nrow = lattSize();
339 cb_nrow[0] >>= 1;
340
341 multi1d<int> cb_coord = coord;
342
343 cb_coord[0] >>= 1; // Number of checkerboards
344
345 int cb = 0;
346 for(int m=0; m<coord.size(); ++m)
347 cb += coord[m];
348 cb = cb & 1;
349
350 return local_site(cb_coord, cb_nrow) + cb*vol_cb;
351 }
352 }
353
354
355
356 //-----------------------------------------------------------------------------
357
358#elif QDP_USE_CB3D_LAYOUT == 1
359
360QDPXX_MESSAGE("Using a 2 checkerboard (red/black) layout but in 3D. Time running fastest")
361
362 namespace Layout
363 {
364
365
367
373
374 multi1d<int> siteCoords(int node, int linearsite) // ignore node
375 {
376 int vol_cb = vol() / 2;
377 multi1d<int> cb_nrow = lattSize();
378 cb_nrow[0] /=2;
379
380 int cb = linearsite / vol_cb;
381
382 // This now uses crtesn with the t running fastest
383 multi1d<int> coord = crtesn(linearsite % vol_cb, cb_nrow);
384
385 int cbb = cb;
386 for(int m=1; m<coord.size()-1; ++m) // Nd-1 checkerboard
387 cbb += coord[m];
388
389 cbb = cbb & 1;
390
391 coord[0] = 2*coord[0] + cbb;
392
393 return coord;
394 }
395
397
398 int linearSiteIndex(const multi1d<int>& coord)
399 {
400 int vol_cb = vol() / 2;
401 multi1d<int> cb_nrow = lattSize();
402 cb_nrow[0] /= 2;
403
404 multi1d<int> cb_coord = coord;
405
406 cb_coord[0] /= 2; // Number of checkerboards
407
408 int cb = 0;
409 for(int m=0; m<coord.size()-1; ++m) // 3d checkerboard
410 cb += coord[m];
411
412 cb = cb & 1;
413
414 // Use funky local site
415 return local_site(cb_coord, cb_nrow) + cb*vol_cb;
416 }
417 }
418
419
420 //-----------------------------------------------------------------------------
421
422#elif QDP_USE_CB32_LAYOUT == 1
423
424QDPXX_MESSAGE("Using a 32 checkerboard layout")
425
426 namespace Layout
427 {
429
433 multi1d<int> siteCoords(int node, int linearsite) // ignore node
434 {
435 int vol_cb = vol() >> (Nd+1);
436 multi1d<int> cb_nrow(Nd);
437 cb_nrow[0] = lattSize()[0] >> 2;
438 for(int i=1; i < Nd; ++i)
439 cb_nrow[i] = lattSize()[i] >> 1;
440
441 int subl = linearsite / vol_cb;
442 multi1d<int> coord = crtesn(linearsite % vol_cb, cb_nrow);
443
444 int cb = 0;
445 for(int m=1; m<Nd; ++m)
446 cb += coord[m];
447 cb &= 1;
448
449 coord[0] <<= 2;
450 for(int m=1; m<Nd; ++m)
451 coord[m] <<= 1;
452
453 subl ^= (cb << Nd);
454 for(int m=0; m<Nd; ++m)
455 coord[m] ^= (subl & (1 << m)) >> m;
456 coord[0] ^= (subl & (1 << Nd)) >> (Nd-1); // this gets the hypercube cb
457
458 return coord;
459 }
460
462
463 int linearSiteIndex(const multi1d<int>& coord)
464 {
465 int vol_cb = vol() >> (Nd+1);
466 multi1d<int> cb_nrow(Nd);
467 cb_nrow[0] = lattSize()[0] >> 2;
468 for(int i=1; i < Nd; ++i)
469 cb_nrow[i] = lattSize()[i] >> 1;
470
471 int subl = coord[Nd-1] & 1;
472 for(int m=Nd-2; m >= 0; --m)
473 subl = (subl << 1) + (coord[m] & 1);
474
475 int cb = 0;
476 for(int m=0; m < Nd; ++m)
477 cb += coord[m] >> 1;
478
479 subl += (cb & 1) << Nd; // Final color or checkerboard
480
481 // Construct the checkerboard lattice coord
482 multi1d<int> cb_coord(Nd);
483
484 cb_coord[0] = coord[0] >> 2;
485 for(int m=1; m < Nd; ++m)
486 cb_coord[m] = coord[m] >> 1;
487
488 return local_site(cb_coord, cb_nrow) + subl*vol_cb;
489 }
490 }
491
492#else
493
494#error "no appropriate layout defined"
495
496#endif
497
498 //-----------------------------------------------------------------------------
499
500
501} // namespace QDP;
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
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 setIONodeGrid(const multi1d< int > &io_grid)
Set the I/O Node grid – satisfy interface.
void create()
Main lattice creation routine.
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.
bool isIOGridDefined(void) QDP_CONST
check if I/O grid is defined
const multi1d< int > & subgridLattSize()
Subgrid (grid on each node) lattice size.
void setNumProc(int N)
Set number of processors in a multi-threaded implementation.
void setIONodeGridDefaults()
Default initializer.
int numIONodeGrid(void) QDP_CONST
number of I/O nodes
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.
const multi1d< int > & getIONodeGrid() QDP_CONST
Get the I/O Node grid.
StandardOutputStream cout
Definition qdp_stdio.cc:21
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.
MakeReturn< UnaryNode< FnFloor, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnFloor >::Type_t >::Expression_t floor(const QDPExpr< T1, C1 > &l)
Definition qdp.h:5388
int setProfileLevel(int n)
multi1d< int > crtesn(int ipos, const multi1d< int > &latt_size)
Decompose a lexicographic site into coordinates.
float pool_size_in_gb
Primary include file for QDP.
#define QDP_CONST
Definition qdp.h:63
Catch-alls for all memory allocators.
#define QDPXX_MESSAGE(s)
Local data specific to all architectures.
int subgrid_vol
Subgrid lattice volume.
multi1d< int > logical_size
Logical system size.
int vol
Total lattice volume.
multi1d< int > iogrid
IO Grid size.
multi1d< int > nrow
Lattice size.
multi1d< int > logical_coord
Logical node coordinates.