QDP++
qdp_layout.cc
Go to the documentation of this file.
1
9
10#include "qdp.h"
11#include "qdp_util.h"
12
13namespace QDP {
14
15 namespace Layout
16 {
19 {
20 multi1d<int> logical(Nd);
21
22 for(int i=0; i < Nd; ++i)
23 logical[i] = coord[i] / subgridLattSize()[i];
24
25 return logical;
26 }
27
29 multi1d<int> physcoord(Nd);
30 int linear=linearr;
31
32 for(int i=0; i < Nd; ++i){
33 physcoord[i] = linear % subgridLattSize()[i];
34 linear=(linear-physcoord[i])/subgridLattSize()[i];
35 }
36
37 return physcoord;
38 }
39
40 extern "C" {
41
42 /* Export this to "C" */
43 void QDPXX_getSiteCoords(int coord[], int node, int linear) QDP_CONST {
44 multi1d<int> wrapped_coords = siteCoords(node,linear);
45 for(int i=0; i < Nd; i++) {
46 coord[i] = wrapped_coords[i];
47 }
48 }
49
50 int QDPXX_getLinearSiteIndex(const int coord[]) {
51 multi1d<int> wrapped_coords(Nd);
52 for(int i=0; i < Nd; i++) {
53 wrapped_coords[i]=coord[i];
54 }
55 return linearSiteIndex(wrapped_coords);
56 }
57
58 int QDPXX_nodeNumber(const int coord[]) {
59 multi1d<int> wrapped_coords(Nd);
60 for(int i=0; i < Nd; i++) {
61 wrapped_coords[i]=coord[i];
62 }
63 return nodeNumber(wrapped_coords);
64 }
65 }
66 }
67
68
69#if QDP_USE_CB3D_LAYOUT == 1
70
71 multi1d<int> crtesn(int ipos, const multi1d<int>& latt_size)
72 {
73 multi1d<int> coord(latt_size.size());
74 int Ndim=latt_size.size() - 1; // Last elem latt size
75
76 /* Calculate the Cartesian coordinates of the VALUE of IPOS where the
77 * value is defined by
78 *
79 * for i = 0 to NDIM-1 {
80 * X_i <- mod( IPOS, L(i) )
81 * IPOS <- int( IPOS / L(i) )
82 * }
83 *
84 * NOTE: here the coord(i) and IPOS have their origin at 0.
85 */
86 for(int i = Ndim; i < Ndim+latt_size.size(); ++i)
87 {
88 int ix=i%latt_size.size();
89
90 coord[ix] = ipos % latt_size[ix];
91 ipos = ipos / latt_size[ix];
92 }
93
94 return coord;
95 }
96
98
102 int local_site(const multi1d<int>& coord, const multi1d<int>& latt_size)
103 {
104 int order = 0;
105
106 // In the 4D Case: t+Lt(x + Lx(y + Ly*z)
107 // essentially starting from i = dim[Nd-2]
108 // order = latt_size[i-1]*(coord[i])
109 // and need to wrap i-1 around to Nd-1 when it gets below 0
110 for(int mmu=latt_size.size()-2; mmu >= 0; --mmu) {
111 int wrapmu = (mmu-1) % latt_size.size();
112 if ( wrapmu < 0 ) wrapmu += latt_size.size();
113 order = latt_size[wrapmu]*(coord[mmu] + order);
114 }
115
116 order += coord[ latt_size.size()-1 ];
117
118 return order;
119 }
120
121
122#else
123 // Usual lattice decomposition -- x fastest, t slowest
125 multi1d<int> crtesn(int ipos, const multi1d<int>& latt_size)
126 {
127 multi1d<int> coord(latt_size.size());
128
129 /* Calculate the Cartesian coordinates of the VALUE of IPOS where the
130 * value is defined by
131 *
132 * for i = 0 to NDIM-1 {
133 * X_i <- mod( IPOS, L(i) )
134 * IPOS <- int( IPOS / L(i) )
135 * }
136 *
137 * NOTE: here the coord(i) and IPOS have their origin at 0.
138 */
139 for(int i=0; i < latt_size.size(); ++i)
140 {
141 coord[i] = ipos % latt_size[i];
142 ipos = ipos / latt_size[i];
143 }
144
145 return coord;
146 }
147
149
153 int local_site(const multi1d<int>& coord, const multi1d<int>& latt_size)
154 {
155 int order = 0;
156
157 for(int mmu=latt_size.size()-1; mmu >= 1; --mmu)
158 order = latt_size[mmu-1]*(coord[mmu] + order);
159
160 order += coord[0];
161
162 return order;
163 }
164
165#endif
166
167
168
169} // namespace QDP;
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
int size() const
Size of array.
Definition qdp_multi.h:60
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.
int linearSiteIndex(int site)
The linearized site index for the corresponding lexicographic site.
multi1d< int > siteCoords(int node, int index) QDP_CONST
Reconstruct the lattice coordinate from the node and site number.
void QDPXX_getSiteCoords(int coord[], int node, int linear) QDP_CONST
Definition qdp_layout.cc:43
int QDPXX_getLinearSiteIndex(const int coord[])
Definition qdp_layout.cc:50
const multi1d< int > & subgridLattSize()
Subgrid (grid on each node) lattice size.
multi1d< int > localLexiCoordFromLinear(const int &linearr)
Definition qdp_layout.cc:28
const multi1d< int > & nodeCoord()
Returns the logical node coordinates for this node.
int QDPXX_nodeNumber(const int coord[])
Definition qdp_layout.cc:58
Yet another random number generator.
int local_site(const multi1d< int > &coord, const multi1d< int > &latt_size)
Calculates the lexicographic site index from the coordinate of a site.
multi1d< int > crtesn(int ipos, const multi1d< int > &latt_size)
Decompose a lexicographic site into coordinates.
Primary include file for QDP.
#define QDP_CONST
Definition qdp.h:63