1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 01:05:38 +01:00

Debugged the copy constructor of the Lattice class

This commit is contained in:
Guido Cossu 2016-07-06 15:31:00 +01:00
parent e3d5319470
commit e87182cf98
4 changed files with 888 additions and 849 deletions

View File

@ -24,7 +24,8 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
See the full license in the file "LICENSE" in the top level distribution directory
See the full license in the file "LICENSE" in the top level distribution
directory
*************************************************************************************/
/* END LEGAL */
#ifndef GRID_LATTICE_BASE_H
@ -255,6 +256,18 @@ PARALLEL_FOR_LOOP
checkerboard=0;
}
Lattice(const Lattice& r){ // copy constructor
_grid = r._grid;
checkerboard = r.checkerboard;
_odata.resize(_grid->oSites());// essential
PARALLEL_FOR_LOOP
for(int ss=0;ss<_grid->oSites();ss++){
_odata[ss]=r._odata[ss];
}
}
virtual ~Lattice(void) = default;
template<class sobj> strong_inline Lattice<vobj> & operator = (const sobj & r){
@ -267,7 +280,7 @@ PARALLEL_FOR_LOOP
template<class robj> strong_inline Lattice<vobj> & operator = (const Lattice<robj> & r){
this->checkerboard = r.checkerboard;
conformable(*this,r);
std::cout<<GridLogMessage<<"Lattice operator ="<<std::endl;
PARALLEL_FOR_LOOP
for(int ss=0;ss<_grid->oSites();ss++){
this->_odata[ss]=r._odata[ss];

View File

@ -38,10 +38,12 @@
// check the pointer is not null
if (ThinLinks == NULL)
std::cout << GridLogError << "[SmearedConfiguration] Error in ThinLinks pointer\n";
std::cout << GridLogError
<< "[SmearedConfiguration] Error in ThinLinks pointer\n";
if (smearingLevels > 0) {
std::cout<< GridLogDebug << "[SmearedConfiguration] Filling SmearedSet\n";
std::cout << GridLogDebug
<< "[SmearedConfiguration] Filling SmearedSet\n";
GaugeField previous_u(ThinLinks->_grid);
previous_u = *ThinLinks;
@ -51,10 +53,9 @@
// For debug purposes
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(previous_u);
std::cout<< GridLogDebug << "[SmearedConfiguration] Plaq: " << impl_plaq<< std::endl;
std::cout << GridLogDebug
<< "[SmearedConfiguration] Plaq: " << impl_plaq << std::endl;
}
}
}
//====================================================================
@ -80,23 +81,19 @@ GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime,
pokeLorentz(SigmaK, SigmaKPrime_mu * e_iQ + adj(Cmu) * iLambda_mu, mu);
pokeLorentz(iLambda, iLambda_mu, mu);
}
StoutSmearing.derivative(SigmaK, iLambda, GaugeK);// derivative of SmearBase
StoutSmearing.derivative(SigmaK, iLambda,
GaugeK); // derivative of SmearBase
return SigmaK;
}
/*! @brief Returns smeared configuration at level 'Level' */
const GaugeField& get_smeared_conf(int Level) const {
return SmearedSet[Level];
}
//====================================================================
void set_iLambda(GaugeLinkField& iLambda,
GaugeLinkField& e_iQ,
const GaugeLinkField& iQ,
const GaugeLinkField& Sigmap,
void set_iLambda(GaugeLinkField& iLambda, GaugeLinkField& e_iQ,
const GaugeLinkField& iQ, const GaugeLinkField& Sigmap,
const GaugeLinkField& GaugeK) const {
GridBase* grid = iQ._grid;
GaugeLinkField iQ2(grid), iQ3(grid), B1(grid), B2(grid), USigmap(grid);
@ -110,7 +107,8 @@ void set_iLambda(GaugeLinkField& iLambda,
LatticeComplex emiu(grid), e2iu(grid), qt(grid), fden(grid);
LatticeComplex r01(grid), r11(grid), r21(grid), r02(grid), r12(grid);
LatticeComplex r22(grid), tr1(grid), tr2(grid);
LatticeComplex b10(grid), b11(grid), b12(grid), b20(grid), b21(grid), b22(grid);
LatticeComplex b10(grid), b11(grid), b12(grid), b20(grid), b21(grid),
b22(grid);
LatticeComplex LatticeUnitComplex(grid);
LatticeUnitComplex = 1.0;
@ -133,19 +131,19 @@ void set_iLambda(GaugeLinkField& iLambda,
emiu = cos(u) - timesI(sin(u));
e2iu = cos(2.0 * u) + timesI(sin(2.0 * u));
r01 = (2.0*u + timesI(2.0*(u2-w2))) * e2iu
+ emiu * ((16.0*u*cosw + 2.0*u*(3.0*u2+w2)*xi0) +
r01 = (2.0 * u + timesI(2.0 * (u2 - w2))) * e2iu +
emiu * ((16.0 * u * cosw + 2.0 * u * (3.0 * u2 + w2) * xi0) +
timesI(-8.0 * u2 * cosw + 2.0 * (9.0 * u2 + w2) * xi0));
r11 = (2.0*LatticeUnitComplex + timesI(4.0*u))* e2iu
+ emiu * ((-2.0*cosw + (3.0*u2-w2)*xi0) +
r11 = (2.0 * LatticeUnitComplex + timesI(4.0 * u)) * e2iu +
emiu * ((-2.0 * cosw + (3.0 * u2 - w2) * xi0) +
timesI((2.0 * u * cosw + 6.0 * u * xi0)));
r21 = 2.0*timesI(e2iu)
+ emiu * (-3.0*u*xi0 + timesI(cosw - 3.0*xi0));
r21 =
2.0 * timesI(e2iu) + emiu * (-3.0 * u * xi0 + timesI(cosw - 3.0 * xi0));
r02 = -2.0 * e2iu + emiu * (-8.0*u2*xi0 +
r02 = -2.0 * e2iu +
emiu * (-8.0 * u2 * xi0 +
timesI(2.0 * u * (cosw + xi0 + 3.0 * u2 * xi1)));
r12 = emiu * (2.0 * u * xi0 + timesI(-cosw - xi0 + 3.0 * u2 * xi1));
@ -169,7 +167,6 @@ void set_iLambda(GaugeLinkField& iLambda,
b21 *= fden;
b22 *= fden;
B1 = b10 * unity + timesMinusI(b11) * iQ - b12 * iQ2;
B2 = b20 * unity + timesMinusI(b21) * iQ - b22 * iQ2;
USigmap = GaugeK * Sigmap;
@ -184,47 +181,39 @@ void set_iLambda(GaugeLinkField& iLambda,
timesI(f1) * USigmap + f2 * QUS + f2 * USQ;
iLambda = Ta(iGamma);
}
//====================================================================
public:
GaugeField* ThinLinks; /*!< @brief Pointer to the thin
GaugeField*
ThinLinks; /*!< @brief Pointer to the thin
links configuration */
/*! @brief Standard constructor */
SmearedConfiguration(GridCartesian * UGrid,
unsigned int Nsmear,
Smear_Stout<Gimpl>& Stout):
smearingLevels(Nsmear),
StoutSmearing(Stout),
ThinLinks(NULL){
SmearedConfiguration(GridCartesian* UGrid, unsigned int Nsmear,
Smear_Stout<Gimpl>& Stout)
: smearingLevels(Nsmear), StoutSmearing(Stout), ThinLinks(NULL) {
for (unsigned int i = 0; i < smearingLevels; ++i)
SmearedSet.push_back(*(new GaugeField(UGrid)));
}
/*! For just thin links */
SmearedConfiguration():
smearingLevels(0),
StoutSmearing(),
SmearedSet(),
ThinLinks(NULL){}
SmearedConfiguration()
: smearingLevels(0), StoutSmearing(), SmearedSet(), ThinLinks(NULL) {}
// attach the smeared routines to the thin links U and fill the smeared set
void set_GaugeField(GaugeField& U) { fill_smearedSet(U); }
//====================================================================
void smeared_force(GaugeField& SigmaTilde) const {
if (smearingLevels > 0) {
GaugeField force(SigmaTilde._grid);
GaugeField force = SigmaTilde; // actually = U*SigmaTilde
GaugeLinkField tmp_mu(SigmaTilde._grid);
force = SigmaTilde;//actually = U*SigmaTilde
for (int mu = 0; mu < Nd; mu++) {
// to get just SigmaTilde
tmp_mu = adj(peekLorentz(SmearedSet[smearingLevels-1], mu)) * peekLorentz(force,mu);
tmp_mu = adj(peekLorentz(SmearedSet[smearingLevels - 1], mu)) *
peekLorentz(force, mu);
pokeLorentz(force, tmp_mu, mu);
}
@ -241,42 +230,33 @@ public:
}
//====================================================================
GaugeField& get_SmearedU(){
return SmearedSet[smearingLevels-1];
}
GaugeField& get_SmearedU() { return SmearedSet[smearingLevels - 1]; }
GaugeField& get_U(bool smeared = false) {
// get the config, thin links by default
if (smeared) {
if (smearingLevels) {
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(SmearedSet[smearingLevels-1]);
std::cout<< GridLogDebug << "getting Usmr Plaq: " << impl_plaq<< std::endl;
RealD impl_plaq =
WilsonLoops<Gimpl>::avgPlaquette(SmearedSet[smearingLevels - 1]);
std::cout << GridLogDebug << "getting Usmr Plaq: " << impl_plaq
<< std::endl;
return get_SmearedU();
}
else {
} else {
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(*ThinLinks);
std::cout<< GridLogDebug << "getting Thin Plaq: " << impl_plaq<< std::endl;
std::cout << GridLogDebug << "getting Thin Plaq: " << impl_plaq
<< std::endl;
return *ThinLinks;
}
} else {
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(*ThinLinks);
std::cout << GridLogDebug << "getting Thin Plaq: " << impl_plaq
<< std::endl;
return *ThinLinks;
}
}
else{
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(*ThinLinks);
std::cout<< GridLogDebug << "getting Thin Plaq: " << impl_plaq<< std::endl;
return *ThinLinks;}
}
};
}
}
#endif

View File

@ -25,35 +25,38 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
See the full license in the file "LICENSE" in the top level distribution directory
See the full license in the file "LICENSE" in the top level distribution
directory
*************************************************************************************/
/* END LEGAL */
#include "Grid.h"
using namespace std;
using namespace Grid;
using namespace Grid::QCD;
/*
Grid_main.cc(232): error: no suitable user-defined conversion from "Grid::iScalar<Grid::iMatrix<Grid::iScalar<Grid::Complex>, 4>>" to "const Grid::iScalar<Grid::iScalar<Grid::iMatrix<Grid::Complex, 3>>>" exists
Grid_main.cc(232): error: no suitable user-defined conversion from
"Grid::iScalar<Grid::iMatrix<Grid::iScalar<Grid::Complex>, 4>>" to "const
Grid::iScalar<Grid::iScalar<Grid::iMatrix<Grid::Complex, 3>>>" exists
c_m = peekIdiot<SpinColourMatrix>(scm,1,2);
*/
template<class vobj> auto peekIdiot(const vobj &rhs,int i,int j) -> decltype(peekIndex<2>(rhs,0,0))
{
template <class vobj>
auto peekIdiot(const vobj &rhs, int i, int j)
-> decltype(peekIndex<2>(rhs, 0, 0)) {
return peekIndex<2>(rhs, i, j);
}
template<class vobj> auto peekDumKopf(const vobj &rhs,int i,int j) -> decltype(peekIndex<3>(rhs,0,0))
{
template <class vobj>
auto peekDumKopf(const vobj &rhs, int i, int j)
-> decltype(peekIndex<3>(rhs, 0, 0)) {
return peekIndex<3>(rhs, i, j);
}
template<class vobj> auto peekDumKopf(const vobj &rhs,int i) -> decltype(peekIndex<3>(rhs,0))
{
template <class vobj>
auto peekDumKopf(const vobj &rhs, int i) -> decltype(peekIndex<3>(rhs, 0)) {
return peekIndex<3>(rhs, i);
}
int main (int argc, char ** argv)
{
int main(int argc, char **argv) {
Grid_init(&argc, &argv);
std::vector<int> latt_size = GridDefaultLatt();
@ -73,7 +76,6 @@ int main (int argc, char ** argv)
#endif
for (int lat = 8; lat <= 16; lat += 40) {
std::cout << "Lat " << lat << std::endl;
latt_size[0] = lat;
@ -132,7 +134,6 @@ int main (int argc, char ** argv)
LatticeLorentzColourMatrix lcMat(&Fine);
LatticeComplex scalar(&Fine);
LatticeReal rscalar(&Fine);
LatticeReal iscalar(&Fine);
@ -154,24 +155,40 @@ int main (int argc, char ** argv)
random(FineRNG, sVec);
random(FineRNG, scVec);
fflush(stdout);
LatticeColourMatrix newFoo = Foo;
// confirm correctness of copy constructor
Bar = Foo - newFoo;
std::cout << "Copy constructor diff check: ";
double test_cc = norm2(Bar);
if (test_cc < 1e-5){
std::cout << "OK\n";
}
else{
std::cout << "fail\n";
abort();
}
TComplex tr = trace(cmat);
cVec = cMat * cVec; // LatticeColourVector = LatticeColourMatrix * LatticeColourVector
sVec = sMat * sVec; // LatticeSpinVector = LatticeSpinMatrix * LatticeSpinVector
scVec= scMat * scVec;// LatticeSpinColourVector = LatticeSpinColourMatrix * LatticeSpinColourVector
scVec= cMat * scVec; // LatticeSpinColourVector = LatticeColourMatrix * LatticeSpinColourVector
scVec= sMat * scVec; // LatticeSpinColourVector = LatticeSpinMatrix * LatticeSpinColourVector
cVec = cMat * cVec; // LatticeColourVector = LatticeColourMatrix
// * LatticeColourVector
sVec = sMat * sVec; // LatticeSpinVector = LatticeSpinMatrix
// * LatticeSpinVector
scVec = scMat * scVec; // LatticeSpinColourVector =
// LatticeSpinColourMatrix *
// LatticeSpinColourVector
scVec = cMat * scVec; // LatticeSpinColourVector = LatticeColourMatrix
// * LatticeSpinColourVector
scVec = sMat * scVec; // LatticeSpinColourVector = LatticeSpinMatrix
// * LatticeSpinColourVector
cMat = outerProduct(cVec, cVec);
scalar = localInnerProduct(cVec, cVec);
cMat = Ta(cMat); // traceless antihermitian
scalar += scalar;
scalar -= scalar;
scalar *= scalar;
@ -193,7 +210,6 @@ int main (int argc, char ** argv)
// scalar =cmplx(rscalar,iscalar);
PokeIndex<ColourIndex>(cVec, scalar, 1);
scalar = transpose(scalar);
scalar = TransposeIndex<ColourIndex>(scalar);
scalar = TraceIndex<SpinIndex>(scalar);
@ -214,9 +230,8 @@ int main (int argc, char ** argv)
// localNorm2
// localInnerProduct
scMat = sMat*scMat; // LatticeSpinColourMatrix = LatticeSpinMatrix * LatticeSpinColourMatrix
scMat = sMat * scMat; // LatticeSpinColourMatrix = LatticeSpinMatrix
// * LatticeSpinColourMatrix
///////////////////////
// Non-lattice (const objects) * Lattice
@ -229,10 +244,13 @@ int main (int argc, char ** argv)
// vSpinColourMatrix vscm;
scMat = cMat * scMat;
scm = cm * scm; // SpinColourMatrix = ColourMatrix * SpinColourMatrix
scm =
cm * scm; // SpinColourMatrix = ColourMatrix * SpinColourMatrix
scm = scm * cm; // SpinColourMatrix = SpinColourMartix * ColourMatrix
scm = GammaFive * scm ; // SpinColourMatrix = SpinMatrix * SpinColourMatrix
scm = scm* GammaFive ; // SpinColourMatrix = SpinColourMatrix * SpinMatrix
scm = GammaFive *
scm; // SpinColourMatrix = SpinMatrix * SpinColourMatrix
scm =
scm * GammaFive; // SpinColourMatrix = SpinColourMatrix * SpinMatrix
scm = scm * cplx;
vscm = vscm * cplx;
@ -261,7 +279,6 @@ int main (int argc, char ** argv)
scm = transpose(scm);
scm = transposeIndex<1>(scm);
random(SerialRNG, cm);
std::cout << GridLogMessage << cm << std::endl;
@ -269,7 +286,6 @@ int main (int argc, char ** argv)
TComplex tracecm = trace(cm);
std::cout << GridLogMessage << cm << std::endl;
cm = Exponentiate(cm, 2.0, 12);
std::cout << GridLogMessage << cm << " " << std::endl;
Complex det = Determinant(cm);
@ -283,11 +299,9 @@ int main (int argc, char ** argv)
std::cout << GridLogMessage << cm << " " << std::endl;
std::cout << GridLogMessage << "norm: " << norm2(cm) << std::endl;
// det = Determinant(cm);
// std::cout<<GridLogMessage << "determinant: " << det << std::endl;
// Foo = Foo+scalar; // LatticeColourMatrix+Scalar
// Foo = Foo*scalar; // LatticeColourMatrix*Scalar
// Foo = Foo-scalar; // LatticeColourMatrix-Scalar
@ -308,19 +322,20 @@ int main (int argc, char ** argv)
std::cout << GridLogMessage << cm << " " << std::endl;
std::cout << GridLogMessage << "norm: " << norm2(cm) << std::endl;
std::cout<<GridLogMessage << "norm cMmat : " << norm2(cMat) << std::endl;
std::cout << GridLogMessage << "norm cMmat : " << norm2(cMat)
<< std::endl;
cMat = expMat(cMat, ComplexD(1.0, 0.0));
std::cout<<GridLogMessage << "norm expMat: " << norm2(cMat) << std::endl;
std::cout << GridLogMessage << "norm expMat: " << norm2(cMat)
<< std::endl;
peekSite(cm, cMat, mysite);
std::cout << GridLogMessage << cm << " " << std::endl;
std::cout<<GridLogMessage << "determinant: " << Determinant(cm) << std::endl;
std::cout << GridLogMessage << "determinant: " << Determinant(cm)
<< std::endl;
std::cout << GridLogMessage << "norm: " << norm2(cm) << std::endl;
// LatticeComplex trlcMat(&Fine);
// trlcMat = trace(lcMat); // Trace involving iVector - now generates error
// trlcMat = trace(lcMat); // Trace involving iVector - now generates
// error
{ // Peek-ology and Poke-ology, with a little app-ology
Complex c;
@ -328,8 +343,10 @@ int main (int argc, char ** argv)
SpinMatrix s_m;
SpinColourMatrix sc_m;
s_m = TensorIndexRecursion<ColourIndex>::traceIndex(sc_m); // Map to traceColour
c_m = TensorIndexRecursion<SpinIndex>::traceIndex(sc_m); // map to traceSpin
s_m = TensorIndexRecursion<ColourIndex>::traceIndex(
sc_m); // Map to traceColour
c_m = TensorIndexRecursion<SpinIndex>::traceIndex(
sc_m); // map to traceSpin
c = TensorIndexRecursion<SpinIndex>::traceIndex(s_m);
c = TensorIndexRecursion<ColourIndex>::traceIndex(c_m);
@ -343,8 +360,10 @@ int main (int argc, char ** argv)
printf("c. Level %d\n", c_m().TensorLevel);
printf("c. Level %d\n", c_m()().TensorLevel);
c_m()() = scm()(0,0); //ColourComponents of CM <= ColourComponents of SpinColourMatrix
scm()(1,1) = cm()(); //ColourComponents of CM <= ColourComponents of SpinColourMatrix
c_m()() = scm()(0, 0); // ColourComponents of CM <= ColourComponents of
// SpinColourMatrix
scm()(1, 1) = cm()(); // ColourComponents of CM <= ColourComponents of
// SpinColourMatrix
c = scm()(1, 1)(1, 2);
scm()(1, 1)(2, 1) = c;
@ -364,12 +383,12 @@ int main (int argc, char ** argv)
*/
lex_sites(Foo);
Integer mm[4];
mm[0] = 1;
mm[1] = Fine._rdimensions[0];
mm[2] = Fine._ldimensions[0] * Fine._ldimensions[1];
mm[3]=Fine._ldimensions[0]*Fine._ldimensions[1]*Fine._ldimensions[2];
mm[3] =
Fine._ldimensions[0] * Fine._ldimensions[1] * Fine._ldimensions[2];
LatticeInteger lex(&Fine);
lex = zero;
@ -377,35 +396,37 @@ int main (int argc, char ** argv)
LatticeInteger coor(&Fine);
LatticeCoordinate(coor, d);
lex = lex + coor * mm[d];
}
// Bar = zero;
// Bar = where(lex<Integer(10),Foo,Bar);
cout << "peeking sites..\n";
{
std::vector<int> coor(4);
for (coor[3] = 0; coor[3] < latt_size[3] / mpi_layout[3]; coor[3]++) {
for (coor[2] = 0; coor[2] < latt_size[2] / mpi_layout[2]; coor[2]++) {
for(coor[1]=0;coor[1]<latt_size[1]/mpi_layout[1];coor[1]++){
for(coor[0]=0;coor[0]<latt_size[0]/mpi_layout[0];coor[0]++){
for (coor[1] = 0; coor[1] < latt_size[1] / mpi_layout[1];
coor[1]++) {
for (coor[0] = 0; coor[0] < latt_size[0] / mpi_layout[0];
coor[0]++) {
ColourMatrix bar;
peekSite(bar, Bar, coor);
for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++) {
// cout<<"bar "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<" "<<bar()()(r,c)<<std::endl;
}}
}}}}
// cout<<"bar "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<"
// "<<bar()()(r,c)<<std::endl;
}
}
}
}
}
}
}
// setCheckerboard(ShiftedCheck,rFoo);
// setCheckerboard(ShiftedCheck,bFoo);
// Lattice SU(3) x SU(3)
Fine.Barrier();
FooBar = Foo * Bar;
@ -440,11 +461,15 @@ int main (int argc, char ** argv)
Fine.Barrier();
if (Fine.IsBoss()) {
#ifdef OMP
printf("mult NumThread %d , Lattice size %d , %f us per call\n",omp_get_max_threads(),lat,(t1-t0)/ncall);
printf("mult NumThread %d , Lattice size %d , %f us per call\n",
omp_get_max_threads(), lat, (t1 - t0) / ncall);
#endif
printf("mult NumThread %d , Lattice size %d , %f us per call\n",omp,lat,(t1-t0)/ncall);
printf("mult NumThread %d , Lattice size %d , %f Mflop/s\n",omp,lat,flops/(t1-t0));
printf("mult NumThread %d , Lattice size %d , %f MB/s\n",omp,lat,bytes/(t1-t0));
printf("mult NumThread %d , Lattice size %d , %f us per call\n", omp,
lat, (t1 - t0) / ncall);
printf("mult NumThread %d , Lattice size %d , %f Mflop/s\n", omp, lat,
flops / (t1 - t0));
printf("mult NumThread %d , Lattice size %d , %f MB/s\n", omp, lat,
bytes / (t1 - t0));
}
mult(FooBar, Foo, Bar);
FooBar = Foo * Bar;
@ -464,9 +489,12 @@ int main (int argc, char ** argv)
FooBar = Foo * Bar;
if (Fine.IsBoss()) {
printf("Cshift Mult: NumThread %d , Lattice size %d , %f us per call\n",omp,lat,(t1-t0)/ncall);
printf("Cshift Mult: NumThread %d , Lattice size %d , %f Mflop/s\n",omp,lat,flops/(t1-t0));
printf("Cshift Mult: NumThread %d , Lattice size %d , %f MB/s\n",omp,lat,bytes/(t1-t0));
printf("Cshift Mult: NumThread %d , Lattice size %d , %f us per call\n",
omp, lat, (t1 - t0) / ncall);
printf("Cshift Mult: NumThread %d , Lattice size %d , %f Mflop/s\n",
omp, lat, flops / (t1 - t0));
printf("Cshift Mult: NumThread %d , Lattice size %d , %f MB/s\n", omp,
lat, bytes / (t1 - t0));
}
// pickCheckerboard(0,rFoo,FooBar);
// pickCheckerboard(1,bFoo,FooBar);
@ -475,20 +503,19 @@ int main (int argc, char ** argv)
double nrm = 0;
LatticeColourMatrix deriv(&Fine);
double half = 0.5;
deriv = 0.5 * Cshift(Foo, 0, 1) - 0.5 * Cshift(Foo, 0, -1);
for (int dir = 0; dir < 4; dir++) {
for (int shift = 0; shift < latt_size[dir]; shift++) {
pickCheckerboard(0,rFoo,Foo); // Pick out red or black checkerboards
pickCheckerboard(0, rFoo,
Foo); // Pick out red or black checkerboards
pickCheckerboard(1, bFoo, Foo);
if (Fine.IsBoss()) {
std::cout<<GridLogMessage << "Shifting both parities by "<< shift <<" direction "<< dir <<std::endl;
std::cout << GridLogMessage << "Shifting both parities by " << shift
<< " direction " << dir << std::endl;
}
Shifted = Cshift(Foo, dir, shift); // Shift everything
@ -497,45 +524,48 @@ int main (int argc, char ** argv)
ShiftedCheck = zero;
setCheckerboard(ShiftedCheck, bShifted); // Put them all together
setCheckerboard(ShiftedCheck,rShifted); // and check the results (later)
setCheckerboard(ShiftedCheck,
rShifted); // and check the results (later)
// Check results
std::vector<int> coor(4);
for (coor[3] = 0; coor[3] < latt_size[3] / mpi_layout[3]; coor[3]++) {
for(coor[2]=0;coor[2]<latt_size[2]/mpi_layout[2];coor[2]++){
for(coor[1]=0;coor[1]<latt_size[1]/mpi_layout[1];coor[1]++){
for(coor[0]=0;coor[0]<latt_size[0]/mpi_layout[0];coor[0]++){
for (coor[2] = 0; coor[2] < latt_size[2] / mpi_layout[2];
coor[2]++) {
for (coor[1] = 0; coor[1] < latt_size[1] / mpi_layout[1];
coor[1]++) {
for (coor[0] = 0; coor[0] < latt_size[0] / mpi_layout[0];
coor[0]++) {
std::complex<Grid::Real> diff;
std::vector<int> shiftcoor = coor;
shiftcoor[dir]=(shiftcoor[dir]+shift+latt_size[dir])%(latt_size[dir]/mpi_layout[dir]);
shiftcoor[dir] = (shiftcoor[dir] + shift + latt_size[dir]) %
(latt_size[dir] / mpi_layout[dir]);
std::vector<int> rl(4);
for (int dd = 0; dd < 4; dd++) {
rl[dd] = latt_size[dd] / simd_layout[dd] / mpi_layout[dd];
}
int lex = coor[0]%rl[0]
+ (coor[1]%rl[1])*rl[0]
+ (coor[2]%rl[2])*rl[0]*rl[1]
+ (coor[3]%rl[3])*rl[0]*rl[1]*rl[2];
lex +=
+1000*(coor[0]/rl[0])
+1000*(coor[1]/rl[1])*simd_layout[0]
+1000*(coor[2]/rl[2])*simd_layout[0]*simd_layout[1]
+1000*(coor[3]/rl[3])*simd_layout[0]*simd_layout[1]*simd_layout[2];
int lex = coor[0] % rl[0] + (coor[1] % rl[1]) * rl[0] +
(coor[2] % rl[2]) * rl[0] * rl[1] +
(coor[3] % rl[3]) * rl[0] * rl[1] * rl[2];
lex += +1000 * (coor[0] / rl[0]) +
1000 * (coor[1] / rl[1]) * simd_layout[0] +
1000 * (coor[2] / rl[2]) * simd_layout[0] *
simd_layout[1] +
1000 * (coor[3] / rl[3]) * simd_layout[0] *
simd_layout[1] * simd_layout[2];
int lex_coor = shiftcoor[0]%rl[0]
+ (shiftcoor[1]%rl[1])*rl[0]
+ (shiftcoor[2]%rl[2])*rl[0]*rl[1]
+ (shiftcoor[3]%rl[3])*rl[0]*rl[1]*rl[2];
lex_coor +=
+1000*(shiftcoor[0]/rl[0])
+1000*(shiftcoor[1]/rl[1])*simd_layout[0]
+1000*(shiftcoor[2]/rl[2])*simd_layout[0]*simd_layout[1]
+1000*(shiftcoor[3]/rl[3])*simd_layout[0]*simd_layout[1]*simd_layout[2];
int lex_coor = shiftcoor[0] % rl[0] +
(shiftcoor[1] % rl[1]) * rl[0] +
(shiftcoor[2] % rl[2]) * rl[0] * rl[1] +
(shiftcoor[3] % rl[3]) * rl[0] * rl[1] * rl[2];
lex_coor += +1000 * (shiftcoor[0] / rl[0]) +
1000 * (shiftcoor[1] / rl[1]) * simd_layout[0] +
1000 * (shiftcoor[2] / rl[2]) * simd_layout[0] *
simd_layout[1] +
1000 * (shiftcoor[3] / rl[3]) * simd_layout[0] *
simd_layout[1] * simd_layout[2];
ColourMatrix foo;
ColourMatrix bar;
@ -558,36 +588,46 @@ int main (int argc, char ** argv)
Real Ttr = real(trprod);
double nn = Ttr;
if (nn > 0)
cout<<"Shift real trace fail "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<endl;
cout << "Shift real trace fail " << coor[0] << coor[1]
<< coor[2] << coor[3] << endl;
for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++) {
diff = shifted1()()(r, c) - shifted2()()(r, c);
nn = real(conjugate(diff) * diff);
if (nn > 0)
cout<<"Shift fail (shifted1/shifted2-ref) "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<" "
cout << "Shift fail (shifted1/shifted2-ref) " << coor[0]
<< coor[1] << coor[2] << coor[3] << " "
<< shifted1()()(r, c) << " " << shifted2()()(r, c)
<< " "<< foo()()(r,c)<< " lex expect " << lex_coor << " lex "<<lex<<endl;
<< " " << foo()()(r, c) << " lex expect "
<< lex_coor << " lex " << lex << endl;
else if (0)
cout<<"Shift pass 1vs2 "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<" "
<<shifted1()()(r,c)<<" "<<shifted2()()(r,c)
<< " "<< foo()()(r,c)<< " lex expect " << lex_coor << " lex "<<lex<<endl;
}}
cout << "Shift pass 1vs2 " << coor[0] << coor[1]
<< coor[2] << coor[3] << " " << shifted1()()(r, c)
<< " " << shifted2()()(r, c) << " "
<< foo()()(r, c) << " lex expect " << lex_coor
<< " lex " << lex << endl;
}
}
for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++) {
diff = shifted3()()(r, c) - shifted2()()(r, c);
nn = real(conjugate(diff) * diff);
if (nn > 0)
cout<<"Shift rb fail (shifted3/shifted2-ref) "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<" "
cout << "Shift rb fail (shifted3/shifted2-ref) "
<< coor[0] << coor[1] << coor[2] << coor[3] << " "
<< shifted3()()(r, c) << " " << shifted2()()(r, c)
<< " "<< foo()()(r,c)<< " lex expect " << lex_coor << " lex "<<lex<<endl;
<< " " << foo()()(r, c) << " lex expect "
<< lex_coor << " lex " << lex << endl;
else if (0)
cout<<"Shift rb pass 3vs2 "<<coor[0]<<coor[1]<<coor[2]<<coor[3] <<" "
<<shifted3()()(r,c)<<" "<<shifted2()()(r,c)
<< " "<< foo()()(r,c)<< " lex expect " << lex_coor << " lex "<<lex<<endl;
}}
cout << "Shift rb pass 3vs2 " << coor[0] << coor[1]
<< coor[2] << coor[3] << " " << shifted3()()(r, c)
<< " " << shifted2()()(r, c) << " "
<< foo()()(r, c) << " lex expect " << lex_coor
<< " lex " << lex << endl;
}
}
peekSite(bar, Bar, coor);
peekSite(foobar1, FooBar, coor);
@ -596,17 +636,23 @@ int main (int argc, char ** argv)
for (int c = 0; c < Nc; c++) {
diff = foobar2()()(r, c) - foobar1()()(r, c);
nrm = nrm + real(conjugate(diff) * diff);
}}
}}}}
if( Fine.IsBoss() ){
std::cout<<GridLogMessage << "LatticeColorMatrix * LatticeColorMatrix nrm diff = "<<nrm<<std::endl;
}
}}
}
}
}
}
}
if (Fine.IsBoss()) {
std::cout << GridLogMessage
<< "LatticeColorMatrix * LatticeColorMatrix nrm diff = "
<< nrm << std::endl;
}
}
}
} // loop for lat
} // loop for omp
/*
// Testing Smearing routine compilation, separate in a different file
GridCartesian Fine(latt_size,simd_layout,mpi_layout);