diff --git a/lib/lattice/Grid_lattice_overload.h b/lib/lattice/Grid_lattice_overload.h new file mode 100644 index 00000000..512e45d1 --- /dev/null +++ b/lib/lattice/Grid_lattice_overload.h @@ -0,0 +1,120 @@ +#ifndef GRID_LATTICE_OVERLOAD_H +#define GRID_LATTICE_OVERLOAD_H + +namespace Grid { + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + // unary negation + ////////////////////////////////////////////////////////////////////////////////////////////////////// + template + inline Lattice operator -(const Lattice &r) + { + Lattice ret(r._grid); +#pragma omp parallel for + for(int ss=0;ssoSites();ss++){ + vstream(ret._odata[ss], -r._odata[ss]); + } + return ret; + } + ///////////////////////////////////////////////////////////////////////////////////// + // Lattice BinOp Lattice, + //NB mult performs conformable check. Do not reapply here for performance. + ///////////////////////////////////////////////////////////////////////////////////// + template + inline auto operator * (const Lattice &lhs,const Lattice &rhs)-> Lattice + { + Lattice ret(rhs._grid); + mult(ret,lhs,rhs); + return ret; + } + template + inline auto operator + (const Lattice &lhs,const Lattice &rhs)-> Lattice + { + Lattice ret(rhs._grid); + add(ret,lhs,rhs); + return ret; + } + template + inline auto operator - (const Lattice &lhs,const Lattice &rhs)-> Lattice + { + Lattice ret(rhs._grid); + sub(ret,lhs,rhs); + return ret; + } + + // Scalar BinOp Lattice ;generate return type + template + inline auto operator * (const left &lhs,const Lattice &rhs) -> Lattice + { + Lattice ret(rhs._grid); +#pragma omp parallel for + for(int ss=0;ssoSites(); ss++){ + decltype(lhs*rhs._odata[0]) tmp=lhs*rhs._odata[ss]; + vstream(ret._odata[ss],tmp); + // ret._odata[ss]=lhs*rhs._odata[ss]; + } + return ret; + } + template + inline auto operator + (const left &lhs,const Lattice &rhs) -> Lattice + { + Lattice ret(rhs._grid); +#pragma omp parallel for + for(int ss=0;ssoSites(); ss++){ + decltype(lhs+rhs._odata[0]) tmp =lhs-rhs._odata[ss]; + vstream(ret._odata[ss],tmp); + // ret._odata[ss]=lhs+rhs._odata[ss]; + } + return ret; + } + template + inline auto operator - (const left &lhs,const Lattice &rhs) -> Lattice + { + Lattice ret(rhs._grid); +#pragma omp parallel for + for(int ss=0;ssoSites(); ss++){ + decltype(lhs-rhs._odata[0]) tmp=lhs-rhs._odata[ss]; + vstream(ret._odata[ss],tmp); + // ret._odata[ss]=lhs-rhs._odata[ss]; + } + return ret; + } + template + inline auto operator * (const Lattice &lhs,const right &rhs) -> Lattice + { + Lattice ret(lhs._grid); +#pragma omp parallel for + for(int ss=0;ssoSites(); ss++){ + decltype(lhs._odata[0]*rhs) tmp =lhs._odata[ss]*rhs; + vstream(ret._odata[ss],tmp); + // ret._odata[ss]=lhs._odata[ss]*rhs; + } + return ret; + } + template + inline auto operator + (const Lattice &lhs,const right &rhs) -> Lattice + { + Lattice ret(lhs._grid); +#pragma omp parallel for + for(int ss=0;ssoSites(); ss++){ + decltype(lhs._odata[0]+rhs) tmp=lhs._odata[ss]+rhs; + vstream(ret._odata[ss],tmp); + // ret._odata[ss]=lhs._odata[ss]+rhs; + } + return ret; + } + template + inline auto operator - (const Lattice &lhs,const right &rhs) -> Lattice + { + Lattice ret(lhs._grid); +#pragma omp parallel for + for(int ss=0;ssoSites(); ss++){ + decltype(lhs._odata[0]-rhs) tmp=lhs._odata[ss]-rhs; + vstream(ret._odata[ss],tmp); + // ret._odata[ss]=lhs._odata[ss]-rhs; + } + return ret; + } + + +}