QDP++
qdp_scalarsite_specific.cc
Go to the documentation of this file.
1
7
8
9#include "qdp.h"
10#include "qdp_util.h"
11
12namespace QDP {
13
14//-----------------------------------------------------------------------------
15namespace Layout
16{
18 /* Assumes no inner grid */
20 {
21 const int nodeSites = Layout::sitesOnNode();
22 const int nodeNumber = Layout::nodeNumber();
24
25 if (mu < 0 || mu >= Nd)
26 QDP_error_exit("dimension out of bounds");
27
28 /* This pragma is from Jacques... Should be OK, since each i is independent
29 * no danger of concurrent writes */
30#pragma omp parallel for
31 for(int i=0; i < nodeSites; ++i)
32 {
34 d.elem(i) = cc.elem();
35 }
36
37 return d;
38 }
39}
40
41
42//-----------------------------------------------------------------------------
43// IO routine solely for debugging. Only defined here
44template<class T>
45std::ostream& operator<<(std::ostream& s, const multi1d<T>& s1)
46{
47 for(int i=0; i < s1.size(); ++i)
48 s << " " << s1[i];
49
50 return s;
51}
52
53
54//-----------------------------------------------------------------------------
56void Set::make(const SetFunc& fun)
57{
58 int nsubset_indices = fun.numSubsets();
59 const int nodeSites = Layout::sitesOnNode();
60 const int nodeNumber = Layout::nodeNumber();
61
62#if QDP_DEBUG >= 2
63 QDP_info("Set a subset: nsubset = %d",nsubset_indices);
64#endif
65
66 // This actually allocates the subsets
67 sub.resize(nsubset_indices);
68
69 // Create the space of the colorings of the lattice
70 lat_color.resize(nodeSites);
71
72 // Create the array holding the array of sitetable info
73 sitetables.resize(nsubset_indices);
74
75 // Loop over linear sites determining their color
76 /* This OMP pragma added by Jacques. Should be OK since in the end
77 each value of linear is independent */
78#pragma omp parallel for
79 for(int linear=0; linear < nodeSites; ++linear)
80 {
81 multi1d<int> coord = Layout::siteCoords(nodeNumber, linear);
82
83 int node = Layout::nodeNumber(coord);
84 int lin = Layout::linearSiteIndex(coord);
85 int icolor = fun(coord);
86
87#if QDP_DEBUG >= 3
88 std::cerr<<"linear="<<linear<<" coord="<<coord<<" node="<<node<<" col="<<icolor << std::endl;
89#endif
90
91 // Sanity checks
92 if (node != nodeNumber)
93 QDP_error_exit("Set: found site with node outside current node!");
94
95 if (lin != linear)
96 QDP_error_exit("Set: inconsistent linear sites");
97
98 if (icolor < 0 || icolor >= nsubset_indices)
99 QDP_error_exit("Set: coloring is outside legal range: color[%d]=%d",linear,icolor);
100
101 // The coloring of this linear site
102 lat_color[linear] = icolor;
103 }
104
105
106 /*
107 * Loop over the lexicographic sites.
108 * This implementation of the Set will always use a
109 * sitetable.
110 */
111
112 /* NB: This OMP parallel added by Jacques.
113 * Should be OK because each subset is independent,
114 * tho the number of subsets may be small... so scope for improvement
115 * from threading may be limited */
116
117#pragma omp parallel for
118 for(int cb=0; cb < nsubset_indices; ++cb)
119 {
120 // Always construct the sitetables.
121
122 // First loop and see how many sites are needed
123 int num_sitetable = 0;
124
125 /* FIXME: This is a 'histogram' -- not yet threaded */
126 for(int linear=0; linear < nodeSites; ++linear) {
127 if (lat_color[linear] == cb) {
128 ++num_sitetable;
129 }
130 }
131 // Now take the inverse of the lattice coloring to produce
132 // the site list
133 multi1d<int>& sitetable = sitetables[cb];
134 sitetable.resize(num_sitetable);
135
136
137 // Site ordering stuff for later
138 bool ordRep;
139 int start, end;
140
141 // Handle the case that there are no sites
142 if (num_sitetable > 0)
143 {
144 // For later sanity, initialize this to something
145 for(int i=0; i < num_sitetable; ++i)
146 sitetable[i] = -1;
147
148 for(int linear=0, j=0; linear < nodeSites; ++linear)
149 if (lat_color[linear] == cb)
150 sitetable[j++] = linear;
151
152
153 // Check *if* this coloring is contiguous and find the start
154 // and ending sites
155 ordRep = true;
156 start = sitetable[0]; // this is the beginning
157 end = sitetable[sitetable.size()-1]; // the absolute last site
158
159 // Now look for a hole
160 for(int prev=sitetable[0], i=0; i < sitetable.size(); ++i)
161 if (sitetable[i] != prev++)
162 {
163#if QDP_DEBUG >= 2
164 QDP_info("Set(%d): sitetable[%d]=%d",cb,i,sitetable[i]);
165#endif
166
167 // Found a hold. The rep is not ordered.
168 ordRep = false;
169 start = end = -1;
170 break;
171 }
172 }
173 else // num_sitetable == 0
174 {
175 ordRep = false;
176 start = end = -1;
177 }
178
179 sub[cb].make(ordRep, start, end, &(sitetables[cb]), cb, this);
180
181#if QDP_DEBUG >= 2
182 QDP_info("Subset(%d)",cb);
183#endif
184 }
185}
186
187
188} // namespace QDP;
T & elem(int i)
Definition qdp_outer.h:400
SetMap.
Definition qdp_subset.h:24
virtual int numSubsets() const =0
multi1d< int > lat_color
Index or color array of lattice.
Definition qdp_subset.h:124
void make(const SetFunc &fn)
Constructor from a function object.
multi1d< multi1d< int > > sitetables
Array of sitetable arrays.
Definition qdp_subset.h:127
multi1d< Subset > sub
A set is composed of an array of subsets.
Definition qdp_subset.h:121
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
int size() const
Size of array.
Definition qdp_multi.h:60
void resize(int ns1)
Resize routine, call a templated resize, using *this to disambiguate.
Definition qdp_multi.h:56
OScalar< PScalar< PScalar< RScalar< INTEGER32 > > > > Integer
OLattice< PScalar< PScalar< RScalar< INTEGER32 > > > > LatticeInteger
TextWriter & operator<<(TextWriter &txt, const std::string &output)
Definition qdp_io.cc:283
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.
int sitesOnNode()
Subgrid lattice volume.
multi1d< int > siteCoords(int node, int index) QDP_CONST
Reconstruct the lattice coordinate from the node and site number.
LatticeInteger latticeCoordinate(int mu)
coord[mu] <- mu : fill with lattice coord in mu direction
Yet another random number generator.
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
int QDP_info(const char *format,...)
Simple information display routine.
Definition qdp_util.cc:43
Primary include file for QDP.