QDP++
qdp_scalarsite_generic_linalg.h
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: qdp_scalarsite_generic_linalg.h,v 1.10 2009-07-14 20:08:41 bjoo Exp $
9
10#ifndef QDP_SCALARSITE_GENERIC_LINALG_H
11#define QDP_SCALARSITE_GENERIC_LINALG_H
13namespace QDP {
14
18 *
19 * @{
20 */
22// Use this def just to safe some typing later on in the file
31// #include "scalarsite_generic/generic_adj_mat_vec.h" -- No longer used."
33
35// #define QDP_SCALARSITE_DEBUG
36
37// Optimized version of
38// PColorMatrix<RComplexFloat,3> <- PColorMatrix<RComplexFloat,3> * PColorMatrix<RComplexFloat,3>
39template<>
44{
47
48#if defined(QDP_SCALARSITE_DEBUG)
49 cout << "M*M" << endl;
50#endif
51
53
54 return d;
55}
56
57
58// Optimized version of
59// PScalar<PColorMatrix<RComplexFloat,3>> <- PScalar<PColorMatrix<RComplexFloat,3>> *
74 _inline_generic_mult_su3_nn(l.elem(),r.elem(),d.elem());
75
76 return d;
77}
78
80// Optimized version of
81// PColorMatrix<RComplexFloat,3> <- adj(PColorMatrix<RComplexFloat,3>) * PColorMatrix<RComplexFloat,3>
82template<>
87{
90
91#if defined(QDP_SCALARSITE_DEBUG)
92 cout << "adj(M)*M" << endl;
93#endif
94
96
97 return d;
98}
99
100
101// Optimized version of
102// PScalar<PColorMatrix<RComplexFloat,3>> <- adj(PScalar<PColorMatrix<RComplexFloat,3>>) * PScalar<PColorMatrix<RComplexFloat,3>>
103template<>
105 PScalar<PColorMatrix<RComplexFloat,3> >, OpAdjMultiply>::Type_t
108{
111
112#if defined(QDP_SCALARSITE_DEBUG)
113 cout << "adj(PSc<M>)*PSc<M>" << endl;
114#endif
115
116 _inline_generic_mult_su3_an(l.elem(),r.elem(),d.elem());
117
118 return d;
119}
120
121
122// Optimized version of
123// PColorMatrix<RComplexFloat,3> <- PColorMatrix<RComplexFloat,3> * adj(PColorMatrix<RComplexFloat,3>)
124template<>
126 PMatrix<RComplexFloat,3,PColorMatrix>, OpMultiplyAdj>::Type_t
129{
132
133#if defined(QDP_SCALARSITE_DEBUG)
134 cout << "M*adj(M)" << endl;
135#endif
136
138
139 return d;
140}
141
142
143// Optimized version of
144// PScalar<PColorMatrix<RComplexFloat,3>> <- PScalar<PColorMatrix<RComplexFloat,3>> * adj(PScalar<PColorMatrix<RComplexFloat,3>>)
145template<>
147 PScalar<PColorMatrix<RComplexFloat,3> >, OpMultiplyAdj>::Type_t
150{
153
154#if defined(QDP_SCALARSITE_DEBUG)
155 cout << "PSc<M>*adj(PSc<M>)" << endl;
156#endif
157
158 _inline_generic_mult_su3_na(l.elem(),r.elem(),d.elem());
159
160 return d;
161}
162
163
164#if 0
165// Do not use this routine - for some unknown reason on P4 it is slower than
166// the default code!!
167
168// Optimized version of
169// PColorMatrix<RComplexFloat,3> <- adj(PColorMatrix<RComplexFloat,3>) * adj(PColorMatrix<RComplexFloat,3>)
170template<>
172 PMatrix<RComplexFloat,3,PColorMatrix>, OpAdjMultiplyAdj>::Type_t
173adjMultiplyAdj(const PMatrix<RComplexFloat,3,PColorMatrix>& l,
174 const PMatrix<RComplexFloat,3,PColorMatrix>& r)
175{
177 PMatrix<RComplexFloat,3,PColorMatrix>, OpAdjMultiplyAdj>::Type_t d;
178
179#if defined(QDP_SCALARSITE_DEBUG)
180 cout << "adj(PSc<M>)*adj(PSc<M>)" << endl;
181#endif
182
184
185 return d;
186}
187#endif
188
189
190// Optimized version of
191// PColorVector<RComplexFloat,3> <- PColorMatrix<RComplexFloat,3> * PColorVector<RComplexFloat,3>
192template<>
197{
200
201#if defined(QDP_SCALARSITE_DEBUG)
202 cout << "M*V" << endl;
203#endif
204
206
207 return d;
208}
209
210
211// Optimized version of
212// PScalar<PColorVector<RComplexFloat,3>> <- PScalar<PColorMatrix<RComplexFloat,3>> * PScalar<PColorVector<RComplexFloat,3>>
213template<>
215 PScalar<PColorVector<RComplexFloat,3> >, OpMultiply>::Type_t
218{
221
222#if defined(QDP_SCALARSITE_DEBUG)
223 cout << "PSc<M>*PSc<V>" << endl;
224#endif
225
226 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(),d.elem());
227
228 return d;
229}
230
231
232// Optimized version of
233// PColorVector<RComplexFloat,3> <- adj(PColorMatrix<RComplexFloat,3>) * PColorVector<RComplexFloat,3>
234template<>
236 PVector<RComplexFloat,3,PColorVector>, OpAdjMultiply>::Type_t
239{
242
243#if defined(QDP_SCALARSITE_DEBUG)
244 cout << "adj(M)*V" << endl;
245#endif
246
248
249 return d;
250}
251
252
253// Optimized version of StaggeredFermion <- ColorMatrix*StaggeredFermion
254// PSpinVector<PColorVector<RComplexFloat,3>,1> <- PScalar<PColorMatrix<RComplexFloat,3>> * PSpinVector<PColorVector<RComplexFloat,3>,1>
255template<>
257 PVector<PColorVector<RComplexFloat,3>,1,PSpinVector>, OpMultiply>::Type_t
260{
263
264#if defined(QDP_SCALARSITE_DEBUG)
265 cout << "PSc<M>*S" << endl;
266#endif
267
268 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(0),d.elem(0));
269
270 return d;
271}
272
273
274// Optimized version of
275// PScalar<PColorVector<RComplexFloat,3>> <- adj(PScalar<PColorMatrix<RComplexFloat,3>>) * PScalar<PColorVector<RComplexFloat,3>>
276template<>
278 PScalar<PColorVector<RComplexFloat,3> >, OpAdjMultiply>::Type_t
281{
284
285#if defined(QDP_SCALARSITE_DEBUG)
286 cout << "adj(PSc<M>)*PSc<V>" << endl;
287#endif
288
289 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(),d.elem());
290
291 return d;
292}
293
294
295// Optimized version of StaggeredFermion <- adj(ColorMatrix)*StaggeredFermion
296// PSpinVector<PColorVector<RComplexFloat,3>,1> <- adj(PScalar<PColorMatrix<RComplexFloat,3>>) * PSpinVector<PColorVector<RComplexFloat,3>,1>
297template<>
299 PVector<PColorVector<RComplexFloat,3>,1,PSpinVector>, OpAdjMultiply>::Type_t
302{
305
306#if defined(QDP_SCALARSITE_DEBUG)
307 cout << "adj(PSc<M>)*S" << endl;
308#endif
309
310 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(0),d.elem(0));
311
312 return d;
313}
314
315
316// Optimized version of HalfFermion <- ColorMatrix*HalfFermion
317// PSpinVector<PColorVector<RComplexFloat,3>,2> <- PScalar<PColorMatrix<RComplexFloat,3>> *
318// PSpinVector<ColorVector<RComplexFloat,3>,2>
319template<>
321 PVector<PColorVector<RComplexFloat,3>,2,PSpinVector>, OpMultiply>::Type_t
324{
327
328#if defined(QDP_SCALARSITE_DEBUG)
329 cout << "PSc<M>*H" << endl;
330#endif
331
332 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(0),d.elem(0));
333 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(1),d.elem(1));
334
335 return d;
336}
337
338
339// Optimized version of HalfFermion <- ColorMatrix*HalfFermion
340// PSpinVector<PColorVector<RComplexFloat,3>,2> <- adj(PScalar<PColorMatrix<RComplexFloat,3>>) *
341// PSpinVector<ColorVector<RComplexFloat,3>,2>
342template<>
344 PVector<PColorVector<RComplexFloat,3>,2,PSpinVector>, OpAdjMultiply>::Type_t
347{
350
351#if defined(QDP_SCALARSITE_DEBUG)
352 cout << "adj(PSc<M>)*H" << endl;
353#endif
354
355 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(0),d.elem(0));
356 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(1),d.elem(1));
357
358 return d;
359}
360
361
362// Optimized version of
363// PColorVector<RComplexFloat,3> <- PColorVector<RComplexFloat,3> + PColorVector<RComplexFloat,3>
364template<>
366 PVector<RComplexFloat,3,PColorVector>, OpAdd>::Type_t
369{
372
373#if defined(QDP_SCALARSITE_DEBUG)
374 cout << "V+V" << endl;
375#endif
376
378
379 return d;
380}
381
382
383// Optimized version of DiracFermion <- ColorMatrix*DiracFermion
384// PSpinVector<PColorVector<RComplexFloat,3>,4> <- PScalar<PColorMatrix<RComplexFloat,3>>
385// * PSpinVector<PColorVector<RComplexFloat,3>,4>
386template<>
388 PVector<PColorVector<RComplexFloat,3>,4,PSpinVector>, OpMultiply>::Type_t
391{
394
395#if defined(QDP_SCALARSITE_DEBUG)
396 cout << "PSc<M>*D" << endl;
397#endif
398
399 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(0),d.elem(0));
400 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(1),d.elem(1));
401 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(2),d.elem(2));
402 _inline_generic_mult_su3_mat_vec(l.elem(),r.elem(3),d.elem(3));
403
404 return d;
405}
406
407
408// Optimized version of DiracFermion <- adj(ColorMatrix)*DiracFermion
409// PSpinVector<PColorVector<RComplexFloat,3>,4> <- adj(PScalar<PColorMatrix<RComplexFloat,3>>)
410// * PSpinVector<PColorVector<RComplexFloat,3>,4>
411template<>
413 PVector<PColorVector<RComplexFloat,3>,4,PSpinVector>, OpAdjMultiply>::Type_t
416{
419
420#if defined(QDP_SCALARSITE_DEBUG)
421 cout << "adj(PSc<M>)*D" << endl;
422#endif
423
424 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(0),d.elem(0));
425 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(1),d.elem(1));
426 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(2),d.elem(2));
427 _inline_generic_mult_adj_su3_mat_vec(l.elem(),r.elem(3),d.elem(3));
428
429 return d;
430}
431
432
433
434// Optimized version of
435// PScalar<PColorVector<RComplexFloat,3>> <- PScalar<PColorVector<RComplexFloat,3>>
436// + PScalar<PColorVector<RComplexFloat,3>>
437template<>
439 PScalar<PColorVector<RComplexFloat,3> >, OpAdd>::Type_t
442{
445
446#if defined(QDP_SCALARSITE_DEBUG)
447 cout << "PSc<V>+PSc<V>" << endl;
448#endif
449
450 _inline_generic_add_su3_vector(l.elem(),r.elem(),d.elem());
451
452 return d;
453}
454
455
456#if 1
457
459// Threading evaluates
460//
461// by Xu Guo, EPCC, 07 August, 2008
463
464// the wrappers for the function to be threaded
466
467// Specialization to optimize the case
468// LatticeHalfFermion = LatticeColorMatrix * LatticeHalfFermion
469// NOTE: let this be a subroutine to save space
470template<>
471inline
473 const OpAssign& op,
480 const Subset& s)
481{
482#if defined(QDP_SCALARSITE_DEBUG)
483 cout << "specialized QDP_H_M_times_H" << endl;
484#endif
485
487 // Original code
489 //typedef OLattice<PScalar<PColorMatrix<RComplexFloat, 3> > > C;
490 //typedef OLattice<PSpinVector<PColorVector<RComplexFloat, 3>, 2> > H;
491
492 const C& l = static_cast<const C&>(rhs.expression().left());
493 const H& r = static_cast<const H&>(rhs.expression().right());
494
495 if( s.hasOrderedRep() ) {
496
497 int totalSize = s.end() - s.start() + 1;
498
499 int base = s.start();
500
501 ordered_linalg_user_arg a(d, l, r, base);
502
504
506 // Original code
508 // Ordered Way - loop through sites and save a table lookup
509 //for(int i=s.start(); i <= s.end(); i++) {
510
511 //_inline_generic_mult_su3_mat_vec(l.elem(i).elem(),
512 // r.elem(i).elem(0),
513 // d.elem(i).elem(0));
514 //_inline_generic_mult_su3_mat_vec(l.elem(i).elem(),
515 // r.elem(i).elem(1),
516 // d.elem(i).elem(1));
517 //}
518
519 }
520 else {
521
522 int totalSize = s.numSiteTable();
523
524 const int *tab = s.siteTable().slice();
525
526 unordered_linalg_user_arg arg(d, l, r, tab);
527
529
531 // Original code
533 // Unordered Way - do a site table lookup
534 //for(int j=0; j < s.numSiteTable(); j++) {
535 //int i = tab[j];
536
537 //_inline_generic_mult_su3_mat_vec(l.elem(i).elem(),
538 // r.elem(i).elem(0),
539 // d.elem(i).elem(0));
540 //_inline_generic_mult_su3_mat_vec(l.elem(i).elem(),
541 // r.elem(i).elem(1),
542 // d.elem(i).elem(1));
543 //}
544 }
545}
546
547#endif
548 // end of group optimizations
550
551#if defined(QDP_SCALARSITE_DEBUG)
552#undef QDP_SCALARSITE_DEBUG
553#endif
554
555} // namespace QDP;
556
557#endif
Outer grid Lattice type.
Definition qdp_outer.h:264
Primitive color Matrix class.
Primitive color Vector class.
Primitive Matrix class.
Primitive Scalar.
Primitive spin Vector class.
Primitive Vector class.
Expression class for QDP.
Definition qdp_qdpexpr.h:16
QDPType - major type class/container for all QDP objects.
Definition qdp_qdptype.h:29
Reality complex.
Subsets - controls how lattices are looped.
Definition qdp_subset.h:39
int end() const
Definition qdp_subset.h:81
const multi1d< int > & siteTable() const
Definition qdp_subset.h:83
int numSiteTable() const
Definition qdp_subset.h:84
bool hasOrderedRep() const
Definition qdp_subset.h:79
int start() const
Definition qdp_subset.h:80
const T * slice() const
Return ref to a column slice.
Definition qdp_multi.h:225
BinaryReturn< IScalar< T1 >, IScalar< T2 >, OpAdjMultiplyAdj >::Type_t adjMultiplyAdj(const IScalar< T1 > &l, const IScalar< T2 > &r)
Definition qdp_inner.h:1198
BinaryReturn< IScalar< T1 >, IScalar< T2 >, OpMultiplyAdj >::Type_t multiplyAdj(const IScalar< T1 > &l, const IScalar< T2 > &r)
Definition qdp_inner.h:1189
BinaryReturn< IScalar< T1 >, IScalar< T2 >, OpAdjMultiply >::Type_t adjMultiply(const IScalar< T1 > &l, const IScalar< T2 > &r)
Definition qdp_inner.h:1180
OLattice< PSpinVector< PColorVector< RComplexFloat, 3 >, 2 > > H
void ordered_linalg_evaluate_userfunc(int lo, int hi, int myId, ordered_linalg_user_arg *a)
user function for the evaluate function in the ordered situation
void evaluate(OLattice< DCol > &d, const OpAssign &op, const QDPExpr< BinaryNode< OpMultiply, Reference< QDPType< DCol, OLattice< DCol > > >, Reference< QDPType< DCol, OLattice< DCol > > > >, OLattice< DCol > > &rhs, const Subset &s)
OLattice< PScalar< PColorMatrix< RComplexFloat, 3 > > > C
RComplex< BAGELQDPFloat > RComplexFloat
void unordered_linalg_evaluate_userfunc(int lo, int hi, int myId, unordered_linalg_user_arg *a)
user function for the evaluate function in the unordered situation
Yet another random number generator.
void dispatch_to_threads(int numSiteTable, Arg a, void(*func)(int, int, int, Arg *))
MakeReturn< BinaryNode< OpMultiply, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, OpMultiply >::Type_t >::Expression_t operator*(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2588
MakeReturn< BinaryNode< OpAdd, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, OpAdd >::Type_t >::Expression_t operator+(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2556
#define _inline_generic_mult_adj_su3_mat_vec(aa, bb, cc)
#define _inline_generic_mult_su3_an(aa, bb, cc)
#define _inline_generic_mult_su3_aa(aa, bb, cc)
#define _inline_generic_mult_su3_na(aa, bb, cc)
#define _inline_generic_add_su3_vector(aa, bb, cc)
#define _inline_generic_mult_su3_nn(aa, bb, cc)
#define _inline_generic_mult_su3_mat_vec(aa, bb, cc)
user argument for the evaluate function in the ordered situation
user argument for the evaluate function in the unordered situation
OLattice< PSpinVector< PColorVector< RComplexFloat, 3 >, 2 > > & d