QDP++
qdp_scalarvec_specific.cc
Go to the documentation of this file.
1
7
8#include "qdp.h"
9#include "qdp_util.h"
10
11namespace QDP {
12
13//-----------------------------------------------------------------------------
15void Map::make(const MapFunc& func)
16{
17#if QDP_DEBUG >= 3
18 QDP_info("Map::make");
19#endif
20
21 //--------------------------------------
22 // Setup the communication index arrays
23 goffsets.resize(Layout::vol());
24
25 /* Get the offsets needed for neighbour comm.
26 * goffsets(position)
27 * the offsets contain the current site, i.e the neighbour for site i
28 * is goffsets(i,dir,mu) and NOT i + goffset(..)
29 */
30 const multi1d<int>& nrow = Layout::lattSize();
31
32 // Loop over the sites on this node
33 for(int linear=0; linear < Layout::vol(); ++linear)
34 {
35 // Get the true lattice coord of this linear site index
36 multi1d<int> coord = Layout::siteCoords(0, linear);
37
38 // Source neighbor for this destination site
39 multi1d<int> fcoord = func(coord,+1);
40
41 // Source linear site and node
42 goffsets[linear] = Layout::linearSiteIndex(fcoord);
43 }
44
45#if 0
46 for(int ipos=0; ipos < Layout::vol(); ++ipos)
47 fprintf(stderr,"goffsets(%d,%d,%d) = %d\n",ipos,goffsets(ipos));
48#endif
49}
50
51
52
53
54
55
56//-----------------------------------------------------------------------
57// Compute simple NERSC-like checksum of a gauge field
58/*
59 * \ingroup io
60 *
61 * \param u gauge configuration ( Read )
62 *
63 * \return checksum
64 */
65
67 int mat_size)
68{
69 size_t size = sizeof(REAL32);
70 size_t su3_size = size*mat_size;
71 n_uint32_t checksum = 0; // checksum
72 const int nodeSites = Layout::sitesOnNode();
73
74 multi1d<multi1d<ColorMatrix> > sa(Nd); // extract gauge fields
75
76 for(int dd=0; dd<Nd; dd++) /* dir */
77 {
78 sa[dd].resize(nodeSites);
79 QDP_extract(sa[dd], u[dd], all);
80 }
81
82 char *chk_buf = new(std::nothrow) char[su3_size];
83 if( chk_buf == 0x0 ) {
84 QDP_error_exit("Unable to allocate chk_buf\n");
85 }
86
87 for(int linear=0; linear < nodeSites; ++linear)
88 {
89 for(int dd=0; dd<Nd; dd++) /* dir */
90 {
91 switch (mat_size)
92 {
93 case 12:
94 {
95 REAL32 su3[2][3][2];
96
97 for(int kk=0; kk<Nc; kk++) /* color */
98 for(int ii=0; ii<2; ii++) /* color */
99 {
100 Complex sitecomp = peekColor(sa[dd][linear],ii,kk);
101 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
102 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
103 }
104
105 memcpy(chk_buf, &(su3[0][0][0]), su3_size);
106 }
107 break;
108
109 case 18:
110 {
111 REAL32 su3[3][3][2];
112
113 for(int kk=0; kk<Nc; kk++) /* color */
114 for(int ii=0; ii<Nc; ii++) /* color */
115 {
116 Complex sitecomp = peekColor(sa[dd][linear],ii,kk);
117 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
118 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
119 }
120
121 memcpy(chk_buf, &(su3[0][0][0]), su3_size);
122 }
123 break;
124
125 default:
126 QDPIO::cerr << __func__ << ": unexpected size" << std::endl;
127 exit(1);
128 }
129
130 // Compute checksum
131 n_uint32_t* chk_ptr = (n_uint32_t*)chk_buf;
132 for(int i=0; i < mat_size*size/sizeof(n_uint32_t); ++i)
133 checksum += chk_ptr[i];
134 }
135 }
136
137 delete[] chk_buf;
138
139 return checksum;
140}
141
142
143//-----------------------------------------------------------------------
144// Read a QCD archive file
145// Read a QCD (NERSC) Archive format gauge field
146/*
147 * \ingroup io
148 *
149 * \param cfg_in binary writer object ( Modify )
150 * \param u gauge configuration ( Modify )
151 */
152
154 n_uint32_t& checksum, int mat_size, int float_size)
155{
156 ColorMatrix sitefield;
157 char *su3_buffer;
158
159 REAL su3[Nc][Nc][2];
160 checksum = 0;
161
162 su3_buffer = new char[ Nc*Nc*2*float_size ];
163 if( su3_buffer == 0x0 ) {
164 QDP_error_exit("Unable to allocate input buffer\n");
165 }
166
167 // Find the location of each site and send to primary node
168 for(int site=0; site < Layout::vol(); ++site)
169 {
170 multi1d<int> coord = crtesn(site, Layout::lattSize());
171
172 for(int dd=0; dd<Nd; dd++) /* dir */
173 {
174 /* Read an fe variable and write it to the BE */
175 cfg_in.readArray(su3_buffer, float_size, mat_size);
176
177 if (cfg_in.fail()) {
178 QDP_error_exit("Error reading configuration");
179 }
180
181
182 // Compute checksum
183 n_uint32_t* chk_ptr = (n_uint32_t*)su3_buffer;
184 for(int i=0; i < mat_size*float_size/sizeof(n_uint32_t); ++i)
185 checksum += chk_ptr[i];
186
187
188 /* Transfer from input buffer to the actual su3 buffer,
189 downcasting it to float if necessary */
190 if ( float_size == 4 ) {
191 REAL32 *su3_bufp = (REAL32 *)su3_buffer;
192 REAL *su3_p = (REAL *)su3;
193
194 for(int cp_index=0; cp_index < mat_size; cp_index++) {
195 su3_p[cp_index] = (REAL)su3_bufp[cp_index];
196 }
197 }
198 else if ( float_size == 8 ) {
199 REAL64 *su3_bufp = (REAL64 *)su3_buffer;
200 REAL *su3_p = (REAL *)su3;
201
202 for(int cp_index =0; cp_index < mat_size; cp_index++) {
203
204 su3_p[cp_index] = (REAL)su3_bufp[cp_index];
205 }
206 }
207
208 /* Reconstruct the third column if necessary */
209 if (mat_size == 12)
210 {
211 su3[2][0][0] = su3[0][1][0]*su3[1][2][0] - su3[0][1][1]*su3[1][2][1]
212 - su3[0][2][0]*su3[1][1][0] + su3[0][2][1]*su3[1][1][1];
213 su3[2][0][1] = su3[0][2][0]*su3[1][1][1] + su3[0][2][1]*su3[1][1][0]
214 - su3[0][1][0]*su3[1][2][1] - su3[0][1][1]*su3[1][2][0];
215
216 su3[2][1][0] = su3[0][2][0]*su3[1][0][0] - su3[0][2][1]*su3[1][0][1]
217 - su3[0][0][0]*su3[1][2][0] + su3[0][0][1]*su3[1][2][1];
218 su3[2][1][1] = su3[0][0][0]*su3[1][2][1] + su3[0][0][1]*su3[1][2][0]
219 - su3[0][2][0]*su3[1][0][1] - su3[0][2][1]*su3[1][0][0];
220
221 su3[2][2][0] = su3[0][0][0]*su3[1][1][0] - su3[0][0][1]*su3[1][1][1]
222 - su3[0][1][0]*su3[1][0][0] + su3[0][1][1]*su3[1][0][1];
223 su3[2][2][1] = su3[0][1][0]*su3[1][0][1] + su3[0][1][1]*su3[1][0][0]
224 - su3[0][0][0]*su3[1][1][1] - su3[0][0][1]*su3[1][1][0];
225 }
226
227 /* Copy into the big array */
228 for(int kk=0; kk<Nc; kk++) /* color */
229 {
230 for(int ii=0; ii<Nc; ii++) /* color */
231 {
232 Real re = su3[ii][kk][0];
233 Real im = su3[ii][kk][1];
234 Complex sitecomp = cmplx(re,im);
235 pokeColor(sitefield,sitecomp,ii,kk);
236 }
237 }
238
239 pokeSite(u[dd], sitefield, coord);
240 }
241 }
242 delete [] su3_buffer;
243}
244
245
246
247//-----------------------------------------------------------------------
248// Write a QCD archive file
249// Write a QCD (NERSC) Archive format gauge field
250/*
251 * \ingroup io
252 *
253 * \param cfg_out binary writer object ( Modify )
254 * \param u gauge configuration ( Read )
255 */
257 int mat_size)
258{
259 ColorMatrix sitefield;
260 float su3[3][3][2];
261
262 // Find the location of each site and send to primary node
263 for(int site=0; site < Layout::vol(); ++site)
264 {
265 multi1d<int> coord = crtesn(site, Layout::lattSize());
266
267 for(int dd=0; dd<Nd; dd++) /* dir */
268 {
269 sitefield = peekSite(u[dd], coord);
270
271 if ( mat_size == 12 )
272 {
273 for(int kk=0; kk < Nc; kk++) /* color */
274 for(int ii=0; ii < Nc-1; ii++) /* color */
275 {
276 Complex sitecomp = peekColor(sitefield,ii,kk);
277 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
278 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
279 }
280 }
281 else
282 {
283 for(int kk=0; kk < Nc; kk++) /* color */
284 for(int ii=0; ii < Nc; ii++) /* color */
285 {
286 Complex sitecomp = peekColor(sitefield,ii,kk);
287 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
288 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
289 }
290 }
291
292 // Write a site variable
293 cfg_out.writeArray((char *)&(su3[0][0][0]),sizeof(float), mat_size);
294 }
295 }
296
297 if (cfg_out.fail())
298 QDP_error_exit("Error writing configuration");
299}
300
301
302} // namespace QDP;
Binary input base class.
Definition qdp_io.h:372
Binary writer base class.
Definition qdp_io.h:1010
MapFunc.
Definition qdp_map.h:32
void make(const MapFunc &func)
Actual constructor from a function object.
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
OScalar< PScalar< PScalar< RComplex< REAL > > > > Complex
OScalar< PScalar< PColorMatrix< RComplex< REAL >, Nc > > > ColorMatrix
OScalar< PScalar< PScalar< RScalar< REAL > > > > Real
REAL32 REAL
double REAL64
void QDP_extract(multi1d< OScalar< T > > &dest, const OLattice< T > &src, const Subset &s)
Copy data values from field src to array dest.
OLattice< T1 > & pokeSite(OLattice< T1 > &l, const OScalar< T1 > &r, const multi1d< int > &coord)
Insert site element.
OScalar< T1 > peekSite(const OScalar< T1 > &l, const multi1d< int > &coord)
Extract site element.
void readArchiv(BinaryReader &cfg_in, multi1d< LatticeColorMatrix > &u, n_uint32_t &checksum, int mat_size, int float_size)
Read a NERSC Gauge Connection Archive file.
void writeArchiv(BinaryWriter &cfg_out, const multi1d< LatticeColorMatrix > &u, int mat_size)
Writes a NERSC Gauge Connection Archive gauge configuration file.
float toFloat(const IScalar< T > &s)
QDP Real to float primitive in conversion routine.
Definition qdp_inner.h:1623
const int Nc
Definition qdp_params.h:25
const int Nd
Definition qdp_params.h:24
Subset all
Default all subset.
Definition qdp_subset.cc:16
unsigned int n_uint32_t
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.
const multi1d< int > & lattSize()
Virtual grid (problem grid) lattice size.
int vol()
Total lattice volume.
StandardOutputStream cerr
Definition qdp_stdio.cc:22
Yet another random number generator.
MakeReturn< UnaryNode< FnReal, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnReal >::Type_t >::Expression_t real(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4972
MakeReturn< UnaryNode< FnPeekColorMatrix, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, C1 >::Expression_t peekColor(const QDPExpr< T1, C1 > &l, int row, int col)
Definition qdp_newops.h:161
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
C1 & pokeColor(QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r, int row, int col)
Definition qdp_newops.h:360
MakeReturn< BinaryNode< FnCmplx, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, FnCmplx >::Type_t >::Expression_t cmplx(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2348
n_uint32_t computeChecksum(const multi1d< LatticeColorMatrix > &u, int mat_size)
Compute simple NERSC-like checksum of a gauge field.
MakeReturn< UnaryNode< FnImag, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnImag >::Type_t >::Expression_t imag(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4985
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.