7#ifndef QDP_SCALARVEC_SPECIFIC_H
8#define QDP_SCALARVEC_SPECIFIC_H
53 inline void broadcast_str(std::string& dest) {}
56 inline void broadcast(
void* dest,
size_t nbytes) {}
59#define QDP_NOT_IMPLEMENTED
67template<
class T,
class T1,
class Op,
class RHS>
69void evaluate(OLattice<T>& dest,
const Op& op,
const QDPExpr<RHS,OScalar<T1> >& rhs,
74#if defined(QDP_USE_PROFILING)
75 static QDPProfile_t prof(dest, op, rhs);
79#if ! defined(QDP_NOT_IMPLEMENTED)
80 const int *tab = s.siteTable().slice();
81 for(
int j=0; j < s.numSiteTable(); ++j)
92#if defined(QDP_USE_PROFILING)
104template<
class T,
class T1,
class Op,
class RHS>
106void evaluate(OLattice<T>& dest,
const Op& op,
const QDPExpr<RHS,OLattice<T1> >& rhs,
111#if defined(QDP_USE_PROFILING)
112 static QDPProfile_t prof(dest, op, rhs);
116#if ! defined(QDP_NOT_IMPLEMENTED)
118 const int *tab = s.siteTable().slice();
119 for(
int j=0; j < s.numSiteTable(); ++j)
123 op(dest.elem(i),
forEach(rhs, EvalLeaf1(i), OpCombine()));
129#if defined(QDP_USE_PROFILING)
141template<
class T1,
class T2>
143copymask(OSubLattice<T2> d,
const OLattice<T1>& mask,
const OLattice<T2>& s1)
145 OLattice<T2>& dest = d.field();
146 const Subset& s = d.subset();
148#if ! defined(QDP_NOT_IMPLEMENTED)
149 const int *tab = s.siteTable().slice();
150 for(
int j=0; j < s.numSiteTable(); ++j)
153 copymask(dest.elem(i), mask.elem(i), s1.elem(i));
163template<
class T1,
class T2>
165copymask(OLattice<T2>& dest,
const OLattice<T1>& mask,
const OLattice<T2>& s1)
168 for(
int i=0; i < iend; ++i)
169 copymask(dest.elem(i), mask.elem(i), s1.elem(i));
203random(OLattice<T>& d,
const Subset& s)
208#if ! defined(QDP_NOT_IMPLEMENTED)
209#error "random(unorderedsubset) broken"
210 const int *tab = s.siteTable().slice();
211 for(
int j=0; j < s.numSiteTable(); ++j)
241void random(OLattice<T>& d)
249void gaussian(OLattice<T>& d,
const Subset& s)
256#if ! defined(QDP_NOT_IMPLEMENTED)
257 const int *tab = s.siteTable().slice();
258 for(
int j=0; j < s.numSiteTable(); ++j)
293void zero_rep(OLattice<T>& dest,
const Subset& s)
295#if ! defined(QDP_NOT_IMPLEMENTED)
296 const int *tab = s.siteTable().slice();
297 for(
int j=0; j < s.numSiteTable(); ++j)
325 for(
int i=0; i < iend; ++i)
338template<
class RHS,
class T>
339typename UnaryReturn<OScalar<T>, FnSum>::Type_t
340sum(
const QDPExpr<RHS,OScalar<T> >& s1,
const Subset& s)
342 typename UnaryReturn<OScalar<T>, FnSum>::Type_t d;
344#if defined(QDP_USE_PROFILING)
345 static QDPProfile_t prof(d, OpAssign(), FnSum(), s1);
351#if defined(QDP_USE_PROFILING)
366template<
class RHS,
class T>
367typename UnaryReturn<OScalar<T>, FnSum>::Type_t
368sum(
const QDPExpr<RHS,OScalar<T> >& s1)
370 typename UnaryReturn<OScalar<T>, FnSum>::Type_t d;
372#if defined(QDP_USE_PROFILING)
373 static QDPProfile_t prof(d, OpAssign(), FnSum(), s1);
379#if defined(QDP_USE_PROFILING)
400template<
class RHS,
class T>
401typename UnaryReturn<OLattice<T>, FnSum>::Type_t
402sum(
const QDPExpr<RHS,OLattice<T> >& s1,
const Subset& s)
404 typename UnaryReturn<OLattice<T>, FnSum>::Type_t d;
407#if defined(QDP_USE_PROFILING)
408 static QDPProfile_t prof(d, OpAssign(), FnSum(), s1);
415 if (s.hasOrderedRep())
417 const int istart = s.start() >>
INNER_LOG;
420 for(
int i=istart; i <= iend; ++i)
422 tmp.elem() =
forEach(s1, EvalLeaf1(i), OpCombine());
423 d.elem() +=
sum(tmp.elem());
428 const int *tab = s.siteTable().slice();
429 for(
int j=0; j < s.numSiteTable(); ++j)
433 int innersite = i & ((1 <<
INNER_LOG)-1);
435 tmp.elem() =
forEach(s1, EvalLeaf1(outersite), OpCombine());
436 d.elem() +=
getSite(tmp.elem(),innersite);
440#if defined(QDP_USE_PROFILING)
458template<
class RHS,
class T>
459typename UnaryReturn<OLattice<T>, FnSum>::Type_t
460sum(
const QDPExpr<RHS,OLattice<T> >& s1)
476template<
class RHS,
class T>
477multi1d<typename UnaryReturn<OScalar<T>, FnSum>::Type_t>
482#if defined(QDP_USE_PROFILING)
483 static QDPProfile_t prof(dest(0,0),
OpAssign(),
FnSum(), s1);
489 dest[i] =
sum(s1,ss[i]);
491#if defined(QDP_USE_PROFILING)
510template<
class RHS,
class T>
512sumMulti(
const QDPExpr<RHS,OLattice<T> >& s1,
const Set& ss)
516#if defined(QDP_USE_PROFILING)
517 static QDPProfile_t prof(dest[0],
OpAssign(), FnSum(), s1);
522 for(
int i=0; i < ss.numSubsets(); ++i)
523 dest[i] =
sum(s1,ss[i]);
525#if defined(QDP_USE_PROFILING)
546multi2d<typename UnaryReturn<OScalar<T>, FnSum>::Type_t>
547sumMulti(
const multi1d< OScalar<T> >& s1,
const Set& ss)
549 multi2d<typename UnaryReturn<OScalar<T>, FnSum>::Type_t> dest(s1.size(), ss.numSubsets());
551#if defined(QDP_USE_PROFILING)
552 static QDPProfile_t prof(dest(0,0), OpAssign(), FnSum(), s1);
557 for(
int i=0; i < dest.size1(); ++i)
558 for(
int j=0; j < dest.size2(); ++j)
561#if defined(QDP_USE_PROFILING)
581multi2d<typename UnaryReturn<OLattice<T>, FnSum>::Type_t>
582sumMulti(
const multi1d< OLattice<T> >& s1,
const Set& ss)
584 multi2d<typename UnaryReturn<OLattice<T>, FnSum>::Type_t> dest(s1.size(),ss.numSubsets());
586#if defined(QDP_USE_PROFILING)
587 static QDPProfile_t prof(dest(0,0), OpAssign(), FnSum(), s1);
592 for(
int k=0; k < s1.size(); ++k)
593 for(
int i=0; i < ss.numSubsets(); ++i)
594 dest(k,i) =
sum(s1[k],ss[i]);
596#if defined(QDP_USE_PROFILING)
615inline typename UnaryReturn<OScalar<T>, FnNorm2>::Type_t
616norm2(
const multi1d< OScalar<T> >& s1)
618 typename UnaryReturn<OScalar<T>, FnNorm2>::Type_t d;
620#if defined(QDP_USE_PROFILING)
621 static QDPProfile_t prof(d, OpAssign(), FnNorm2(), s1[0]);
628 for(
int n=0; n < s1.size(); ++n)
630 OScalar<T>& ss1 = s1[n];
634#if defined(QDP_USE_PROFILING)
646inline typename UnaryReturn<OScalar<T>, FnNorm2>::Type_t
647norm2(
const multi1d< OScalar<T> >& s1,
const Subset& s)
662inline typename UnaryReturn<OLattice<T>, FnNorm2>::Type_t
663norm2(
const multi1d< OLattice<T> >& s1,
const Subset& s)
665 typename UnaryReturn<OLattice<T>, FnNorm2>::Type_t d;
667#if defined(QDP_USE_PROFILING)
668 static QDPProfile_t prof(d, OpAssign(), FnNorm2(), s1[0]);
675#if ! defined(QDP_NOT_IMPLEMENTED)
676 const int *tab = s.siteTable().slice();
677 for(
int n=0; n < s1.size(); ++n)
679 const OLattice<T>& ss1 = s1[n];
680 for(
int j=0; j < s.numSiteTable(); ++j)
690#if defined(QDP_USE_PROFILING)
708inline typename UnaryReturn<OLattice<T>, FnNorm2>::Type_t
709norm2(
const multi1d< OLattice<T> >& s1)
728inline typename UnaryReturn<OScalar<T1>, FnPeekSite>::Type_t
741template<
class RHS,
class T1>
780template<
class RHS,
class T1>
799template<
class T1,
class T2>
868#if defined(QDP_USE_PROFILING)
870struct TagVisitor<FnMap, PrintTag> :
public ParenPrinter<FnMap>
872 static void visit(FnMap op, PrintTag t)
873 { t.os_m <<
"shift"; }
923 int i0 = goffsets[i+0] & (
INNER_LEN - 1);
926 int i1 = goffsets[i+1] & (
INNER_LEN - 1);
929 int i2 = goffsets[i+2] & (
INNER_LEN - 1);
932 int i3 = goffsets[i+3] & (
INNER_LEN - 1);
935 QDP_info(
"Map(lattice[%d]=lattice([%d,%d],[%d,%d],[%d,%d],[%d,%d])",
936 ii,o0,i0,o1,i1,o2,i2,o3,i3);
948#error "Map: this inner grid length is not supported - easy to fix"
966 template<
class RHS,
class T1>
979 template<
class RHS,
class T1>
1002 void operator=(
const Map&) {}
1009 multi1d<int> goffsets;
1046 QDP_info(
"ArrayMap(OLattice,%d)",dir);
1049 return mapsa[dir](l);
1057 QDP_info(
"ArrayMap(OScalar,%d)",dir);
1060 return mapsa[dir](l);
1064 template<
class RHS,
class T1>
1071 return mapsa[dir](l);
1074 template<
class RHS,
class T1>
1081 return mapsa[dir](l);
1090 void operator=(
const ArrayMap&) {}
1099class BiDirectionalMap
1130 QDP_info(
"BiDirectionalMap(OLattice,%d)",isign);
1133 return bimaps[(isign+1)>>1](l);
1142 QDP_info(
"BiDirectionalMap(OScalar,%d)",isign);
1145 return bimaps[(isign+1)>>1](l);
1149 template<
class RHS,
class T1>
1156 return bimaps[(isign+1)>>1](l);
1159 template<
class RHS,
class T1>
1166 return bimaps[(isign+1)>>1](l);
1175 void operator=(
const BiDirectionalMap&) {}
1178 multi1d<Map> bimaps;
1185class ArrayBiDirectionalMap
1224 QDP_info(
"ArrayBiDirectionalMap(OLattice,%d,%d)",isign,dir);
1227 return bimapsa((isign+1)>>1,dir)(l);
1235 QDP_info(
"ArrayBiDirectionalMap(OScalar,%d,%d)",isign,dir);
1238 return bimapsa((isign+1)>>1,dir)(l);
1242 template<
class RHS,
class T1>
1249 return bimapsa((isign+1)>>1,dir)(l);
1252 template<
class RHS,
class T1>
1259 return bimapsa((isign+1)>>1,dir)(l);
1268 void operator=(
const ArrayBiDirectionalMap&) {}
1271 multi2d<Map> bimapsa;
1280multi1d<int>
crtesn(
int ipos,
const multi1d<int>& latt_size);
1284XMLWriter&
operator<<(XMLWriter& xml,
const OLattice<T>& d)
1286 xml.openTag(
"OLattice");
1288 XMLWriterAPI::AttributeList alist;
1291 for(
int site=0; site < iend; ++site)
1294 std::ostringstream os;
1296 for(
int i=1; i < coord.size(); ++i)
1297 os <<
" " << coord[i];
1301 int innersite = i & ((1 <<
INNER_LOG)-1);
1304 alist.push_back(XMLWriterAPI::Attribute(
"site", site));
1305 alist.push_back(XMLWriterAPI::Attribute(
"coord", os.str()));
1307 xml.openTag(
"elem", alist);
1308 xml <<
getSite(d.elem(outersite),innersite);
1323void write(BinaryWriter& bin,
const OScalar<T>& d)
1325 bin.writeArray((
const char *)&(d.elem()),
1333void write(BinaryWriter& bin,
const OLattice<T>& d)
1336 for(
int site=0; site < iend; ++site)
1340 int innersite = i & ((1 <<
INNER_LOG)-1);
1343 Site_t this_site =
getSite(d.elem(outersite),innersite);
1345 bin.writeArray((
const char*)&this_site,
1354void write(BinaryWriter& bin,
const OLattice<T>& d,
const multi1d<int>& coord)
1358 int innersite = i & ((1 <<
INNER_LOG)-1);
1361 Site_t this_site =
getSite(d.elem(outersite),innersite);
1363 bin.writeArray((
const char*)&this_site,
1371void read(BinaryReader& bin, OScalar<T>& d)
1373 bin.readArray((
char*)&(d.elem()),
1381void read(BinaryReader& bin, OLattice<T>& d)
1384 for(
int site=0; site < iend; ++site)
1388 int innersite = i & ((1 <<
INNER_LOG)-1);
1393 bin.readArray((
char*)&this_site,
1397 copy_site(d.elem(outersite), innersite, this_site);
1404void read(BinaryReader& bin, OLattice<T>& d,
const multi1d<int>& coord)
1408 int innersite = i & ((1 <<
INNER_LOG)-1);
1413 bin.readArray((
char*)&this_site,
1417 copy_site(d.elem(outersite), innersite, this_site);
ForEach< Expr, FTag, CTag >::Type_t forEach(const Expr &e, const FTag &f, const CTag &c)
#define PETE_EMPTY_CONSTRUCTORS(CLASS)
ArrayBiDirectional of general permutation map class for communications.
~ArrayBiDirectionalMap()
Destructor.
OLattice< T1 > operator()(const OLattice< T1 > &l, int isign, int dir)
Function call operator for a shift.
void make(const ArrayMapFunc &func)
Actual constructor from a function object.
ArrayBiDirectionalMap(const ArrayMapFunc &fn)
Constructor from a function object.
ArrayBiDirectionalMap()
Constructor - does nothing really.
OScalar< T1 > operator()(const QDPExpr< RHS, OScalar< T1 > > &l, int isign, int dir)
OScalar< T1 > operator()(const OScalar< T1 > &l, int isign, int dir)
OLattice< T1 > operator()(const QDPExpr< RHS, OLattice< T1 > > &l, int isign, int dir)
Array of general permutation map class for communications.
OLattice< T1 > operator()(const OLattice< T1 > &l, int dir)
Function call operator for a shift.
ArrayMap()
Constructor - does nothing really.
OScalar< T1 > operator()(const OScalar< T1 > &l, int dir)
OLattice< T1 > operator()(const QDPExpr< RHS, OLattice< T1 > > &l, int dir)
ArrayMap(const ArrayMapFunc &fn)
Constructor from a function object.
OScalar< T1 > operator()(const QDPExpr< RHS, OScalar< T1 > > &l, int dir)
void make(const ArrayMapFunc &func)
Actual constructor from a function object.
BiDirectional of general permutation map class for communications.
OScalar< T1 > operator()(const QDPExpr< RHS, OScalar< T1 > > &l, int isign)
void make(const MapFunc &func)
Actual constructor from a function object.
OLattice< T1 > operator()(const QDPExpr< RHS, OLattice< T1 > > &l, int isign)
~BiDirectionalMap()
Destructor.
BiDirectionalMap(const MapFunc &fn)
Constructor from a function object.
OScalar< T1 > operator()(const OScalar< T1 > &l, int isign)
OLattice< T1 > operator()(const OLattice< T1 > &l, int isign)
Function call operator for a shift.
BiDirectionalMap()
Constructor - does nothing really.
General permutation map class for communications.
OLattice< T1 > operator()(const QDPExpr< RHS, OLattice< T1 > > &l)
Map(const MapFunc &fn)
Constructor from a function object.
OScalar< T1 > operator()(const QDPExpr< RHS, OScalar< T1 > > &l)
OScalar< T1 > operator()(const OScalar< T1 > &l)
const multi1d< int > & goffset() const
Accessor to offsets.
Map()
Constructor - does nothing really.
OLattice< T1 > operator()(const OLattice< T1 > &l)
Function call operator for a shift.
void make(const MapFunc &func)
Actual constructor from a function object.
Outer grid Scalar class */.
OLattice class narrowed to a subset.
const Subset & subset() const
Expression class for QDP.
OLattice< T1 > & pokeSite(OLattice< T1 > &l, const OScalar< T2 > &r, const multi1d< int > &coord)
Insert site element.
OScalar< T1 > peekSite(const QDPExpr< RHS, OScalar< T1 > > &l, const multi1d< int > &coord)
Extract site element.
UnaryReturn< OScalar< T1 >, FnPeekSite >::Type_t peekSite(const OScalar< T1 > &l, const multi1d< int > &coord)
Extract site element.
UnaryReturn< OLattice< T1 >, FnPeekSite >::Type_t peekSite(const OLattice< T1 > &l, const multi1d< int > &coord)
Extract site element.
OScalar< T1 > peekSite(const QDPExpr< RHS, OLattice< T1 > > &l, const multi1d< int > &coord)
Extract site element.
void QDP_extract(multi1d< OScalar< typename UnaryReturn< T, FnGetSite >::Type_t > > &dest, const OLattice< T > &src, const Subset &s)
Copy data values from field src to array dest.
void QDP_insert(OLattice< T > &dest, const multi1d< OScalar< typename UnaryReturn< T, FnGetSite >::Type_t > > &src, const Subset &s)
Inserts data values from site array src.
Set - collection of subsets controlling which sites are involved in an operation.
int numSubsets() const
Return number of subsets.
Subsets - controls how lattices are looped.
const multi1d< int > & siteTable() const
Container for a multi-dimensional 1D array.
const T * slice() const
Return ref to a column slice.
Container for a multi-dimensional 2D array.
OLattice< PScalar< PSeed< RScalar< INTEGER32 > > > > LatticeSeed
OScalar< PScalar< PSeed< RScalar< INTEGER32 > > > > Seed
OLattice< PScalar< PScalar< RScalar< INTEGER32 > > > > LatticeInteger
OScalar< T1 > peekSite(const OScalar< T1 > &l, const multi1d< int > &coord)
Extract site element.
UnaryReturn< C, FnNorm2 >::Type_t norm2(const QDPType< T, C > &s1)
OScalar = norm2(trace(adj(source)*source)).
UnaryReturn< C, FnSumMulti >::Type_t sumMulti(const QDPType< T, C > &s1, const Set &ss)
dest = sumMulti(source1,Set)
UnaryReturn< C, FnSum >::Type_t sum(const QDPType< T, C > &s1)
OScalar = sum(source).
void gather_sites(ILattice< T, 2 > &d, const ILattice< T1, 2 > &s0, int i0, const ILattice< T1, 2 > &s1, int i1)
gather several inner sites together
TextWriter & operator<<(TextWriter &txt, const std::string &output)
void write(BinaryWriter &bin, const std::string &output)
void read(BinaryReader &bin, std::string &input, size_t maxBytes)
void fill_gaussian(IScalar< T > &d, IScalar< T > &r1, IScalar< T > &r2)
dest = gaussian
void copy_site(IScalar< T > &d, int isite, const IScalar< T1 > &s1)
dest [some type] = source [some type]
void zero_rep(IScalar< T > &dest)
dest = 0
void copymask(IScalar< T > &d, const IScalar< T1 > &mask, const IScalar< T > &s1)
dest = (mask) ? s1 : dest
UnaryReturn< IScalar< T >, FnGetSite >::Type_t getSite(const IScalar< T > &s1, int innersite)
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)
void gaussian(OSubScalar< T > &d)
dest = gaussian
void random(OScalar< T > &d)
dest = random
Subset all
Default all subset.
Layout namespace holding info on problem size and machine info.
int linearSiteIndex(int site)
The linearized site index for the corresponding lexicographic site.
int sitesOnNode()
Subgrid lattice volume.
int outerSitesOnNode()
Subgrid lattice volume.
const multi1d< int > & lattSize()
Virtual grid (problem grid) lattice size.
LatticeInteger latticeCoordinate(int mu)
coord[mu] <- mu : fill with lattice coord in mu direction
int vol()
Total lattice volume.
void broadcast(T &dest)
Broadcast from primary node to all other nodes.
void globalSum(T &dest)
Sum across all nodes.
void globalSumArray(unsigned int *dest, int len)
Wrapper to get a functional unsigned global sum.
Seed ran_mult_n
RNG multiplier raised to the volume+1.
Seed ran_mult
RNG multiplier.
LatticeSeed * lattice_ran_mult
The lattice of skewed RNG multipliers.
Seed ran_seed
Global (current) seed.
Yet another random number generator.
ForEach< Expr, FTag, CTag >::Type_t forEach(const Expr &e, const FTag &f, const CTag &c)
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
QDPTime_t getClockTime()
Get the wallclock time.
multi1d< int > crtesn(int ipos, const multi1d< int > &latt_size)
Decompose a lexicographic site into coordinates.
void fill_random(float &d, T1 &seed, T2 &skewed_seed, const T1 &seed_mult)
dest = random
MakeReturn< UnaryNode< FnLocalNorm2, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnLocalNorm2 >::Type_t >::Expression_t localNorm2(const QDPExpr< T1, C1 > &l)
int QDP_info(const char *format,...)
Simple information display routine.