// i represents a "half index" into an even or odd "half lattice". // when oddBit={0,1} the half lattice is {even,odd}. // // the displacements, such as dx, refer to the full lattice coordinates. // // neighborIndex() takes a "half index", displaces it, and returns the // new "half index", which can be an index into either the even or odd lattices. // displacements of magnitude one always interchange odd and even lattices. // int neighborIndex(int i, int oddBit, int dx4, int dx3, int dx2, int dx1) { int X = fullLatticeIndex(i, oddBit); int x4 = X/(L3*L2*L1); int x3 = (X/(L2*L1)) % L3; int x2 = (X/L1) % L2; int x1 = X % L1; // assert (oddBit == (x+y+z+t)%2); x4 = (x4+dx4+L4) % L4; x3 = (x3+dx3+L3) % L3; x2 = (x2+dx2+L2) % L2; x1 = (x1+dx1+L1) % L1; return (x4*(L3*L2*L1) + x3*(L2*L1) + x2*(L1) + x1) / 2; }
int link_sanity_check_internal_12(Float* link, int dir, int ga_idx, QudaGaugeParam* gaugeParam, int oddBit) { //printf("link sanity check is called\n"); int ret =0; Float refc_buf[6]; Float* refc = &refc_buf[0]; memset((void*)refc, 0, sizeof(refc_buf)); Float* a = link; Float* b = link + 6; Float* c = link + 12; accumulateConjugateProduct(refc + 0*2, a + 1*2, b + 2*2, +1); accumulateConjugateProduct(refc + 0*2, a + 2*2, b + 1*2, -1); accumulateConjugateProduct(refc + 1*2, a + 2*2, b + 0*2, +1); accumulateConjugateProduct(refc + 1*2, a + 0*2, b + 2*2, -1); accumulateConjugateProduct(refc + 2*2, a + 0*2, b + 1*2, +1); accumulateConjugateProduct(refc + 2*2, a + 1*2, b + 0*2, -1); int X1h=gaugeParam->X[0]/2; int X1 =gaugeParam->X[0]; int X2 =gaugeParam->X[1]; int X3 =gaugeParam->X[2]; int X4 =gaugeParam->X[3]; double t_boundary = (gaugeParam->t_boundary ==QUDA_ANTI_PERIODIC_T)? -1.0:1.0; double u0 = gaugeParam->tadpole_coeff; double coff= -u0*u0*24; //coff = (dir < 6) ? coff : ( (ga_idx >= (X4-3)*X1h*X2*X3 )? t_boundary : 1); //float u0 = (dir < 6) ? gaugeParam->anisotropy : ( (ga_idx >= (X4-3)*X1h*X2*X3 )? t_boundary : 1); #if 1 { int index = fullLatticeIndex(ga_idx, oddBit); int i4 = index /(X3*X2*X1); int i3 = (index - i4*(X3*X2*X1))/(X2*X1); int i2 = (index - i4*(X3*X2*X1) - i3*(X2*X1))/X1; int i1 = index - i4*(X3*X2*X1) - i3*(X2*X1) - i2*X1; if (dir == 0) { if (i4 % 2 == 1){ coff *= -1; } } if (dir == 2){ if ((i1+i4) % 2 == 1){ coff *= -1; } } if (dir == 4){ if ( (i4+i1+i2) % 2 == 1){ coff *= -1; } } if (dir == 6){ if (ga_idx >= (X4-3)*X1h*X2*X3 ){ coff *= -1; } } //printf("local ga_idx =%d, index=%d, i4,3,2,1 =%d %d %d %d\n", ga_idx, index, i4, i3, i2,i1); } #endif refc[0]*=coff; refc[1]*=coff; refc[2]*=coff; refc[3]*=coff; refc[4]*=coff; refc[5]*=coff; double delta = 0.0001; int i; for (i =0;i < 6; i++){ double diff = refc[i] - c[i]; double absdiff = diff > 0? diff: (-diff); if (absdiff > delta){ printf("ERROR: sanity check failed for link\n"); display_link_internal(link); printf("refc = (%.10f,%.10f) (%.10f,%.10f) (%.10f,%.10f)\n", refc[0], refc[1], refc[2], refc[3], refc[4], refc[5]); printf("dir=%d, ga_idx=%d, coff=%f, t_boundary=%f\n",dir, ga_idx,coff, t_boundary); printf("X=%d %d %d %d, X1h=%d\n", gaugeParam->X[0], X2, X3, X4, X1h); return -1; } } return ret; }
int link_sanity_check_internal_8(Float* link, int dir, int ga_idx, QudaGaugeParam* gaugeParam, int oddBit) { int ret =0; Float ref_link_buf[18]; Float* ref = & ref_link_buf[0]; memset(ref, 0, sizeof(ref_link_buf)); ref[0] = atan2(link[1], link[0]); ref[1] = atan2(link[13], link[12]); for (int i=2; i<7; i++) { ref[i] = link[i]; } int X1h=gaugeParam->X[0]/2; int X2 =gaugeParam->X[1]; int X3 =gaugeParam->X[2]; int X4 =gaugeParam->X[3]; double t_boundary = (gaugeParam->t_boundary ==QUDA_ANTI_PERIODIC_T)? -1.0:1.0; // First reconstruct first row Float row_sum = 0.0; row_sum += ref[2]*ref[2]; row_sum += ref[3]*ref[3]; row_sum += ref[4]*ref[4]; row_sum += ref[5]*ref[5]; #define SMALL_NUM 1e-24 row_sum = (row_sum != 0)?row_sum: SMALL_NUM; #if 1 Float u0= -gaugeParam->tadpole_coeff*gaugeParam->tadpole_coeff*24; { int X1h=gaugeParam->X[0]/2; int X1 =gaugeParam->X[0]; int X2 =gaugeParam->X[1]; int X3 =gaugeParam->X[2]; int X4 =gaugeParam->X[3]; int index = fullLatticeIndex(ga_idx, oddBit); int i4 = index /(X3*X2*X1); int i3 = (index - i4*(X3*X2*X1))/(X2*X1); int i2 = (index - i4*(X3*X2*X1) - i3*(X2*X1))/X1; int i1 = index - i4*(X3*X2*X1) - i3*(X2*X1) - i2*X1; if (dir == 0) { if (i4 % 2 == 1){ u0 *= -1; } } if (dir == 1){ if ((i1+i4) % 2 == 1){ u0 *= -1; } } if (dir == 2){ if ( (i4+i1+i2) % 2 == 1){ u0 *= -1; } } if (dir == 3){ if (ga_idx >= (X4-3)*X1h*X2*X3 ){ u0 *= -1; } } //printf("local ga_idx =%d, index=%d, i4,3,2,1 =%d %d %d %d\n", ga_idx, index, i4, i3, i2,i1); } #endif Float U00_mag = sqrt( (1.f/(u0*u0) - row_sum)>0? (1.f/(u0*u0)-row_sum):0); ref[14] = ref[0]; ref[15] = ref[1]; ref[0] = U00_mag * cos(ref[14]); ref[1] = U00_mag * sin(ref[14]); Float column_sum = 0.0; for (int i=0; i<2; i++) column_sum += ref[i]*ref[i]; for (int i=6; i<8; i++) column_sum += ref[i]*ref[i]; Float U20_mag = sqrt( (1.f/(u0*u0) - column_sum) > 0? (1.f/(u0*u0)-column_sum) : 0); ref[12] = U20_mag * cos(ref[15]); ref[13] = U20_mag * sin(ref[15]); // First column now restored // finally reconstruct last elements from SU(2) rotation Float r_inv2 = 1.0/(u0*row_sum); // U11 Float A[2]; complexDotProduct(A, ref+0, ref+6); complexConjugateProduct(ref+8, ref+12, ref+4); accumulateComplexProduct(ref+8, A, ref+2, u0); ref[8] *= -r_inv2; ref[9] *= -r_inv2; // U12 complexConjugateProduct(ref+10, ref+12, ref+2); accumulateComplexProduct(ref+10, A, ref+4, -u0); ref[10] *= r_inv2; ref[11] *= r_inv2; // U21 complexDotProduct(A, ref+0, ref+12); complexConjugateProduct(ref+14, ref+6, ref+4); accumulateComplexProduct(ref+14, A, ref+2, -u0); ref[14] *= r_inv2; ref[15] *= r_inv2; // U12 complexConjugateProduct(ref+16, ref+6, ref+2); accumulateComplexProduct(ref+16, A, ref+4, u0); ref[16] *= -r_inv2; ref[17] *= -r_inv2; double delta = 0.0001; int i; for (i =0;i < 18; i++){ double diff = ref[i] - link[i]; double absdiff = diff > 0? diff: (-diff); if ( (ref[i] != ref[i]) || (absdiff > delta)){ printf("ERROR: sanity check failed for link\n"); display_link_internal(link); printf("reconstructed link is\n"); display_link_internal(ref); printf("dir=%d, ga_idx=%d, u0=%f, t_boundary=%f\n",dir, ga_idx, u0, t_boundary); printf("X=%d %d %d %d, X1h=%d\n", gaugeParam->X[0], X2, X3, X4, X1h); return -1; } } return ret; }
int site_link_sanity_check_internal_12(Float* link, int dir, int ga_idx, QudaGaugeParam* gaugeParam, int oddBit) { int ret =0; Float refc_buf[6]; Float* refc = &refc_buf[0]; memset((void*)refc, 0, sizeof(refc_buf)); Float* a = link; Float* b = link + 6; Float* c = link + 12; accumulateConjugateProduct(refc + 0*2, a + 1*2, b + 2*2, +1); accumulateConjugateProduct(refc + 0*2, a + 2*2, b + 1*2, -1); accumulateConjugateProduct(refc + 1*2, a + 2*2, b + 0*2, +1); accumulateConjugateProduct(refc + 1*2, a + 0*2, b + 2*2, -1); accumulateConjugateProduct(refc + 2*2, a + 0*2, b + 1*2, +1); accumulateConjugateProduct(refc + 2*2, a + 1*2, b + 0*2, -1); int X1h=gaugeParam->X[0]/2; int X1 =gaugeParam->X[0]; int X2 =gaugeParam->X[1]; int X3 =gaugeParam->X[2]; int X4 =gaugeParam->X[3]; #if 1 double coeff= 1.0; { int index = fullLatticeIndex(ga_idx, oddBit); int i4 = index /(X3*X2*X1); int i3 = (index - i4*(X3*X2*X1))/(X2*X1); int i2 = (index - i4*(X3*X2*X1) - i3*(X2*X1))/X1; int i1 = index - i4*(X3*X2*X1) - i3*(X2*X1) - i2*X1; if (dir == XUP) { if (i4 % 2 == 1){ coeff *= -1; } } if (dir == YUP){ if ((i1+i4) % 2 == 1){ coeff *= -1; } } if (dir == ZUP){ if ( (i4+i1+i2) % 2 == 1){ coeff *= -1; } } if (dir == TUP){ if ((commCoords(3) == commDim(3) -1) && i4 == (X4-1) ){ coeff *= -1; } } } refc[0]*=coeff; refc[1]*=coeff; refc[2]*=coeff; refc[3]*=coeff; refc[4]*=coeff; refc[5]*=coeff; #endif double delta = 0.0001; int i; for (i =0;i < 6; i++){ double diff = refc[i] - c[i]; double absdiff = diff > 0? diff: (-diff); if (absdiff > delta){ printf("ERROR: sanity check failed for site link\n"); display_link_internal(link); printf("refc = (%.10f,%.10f) (%.10f,%.10f) (%.10f,%.10f)\n", refc[0], refc[1], refc[2], refc[3], refc[4], refc[5]); printf("X=%d %d %d %d, X1h=%d\n", gaugeParam->X[0], X2, X3, X4, X1h); return -1; } } return ret; }