QDP++
qdp_scalar_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 // nrow is not used here. Comment it out to satisfy -Wall
31 // const multi1d<int>& nrow = Layout::lattSize();
32
33 // Loop over the sites on this node
34#pragma omp parallel for
35 for(int linear=0; linear < Layout::vol(); ++linear)
36 {
37 // Get the true lattice coord of this linear site index
38 multi1d<int> coord = Layout::siteCoords(0, linear);
39
40 // Source neighbor for this destination site
41 multi1d<int> fcoord = func(coord,+1);
42
43 // Source linear site and node
44 goffsets[linear] = Layout::linearSiteIndex(fcoord);
45 }
46
47#if 0
48 for(int ipos=0; ipos < Layout::vol(); ++ipos)
49 fprintf(stderr,"goffsets(%d,%d,%d) = %d\n",ipos,goffsets(ipos));
50#endif
51}
52
53
54
55//-----------------------------------------------------------------------
56// Compute simple NERSC-like checksum of a gauge field
57/*
58 * \ingroup io
59 *
60 * \param u gauge configuration ( Read )
61 *
62 * \return checksum
63 */
64
66 int mat_size)
67{
68 size_t size = sizeof(REAL32);
69 size_t su3_size = size*mat_size;
70 uint32_t checksum = 0; // checksum
71 const int nodeSites = Layout::sitesOnNode();
72
73 multi1d<multi1d<ColorMatrix> > sa(Nd); // extract gauge fields
74
75 for(int dd=0; dd<Nd; dd++) /* dir */
76 {
77 sa[dd].resize(nodeSites);
78 QDP_extract(sa[dd], u[dd], all);
79 }
80
81 char *chk_buf = new(std::nothrow) char[su3_size];
82 if( chk_buf == 0x0 ) {
83 QDP_error_exit("Unable to allocate chk_buf\n");
84 }
85
86 for(int linear=0; linear < nodeSites; ++linear)
87 {
88 for(int dd=0; dd<Nd; dd++) /* dir */
89 {
90 switch (mat_size)
91 {
92 case 12:
93 {
94 REAL32 su3[2][3][2];
95
96 for(int kk=0; kk<Nc; kk++) /* color */
97 for(int ii=0; ii<2; ii++) /* color */
98 {
99 Complex sitecomp = peekColor(sa[dd][linear],ii,kk);
100 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
101 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
102 }
103
104 memcpy(chk_buf, &(su3[0][0][0]), su3_size);
105 }
106 break;
107
108 case 18:
109 {
110 REAL32 su3[3][3][2];
111
112 for(int kk=0; kk<Nc; kk++) /* color */
113 for(int ii=0; ii<Nc; ii++) /* color */
114 {
115 Complex sitecomp = peekColor(sa[dd][linear],ii,kk);
116 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
117 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
118 }
119
120 memcpy(chk_buf, &(su3[0][0][0]), su3_size);
121 }
122 break;
123
124 default:
125 QDPIO::cerr << __func__ << ": unexpected size" << std::endl;
126 QDP_abort(1);
127 }
128
129 // Compute checksum
130 uint32_t* chk_ptr = (uint32_t*)chk_buf;
131 for(int i=0; i < mat_size*size/sizeof(uint32_t); ++i)
132 checksum += chk_ptr[i];
133 }
134 }
135
136 delete[] chk_buf;
137
138 // Get all nodes to contribute
139 QDPInternal::globalSumArray((unsigned int*)&checksum, 1); // g++ requires me to narrow the type to unsigned int
140
141 return checksum;
142}
143
144
145//-----------------------------------------------------------------------
146// Read a QCD archive file
147// Read a QCD (NERSC) Archive format gauge field
148/*
149 * \ingroup io
150 *
151 * \param cfg_in binary writer object ( Modify )
152 * \param u gauge configuration ( Modify )
153 */
154
156 uint32_t& checksum, int mat_size, int float_size)
157{
158 ColorMatrix sitefield;
159 char *su3_buffer;
160
161 REAL su3[Nc][Nc][2];
162 checksum = 0;
163
164 su3_buffer = new char[ Nc*Nc*2*float_size ];
165 if( su3_buffer == 0x0 ) {
166 QDP_error_exit("Unable to allocate input buffer\n");
167 }
168
169 // Find the location of each site and send to primary node
170 for(int site=0; site < Layout::vol(); ++site)
171 {
172 multi1d<int> coord = crtesn(site, Layout::lattSize());
173
174 for(int dd=0; dd<Nd; dd++) /* dir */
175 {
176 /* Read an fe variable and write it to the BE */
177 cfg_in.readArray(su3_buffer, float_size, mat_size);
178
179 if (cfg_in.fail()) {
180 QDP_error_exit("Error reading configuration");
181 }
182
183
184 // Compute checksum
185 uint32_t* chk_ptr = (uint32_t*)su3_buffer;
186 for(int i=0; i < mat_size*float_size/sizeof(uint32_t); ++i)
187 checksum += chk_ptr[i];
188
189
190 /* Transfer from input buffer to the actual su3 buffer,
191 downcasting it to float if necessary */
192 if ( float_size == 4 )
193 {
194 REAL32 *su3_bufp = (REAL32 *)su3_buffer;
195 REAL *su3_p = (REAL *)su3;
196
197 for(int cp_index=0; cp_index < mat_size; cp_index++) {
198 su3_p[cp_index] = (REAL)su3_bufp[cp_index];
199 }
200 }
201 else if ( float_size == 8 )
202 {
203 REAL64 *su3_bufp = (REAL64 *)su3_buffer;
204 REAL *su3_p = (REAL *)su3;
205
206 for(int cp_index =0; cp_index < mat_size; cp_index++) {
207
208 su3_p[cp_index] = (REAL)su3_bufp[cp_index];
209 }
210 }
211
212 /* Reconstruct the third column if necessary */
213 if (mat_size == 12)
214 {
215 su3[2][0][0] = su3[0][1][0]*su3[1][2][0] - su3[0][1][1]*su3[1][2][1]
216 - su3[0][2][0]*su3[1][1][0] + su3[0][2][1]*su3[1][1][1];
217 su3[2][0][1] = su3[0][2][0]*su3[1][1][1] + su3[0][2][1]*su3[1][1][0]
218 - su3[0][1][0]*su3[1][2][1] - su3[0][1][1]*su3[1][2][0];
219
220 su3[2][1][0] = su3[0][2][0]*su3[1][0][0] - su3[0][2][1]*su3[1][0][1]
221 - su3[0][0][0]*su3[1][2][0] + su3[0][0][1]*su3[1][2][1];
222 su3[2][1][1] = su3[0][0][0]*su3[1][2][1] + su3[0][0][1]*su3[1][2][0]
223 - su3[0][2][0]*su3[1][0][1] - su3[0][2][1]*su3[1][0][0];
224
225 su3[2][2][0] = su3[0][0][0]*su3[1][1][0] - su3[0][0][1]*su3[1][1][1]
226 - su3[0][1][0]*su3[1][0][0] + su3[0][1][1]*su3[1][0][1];
227 su3[2][2][1] = su3[0][1][0]*su3[1][0][1] + su3[0][1][1]*su3[1][0][0]
228 - su3[0][0][0]*su3[1][1][1] - su3[0][0][1]*su3[1][1][0];
229 }
230
231 /* Copy into the big array */
232 for(int kk=0; kk<Nc; kk++) /* color */
233 {
234 for(int ii=0; ii<Nc; ii++) /* color */
235 {
236 Real re = su3[ii][kk][0];
237 Real im = su3[ii][kk][1];
238 Complex sitecomp = cmplx(re,im);
239 pokeColor(sitefield,sitecomp,ii,kk);
240 }
241 }
242
243 pokeSite(u[dd], sitefield, coord);
244 }
245 }
246 delete [] su3_buffer;
247}
248
249
250
251//-----------------------------------------------------------------------
252// Write a QCD archive file
253// Write a QCD (NERSC) Archive format gauge field
254/*
255 * \ingroup io
256 *
257 * \param cfg_out binary writer object ( Modify )
258 * \param u gauge configuration ( Read )
259 */
260void writeArchiv(BinaryWriter& cfg_out, const multi1d<LatticeColorMatrix>& u,
261 int mat_size)
262{
263 ColorMatrix sitefield;
264 float su3[3][3][2];
265
266 // Find the location of each site and send to primary node
267 for(int site=0; site < Layout::vol(); ++site)
268 {
269 multi1d<int> coord = crtesn(site, Layout::lattSize());
270
271 for(int dd=0; dd<Nd; dd++) /* dir */
272 {
273 sitefield = peekSite(u[dd], coord);
274
275 if ( mat_size == 12 )
276 {
277 for(int kk=0; kk < Nc; kk++) /* color */
278 for(int ii=0; ii < Nc-1; ii++) /* color */
279 {
280 Complex sitecomp = peekColor(sitefield,ii,kk);
281 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
282 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
283 }
284 }
285 else
286 {
287 for(int kk=0; kk < Nc; kk++) /* color */
288 for(int ii=0; ii < Nc; ii++) /* color */
289 {
290 Complex sitecomp = peekColor(sitefield,ii,kk);
291 su3[ii][kk][0] = toFloat(Real(real(sitecomp)));
292 su3[ii][kk][1] = toFloat(Real(imag(sitecomp)));
293 }
294 }
295
296 // Write a site variable
297 cfg_out.writeArray((char *)&(su3[0][0][0]),sizeof(float), mat_size);
298 }
299 }
300
301 if (cfg_out.fail())
302 QDP_error_exit("Error writing configuration");
303}
304
305
306} // namespace QDP;
Binary input base class.
Definition qdp_io.h:372
virtual void readArray(char *output, size_t nbytes, size_t nmemb)
Read data on the primary node and broadcast to all nodes.
Definition qdp_io.cc:706
virtual bool fail()
Checks status of the previous IO operation.
Definition qdp_io.cc:524
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
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
void globalSumArray(unsigned int *dest, int len)
Wrapper to get a functional unsigned global sum.
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
void QDP_abort(int status)
Panic button.
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.