2015-04-18 20:44:19 +01:00
|
|
|
#ifndef GRID_LATTICE_ARITH_H
|
|
|
|
#define GRID_LATTICE_ARITH_H
|
|
|
|
|
|
|
|
namespace Grid {
|
|
|
|
|
2015-05-03 09:44:47 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// avoid copy back routines for mult, mac, sub, add
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void mult(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const Lattice<obj3> &rhs){
|
|
|
|
conformable(lhs,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
mult(&tmp,&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
mult(&ret._odata[ss],&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-18 20:44:19 +01:00
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void mac(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const Lattice<obj3> &rhs){
|
|
|
|
conformable(lhs,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
mac(&tmp,&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
mac(&ret._odata[ss],&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void sub(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const Lattice<obj3> &rhs){
|
2015-04-18 20:44:19 +01:00
|
|
|
conformable(lhs,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
sub(&tmp,&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
sub(&ret._odata[ss],&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void add(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const Lattice<obj3> &rhs){
|
2015-04-18 20:44:19 +01:00
|
|
|
conformable(lhs,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
add(&tmp,&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
add(&ret._odata[ss],&lhs._odata[ss],&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 09:44:47 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// avoid copy back routines for mult, mac, sub, add
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void mult(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const obj3 &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(lhs,ret);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
obj1 tmp;
|
|
|
|
mult(&tmp,&lhs._odata[ss],&rhs);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-18 20:44:19 +01:00
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void mac(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const obj3 &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(lhs,ret);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
obj1 tmp;
|
|
|
|
mac(&tmp,&lhs._odata[ss],&rhs);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void sub(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const obj3 &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(lhs,ret);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-03 09:44:47 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
sub(&tmp,&lhs._odata[ss],&rhs);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
sub(&ret._odata[ss],&lhs._odata[ss],&rhs);
|
|
|
|
#endif
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void add(Lattice<obj1> &ret,const Lattice<obj2> &lhs,const obj3 &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(lhs,ret);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-03 09:44:47 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
add(&tmp,&lhs._odata[ss],&rhs);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
add(&ret._odata[ss],&lhs._odata[ss],&rhs);
|
|
|
|
#endif
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// avoid copy back routines for mult, mac, sub, add
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void mult(Lattice<obj1> &ret,const obj2 &lhs,const Lattice<obj3> &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(ret,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
mult(&tmp,&lhs,&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
mult(&ret._odata[ss],&lhs,&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void mac(Lattice<obj1> &ret,const obj2 &lhs,const Lattice<obj3> &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(ret,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
mac(&tmp,&lhs,&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
mac(&ret._odata[ss],&lhs,&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void sub(Lattice<obj1> &ret,const obj2 &lhs,const Lattice<obj3> &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(ret,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
sub(&tmp,&lhs,&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
sub(&ret._odata[ss],&lhs,&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class obj1,class obj2,class obj3> strong_inline
|
2015-05-03 09:44:47 +01:00
|
|
|
void add(Lattice<obj1> &ret,const obj2 &lhs,const Lattice<obj3> &rhs){
|
2015-05-05 18:14:09 +01:00
|
|
|
conformable(ret,rhs);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-05 18:14:09 +01:00
|
|
|
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-05 18:14:09 +01:00
|
|
|
obj1 tmp;
|
|
|
|
add(&tmp,&lhs,&rhs._odata[ss]);
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
add(&ret._odata[ss],&lhs,&rhs._odata[ss]);
|
|
|
|
#endif
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 04:33:10 +01:00
|
|
|
template<class sobj,class vobj> strong_inline
|
2015-05-19 13:57:35 +01:00
|
|
|
void axpy(Lattice<vobj> &ret,sobj a,const Lattice<vobj> &x,const Lattice<vobj> &y){
|
|
|
|
conformable(x,y);
|
2015-05-23 09:32:37 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-19 13:57:35 +01:00
|
|
|
for(int ss=0;ss<x._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-19 13:57:35 +01:00
|
|
|
vobj tmp = a*x._odata[ss]+y._odata[ss];
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
ret._odata[ss]=a*x._odata[ss]+y._odata[ss];
|
|
|
|
#endif
|
2015-05-19 13:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
template<class sobj,class vobj> strong_inline
|
|
|
|
void axpby(Lattice<vobj> &ret,sobj a,sobj b,const Lattice<vobj> &x,const Lattice<vobj> &y){
|
|
|
|
conformable(x,y);
|
2015-05-23 09:32:37 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-05-19 13:57:35 +01:00
|
|
|
for(int ss=0;ss<x._grid->oSites();ss++){
|
2015-05-21 06:39:00 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2015-05-19 13:57:35 +01:00
|
|
|
vobj tmp = a*x._odata[ss]+b*y._odata[ss];
|
|
|
|
vstream(ret._odata[ss],tmp);
|
2015-05-21 06:39:00 +01:00
|
|
|
#else
|
|
|
|
ret._odata[ss]=a*x._odata[ss]+b*y._odata[ss];
|
|
|
|
#endif
|
2015-05-19 13:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class sobj,class vobj> strong_inline
|
|
|
|
RealD axpy_norm(Lattice<vobj> &ret,sobj a,const Lattice<vobj> &x,const Lattice<vobj> &y){
|
|
|
|
conformable(x,y);
|
2015-05-21 06:39:00 +01:00
|
|
|
axpy(ret,a,x,y);
|
2015-05-19 13:57:35 +01:00
|
|
|
return norm2(ret);
|
|
|
|
}
|
|
|
|
template<class sobj,class vobj> strong_inline
|
|
|
|
RealD axpby_norm(Lattice<vobj> &ret,sobj a,sobj b,const Lattice<vobj> &x,const Lattice<vobj> &y){
|
|
|
|
conformable(x,y);
|
2015-05-21 06:39:00 +01:00
|
|
|
axpby(ret,a,b,x,y);
|
2015-05-19 13:57:35 +01:00
|
|
|
return norm2(ret); // FIXME implement parallel norm in ss loop
|
2015-05-03 09:44:47 +01:00
|
|
|
}
|
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
#endif
|