mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 20:57:06 +01:00
Compare commits
273 Commits
feature/di
...
rmhmc_merg
Author | SHA1 | Date | |
---|---|---|---|
cfa0576ffd | |||
fe98e9f555 | |||
948d16fb06 | |||
58fbcaa399 | |||
9ad6836b0f | |||
026eb8a695 | |||
076580c232 | |||
7af6022a2a | |||
982a60536c | |||
dc36d272ce | |||
515ff6bf62 | |||
6d0c2de399 | |||
7786ea9921 | |||
d93eac7b1c | |||
afc316f501 | |||
f14bfd5c1b | |||
c5f1420dea | |||
018e6da872 | |||
b77bccfac2 | |||
80359e0d49 | |||
3d437c5cc4 | |||
b8a7004365 | |||
bd56c95a6f | |||
994512048e | |||
dbd8bb49dc | |||
3a29af0ce4 | |||
f7b79cdd45 | |||
075b9d22d0 | |||
b92428f05f | |||
34b11864b6 | |||
1dfaa08afb | |||
f44dce390f | |||
bb71e9a96a | |||
78bae9417c | |||
dd170ead01 | |||
014704856f | |||
6f6844ccf1 | |||
4c6613d72c | |||
ee92e08edb | |||
c1dcee9328 | |||
559257bbe9 | |||
6b150961fe | |||
cff1f8d3b8 | |||
f27d2083cd | |||
36cc9c524f | |||
2822487450 | |||
e07fafe46a | |||
063d290bd8 | |||
4e6194d92a | |||
de30c4e22a | |||
5bafcaedfa | |||
bfeceae708 | |||
eacb66591f | |||
fadaa85626 | |||
02a5b0d786 | |||
0e2141442a | |||
769eb0eecb | |||
4241c7d4a3 | |||
7b11075102 | |||
abc658dca5 | |||
2372275b2c | |||
ef736e8aa4 | |||
5e539e2d54 | |||
96773f5254 | |||
d80df09f3b | |||
621e612c30 | |||
8c3792721b | |||
c95bbd3948 | |||
e28ab7a732 | |||
c797cbe737 | |||
e09dfbf1c2 | |||
85e35c4da1 | |||
d72e914cf0 | |||
3b5254e2d5 | |||
f1c358b596 | |||
c0ef210265 | |||
e3e1cc1962 | |||
723eadbb5c | |||
e24637ec1e | |||
8b01ff4ce7 | |||
588197c487 | |||
116d90b0ee | |||
b0646ca187 | |||
1352bad2e4 | |||
4895ff260e | |||
470d93006a | |||
2f3d03f188 | |||
8db7c23bee | |||
69dc5172dc | |||
fd72eb6546 | |||
ffd7301649 | |||
d2a8494044 | |||
0982e0d19b | |||
3badbfc3c1 | |||
5465961e30 | |||
477b794bc5 | |||
4835fd1a87 | |||
6533c25814 | |||
b405767569 | |||
fe88a0c12f | |||
e61a9ed2b4 | |||
de8daa3824 | |||
3a50fb29cb | |||
6647d2656f | |||
a6f4dbeb6d | |||
92a282f2d8 | |||
ca2fd9fc7b | |||
be1a4f5860 | |||
1b2914ec09 | |||
519f795066 | |||
5897b93dd4 | |||
af091e0881 | |||
3c1e5e9517 | |||
85b2cb7a8a | |||
4240ad5ca8 | |||
d418347d86 | |||
29a4bfe5e5 | |||
9955bf9daf | |||
b8bdc2eefb | |||
0078826ff1 | |||
e855c41772 | |||
d169c275b6 | |||
a5125e23f4 | |||
7b83c80757 | |||
e41821e206 | |||
5a75ab15a2 | |||
932c783fbf | |||
55f9cce577 | |||
b3533ca847 | |||
fd2a637010 | |||
eee27b8b30 | |||
8522352aa3 | |||
3beb8f4091 | |||
12a706e9b1 | |||
170aa7df01 | |||
e8ad1fef53 | |||
876c8f4478 | |||
9c8750f261 | |||
91efd08179 | |||
9953511b65 | |||
025fa9991a | |||
e8c60c355b | |||
6c9c7f9d85 | |||
f534523ede | |||
1b8a834beb | |||
aa9df63a05 | |||
3953312a93 | |||
6e62f4f616 | |||
6a7bdca53b | |||
c7fba9aace | |||
ac6c7cb8d6 | |||
c5924833a1 | |||
ac0a74be0d | |||
42b0e1125d | |||
339c4fda79 | |||
9b85bf9402 | |||
86b02c3cd8 | |||
7b3b7093fa | |||
881b08a465 | |||
3ee5444c69 | |||
5e28fe56d2 | |||
3aa43e6065 | |||
78ac4044ff | |||
119c3db47f | |||
21bbdb8fc2 | |||
5aabe074fe | |||
739bd7572c | |||
074627a5bd | |||
6a23b2c599 | |||
dace904c10 | |||
be98d26610 | |||
bd891fb3f5 | |||
3984265851 | |||
45361d188f | |||
80c9d77e02 | |||
3aff64dddb | |||
b4f2ca81ff | |||
d1dea5f840 | |||
54f8b84d16 | |||
da503fef0e | |||
4a6802098a | |||
f9b41a84d2 | |||
5d7e0d18b9 | |||
9e64387933 | |||
983b681d46 | |||
4072408b6f | |||
bd76b47fbf | |||
178376f24b | |||
18ce23aa75 | |||
6a0eb466ee | |||
ffa7fe0cc2 | |||
4ea29b8f0f | |||
778291230a | |||
86dac5ff4f | |||
4a382fad3f | |||
cc753670d9 | |||
cc9d88ea1c | |||
b281b0166e | |||
6a21f694ff | |||
026e736dfa | |||
4275b3f431 | |||
af64c1c6b6 | |||
866f48391a | |||
a4df527d74 | |||
5764d21161 | |||
496d04cd85 | |||
10e6d7c6ce | |||
c42e25e5b8 | |||
a00ae981e0 | |||
39214702f6 | |||
3e4614c63a | |||
1b8176e2c0 | |||
cbc053c3db | |||
cdf3f6ef6e | |||
ba7f9d7b70 | |||
371fd123fb | |||
d6ff644aab | |||
29586f6b5e | |||
fd057c838f | |||
f51222086c | |||
f73691ec47 | |||
ccd21f96ff | |||
4b90cb8888 | |||
7ebda3e9ec | |||
b10e1b7bc8 | |||
d7dea44ce7 | |||
37b6b82869 | |||
92ad5b8f74 | |||
8c80f1c168 | |||
0af7d5a793 | |||
505fa49983 | |||
7bcf33def9 | |||
a13820656a | |||
fa71b46a41 | |||
b8b3ae6ac1 | |||
55c008da21 | |||
2507606bd0 | |||
7c2ad4f8c8 | |||
54c8025aad | |||
921e23e83c | |||
6e750ecb0e | |||
b8f1f5d2a3 | |||
9273f2937c | |||
1aa28b47ae | |||
629cb2987a | |||
03235d6368 | |||
22064c7e4c | |||
2de03e5172 | |||
3af4929dda | |||
1ba429345b | |||
88bdd4344b | |||
4044536eea | |||
4d8ae6221c | |||
4e31e4e094 | |||
0d6674e489 | |||
b145fd4f5b | |||
8a5b794f25 | |||
291e80f88a | |||
1ace5850ae | |||
283f14b7c1 | |||
1d6e708083 | |||
89457e25e3 | |||
7e3b298d3d | |||
7ff3e5eed4 | |||
19eb51cf41 | |||
470d4dcc6d | |||
ed03bfd555 | |||
8c0fbcccae | |||
d4866157fe | |||
b6496b6cb5 | |||
4f5fe57920 | |||
11fb943b1e | |||
046a23121e |
54
.github/ISSUE_TEMPLATE/bug-report.yml
vendored
Normal file
54
.github/ISSUE_TEMPLATE/bug-report.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
name: Bug report
|
||||
description: Report a bug.
|
||||
title: "<insert title>"
|
||||
labels: [bug]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
Thank you for taking the time to file a bug report.
|
||||
Please check that the code is pointing to the HEAD of develop
|
||||
or any commit in master which is tagged with a version number.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Describe the issue:"
|
||||
description: >
|
||||
Describe the issue and any previous attempt to solve it.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Code example:"
|
||||
description: >
|
||||
If relevant, show how to reproduce the issue using a minimal working
|
||||
example.
|
||||
placeholder: |
|
||||
<< your code here >>
|
||||
render: shell
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Target platform:"
|
||||
description: >
|
||||
Give a description of the target platform (CPU, network, compiler).
|
||||
Please give the full CPU part description, using for example
|
||||
`cat /proc/cpuinfo | grep 'model name' | uniq` (Linux)
|
||||
or `sysctl machdep.cpu.brand_string` (macOS) and the full output
|
||||
the `--version` option of your compiler.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: "Configure options:"
|
||||
description: >
|
||||
Please give the exact configure command used and attach
|
||||
`config.log`, `grid.config.summary` and the output of `make V=1`.
|
||||
render: shell
|
||||
validations:
|
||||
required: true
|
@ -66,6 +66,10 @@ if BUILD_FERMION_REPS
|
||||
extra_sources+=$(ADJ_FERMION_FILES)
|
||||
extra_sources+=$(TWOIND_FERMION_FILES)
|
||||
endif
|
||||
if BUILD_SP
|
||||
extra_sources+=$(SP_FERMION_FILES)
|
||||
extra_sources+=$(SP_TWOIND_FERMION_FILES)
|
||||
endif
|
||||
|
||||
lib_LIBRARIES = libGrid.a
|
||||
|
||||
|
@ -460,6 +460,53 @@ class NonHermitianSchurDiagTwoOperator : public NonHermitianSchurOperatorBase<Fi
|
||||
}
|
||||
};
|
||||
|
||||
template<class Matrix,class Field>
|
||||
class QuadLinearOperator : public LinearOperatorBase<Field> {
|
||||
Matrix &_Mat;
|
||||
public:
|
||||
RealD a0,a1,a2;
|
||||
QuadLinearOperator(Matrix &Mat): _Mat(Mat),a0(0.),a1(0.),a2(1.) {};
|
||||
QuadLinearOperator(Matrix &Mat, RealD _a0,RealD _a1,RealD _a2): _Mat(Mat),a0(_a0),a1(_a1),a2(_a2) {};
|
||||
// Support for coarsening to a multigrid
|
||||
void OpDiag (const Field &in, Field &out) {
|
||||
assert(0);
|
||||
_Mat.Mdiag(in,out);
|
||||
}
|
||||
void OpDir (const Field &in, Field &out,int dir,int disp) {
|
||||
assert(0);
|
||||
_Mat.Mdir(in,out,dir,disp);
|
||||
}
|
||||
void OpDirAll (const Field &in, std::vector<Field> &out){
|
||||
assert(0);
|
||||
_Mat.MdirAll(in,out);
|
||||
}
|
||||
void HermOp (const Field &in, Field &out){
|
||||
// _Mat.M(in,out);
|
||||
Field tmp1(in.Grid());
|
||||
// Linop.HermOpAndNorm(psi, mmp, d, b);
|
||||
_Mat.M(in,tmp1);
|
||||
_Mat.M(tmp1,out);
|
||||
out *= a2;
|
||||
axpy(out, a1, tmp1, out);
|
||||
axpy(out, a0, in, out);
|
||||
// d=real(innerProduct(psi,mmp));
|
||||
// b=norm2(mmp);
|
||||
}
|
||||
void AdjOp (const Field &in, Field &out){
|
||||
assert(0);
|
||||
_Mat.M(in,out);
|
||||
}
|
||||
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||
HermOp(in,out);
|
||||
ComplexD dot= innerProduct(in,out); n1=real(dot);
|
||||
n2=norm2(out);
|
||||
}
|
||||
void Op(const Field &in, Field &out){
|
||||
assert(0);
|
||||
_Mat.M(in,out);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Left handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) psi = eta --> ( 1 - Moo^-1 Moe Mee^-1 Meo ) psi = Moo^-1 eta
|
||||
// Right handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) Moo^-1 Moo psi = eta --> ( 1 - Moe Mee^-1 Meo Moo^-1) phi=eta ; psi = Moo^-1 phi
|
||||
@ -542,6 +589,7 @@ public:
|
||||
(*this)(in[i], out[i]);
|
||||
}
|
||||
}
|
||||
virtual ~LinearFunction(){};
|
||||
};
|
||||
|
||||
template<class Field> class IdentityLinearFunction : public LinearFunction<Field> {
|
||||
|
@ -36,11 +36,12 @@ NAMESPACE_BEGIN(Grid);
|
||||
// Abstract base class.
|
||||
// Takes a matrix (Mat), a source (phi), and a vector of Fields (chi)
|
||||
// and returns a forecasted solution to the system D*psi = phi (psi).
|
||||
template<class Matrix, class Field>
|
||||
// Changing to operator
|
||||
template<class LinearOperatorBase, class Field>
|
||||
class Forecast
|
||||
{
|
||||
public:
|
||||
virtual Field operator()(Matrix &Mat, const Field& phi, const std::vector<Field>& chi) = 0;
|
||||
virtual Field operator()(LinearOperatorBase &Mat, const Field& phi, const std::vector<Field>& chi) = 0;
|
||||
};
|
||||
|
||||
// Implementation of Brower et al.'s chronological inverter (arXiv:hep-lat/9509012),
|
||||
@ -54,13 +55,13 @@ public:
|
||||
Field operator()(Matrix &Mat, const Field& phi, const std::vector<Field>& prev_solns)
|
||||
{
|
||||
int degree = prev_solns.size();
|
||||
std::cout << GridLogMessage << "ChronoForecast: degree= " << degree << std::endl;
|
||||
Field chi(phi); // forecasted solution
|
||||
|
||||
// Trivial cases
|
||||
if(degree == 0){ chi = Zero(); return chi; }
|
||||
else if(degree == 1){ return prev_solns[0]; }
|
||||
|
||||
// RealD dot;
|
||||
ComplexD xp;
|
||||
Field r(phi); // residual
|
||||
Field Mv(phi);
|
||||
@ -83,8 +84,9 @@ public:
|
||||
// Perform sparse matrix multiplication and construct rhs
|
||||
for(int i=0; i<degree; i++){
|
||||
b[i] = innerProduct(v[i],phi);
|
||||
Mat.M(v[i],Mv);
|
||||
Mat.Mdag(Mv,MdagMv[i]);
|
||||
// Mat.M(v[i],Mv);
|
||||
// Mat.Mdag(Mv,MdagMv[i]);
|
||||
Mat.HermOp(v[i],MdagMv[i]);
|
||||
G[i][i] = innerProduct(v[i],MdagMv[i]);
|
||||
}
|
||||
|
||||
|
@ -166,16 +166,16 @@ public:
|
||||
rsqf[s] =rsq[s];
|
||||
std::cout<<GridLogMessage<<"ConjugateGradientMultiShiftMixedPrecCleanup: shift "<< s <<" target resid "<<rsq[s]<<std::endl;
|
||||
// ps_d[s] = src_d;
|
||||
precisionChangeFast(ps_f[s],src_d);
|
||||
precisionChange(ps_f[s],src_d);
|
||||
}
|
||||
// r and p for primary
|
||||
p_d = src_d; //primary copy --- make this a reference to ps_d to save axpys
|
||||
r_d = p_d;
|
||||
|
||||
//MdagM+m[0]
|
||||
precisionChangeFast(p_f,p_d);
|
||||
precisionChange(p_f,p_d);
|
||||
Linop_f.HermOpAndNorm(p_f,mmp_f,d,qq); // mmp = MdagM p d=real(dot(p, mmp)), qq=norm2(mmp)
|
||||
precisionChangeFast(tmp_d,mmp_f);
|
||||
precisionChange(tmp_d,mmp_f);
|
||||
Linop_d.HermOpAndNorm(p_d,mmp_d,d,qq); // mmp = MdagM p d=real(dot(p, mmp)), qq=norm2(mmp)
|
||||
tmp_d = tmp_d - mmp_d;
|
||||
std::cout << " Testing operators match "<<norm2(mmp_d)<<" f "<<norm2(mmp_f)<<" diff "<< norm2(tmp_d)<<std::endl;
|
||||
@ -204,7 +204,7 @@ public:
|
||||
|
||||
for(int s=0;s<nshift;s++) {
|
||||
axpby(psi_d[s],0.,-bs[s]*alpha[s],src_d,src_d);
|
||||
precisionChangeFast(psi_f[s],psi_d[s]);
|
||||
precisionChange(psi_f[s],psi_d[s]);
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
@ -225,7 +225,7 @@ public:
|
||||
AXPYTimer.Stop();
|
||||
|
||||
PrecChangeTimer.Start();
|
||||
precisionChangeFast(r_f, r_d);
|
||||
precisionChange(r_f, r_d);
|
||||
PrecChangeTimer.Stop();
|
||||
|
||||
AXPYTimer.Start();
|
||||
@ -243,13 +243,13 @@ public:
|
||||
|
||||
cp=c;
|
||||
PrecChangeTimer.Start();
|
||||
precisionChangeFast(p_f, p_d); //get back single prec search direction for linop
|
||||
precisionChange(p_f, p_d); //get back single prec search direction for linop
|
||||
PrecChangeTimer.Stop();
|
||||
MatrixTimer.Start();
|
||||
Linop_f.HermOp(p_f,mmp_f);
|
||||
MatrixTimer.Stop();
|
||||
PrecChangeTimer.Start();
|
||||
precisionChangeFast(mmp_d, mmp_f); // From Float to Double
|
||||
precisionChange(mmp_d, mmp_f); // From Float to Double
|
||||
PrecChangeTimer.Stop();
|
||||
|
||||
d=real(innerProduct(p_d,mmp_d));
|
||||
@ -311,7 +311,7 @@ public:
|
||||
SolverTimer.Stop();
|
||||
|
||||
for(int s=0;s<nshift;s++){
|
||||
precisionChangeFast(psi_d[s],psi_f[s]);
|
||||
precisionChange(psi_d[s],psi_f[s]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,7 +211,7 @@ public:
|
||||
Linop_d.HermOpAndNorm(p_d,mmp_d,d,qq); // mmp = MdagM p d=real(dot(p, mmp)), qq=norm2(mmp)
|
||||
tmp_d = tmp_d - mmp_d;
|
||||
std::cout << " Testing operators match "<<norm2(mmp_d)<<" f "<<norm2(mmp_f)<<" diff "<< norm2(tmp_d)<<std::endl;
|
||||
// assert(norm2(tmp_d)< 1.0e-4);
|
||||
assert(norm2(tmp_d)< 1.0);
|
||||
|
||||
axpy(mmp_d,mass[0],p_d,mmp_d);
|
||||
RealD rn = norm2(p_d);
|
||||
|
@ -419,14 +419,15 @@ until convergence
|
||||
}
|
||||
}
|
||||
|
||||
if ( Nconv < Nstop )
|
||||
if ( Nconv < Nstop ) {
|
||||
std::cout << GridLogIRL << "Nconv ("<<Nconv<<") < Nstop ("<<Nstop<<")"<<std::endl;
|
||||
|
||||
std::cout << GridLogIRL << "returning Nstop vectors, the last "<< Nstop-Nconv << "of which might meet convergence criterion only approximately" <<std::endl;
|
||||
}
|
||||
eval=eval2;
|
||||
|
||||
//Keep only converged
|
||||
eval.resize(Nconv);// Nstop?
|
||||
evec.resize(Nconv,grid);// Nstop?
|
||||
eval.resize(Nstop);// was Nconv
|
||||
evec.resize(Nstop,grid);// was Nconv
|
||||
basisSortInPlace(evec,eval,reverse);
|
||||
|
||||
}
|
||||
|
@ -519,7 +519,6 @@ void MemoryManager::Audit(std::string s)
|
||||
uint64_t LruBytes1=0;
|
||||
uint64_t LruBytes2=0;
|
||||
uint64_t LruCnt=0;
|
||||
uint64_t LockedBytes=0;
|
||||
|
||||
std::cout << " Memory Manager::Audit() from "<<s<<std::endl;
|
||||
for(auto it=LRU.begin();it!=LRU.end();it++){
|
||||
|
@ -128,7 +128,7 @@ double CartesianCommunicator::StencilSendToRecvFromBegin(std::vector<CommsReques
|
||||
int recv_from_rank,int dor,
|
||||
int xbytes,int rbytes, int dir)
|
||||
{
|
||||
return 2.0*bytes;
|
||||
return xbytes+rbytes;
|
||||
}
|
||||
void CartesianCommunicator::StencilSendToRecvFromComplete(std::vector<CommsRequest_t> &waitall,int dir)
|
||||
{
|
||||
|
@ -91,6 +91,59 @@ void *SharedMemory::ShmBufferSelf(void)
|
||||
//std::cerr << "ShmBufferSelf "<<ShmRank<<" "<<std::hex<< ShmCommBufs[ShmRank] <<std::dec<<std::endl;
|
||||
return ShmCommBufs[ShmRank];
|
||||
}
|
||||
static inline int divides(int a,int b)
|
||||
{
|
||||
return ( b == ( (b/a)*a ) );
|
||||
}
|
||||
void GlobalSharedMemory::GetShmDims(const Coordinate &WorldDims,Coordinate &ShmDims)
|
||||
{
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Allow user to configure through environment variable
|
||||
////////////////////////////////////////////////////////////////
|
||||
char* str = getenv(("GRID_SHM_DIMS_" + std::to_string(ShmDims.size())).c_str());
|
||||
if ( str ) {
|
||||
std::vector<int> IntShmDims;
|
||||
GridCmdOptionIntVector(std::string(str),IntShmDims);
|
||||
assert(IntShmDims.size() == WorldDims.size());
|
||||
long ShmSize = 1;
|
||||
for (int dim=0;dim<WorldDims.size();dim++) {
|
||||
ShmSize *= (ShmDims[dim] = IntShmDims[dim]);
|
||||
assert(divides(ShmDims[dim],WorldDims[dim]));
|
||||
}
|
||||
assert(ShmSize == WorldShmSize);
|
||||
return;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Powers of 2,3,5 only in prime decomposition for now
|
||||
////////////////////////////////////////////////////////////////
|
||||
int ndimension = WorldDims.size();
|
||||
ShmDims=Coordinate(ndimension,1);
|
||||
|
||||
std::vector<int> primes({2,3,5});
|
||||
|
||||
int dim = 0;
|
||||
int last_dim = ndimension - 1;
|
||||
int AutoShmSize = 1;
|
||||
while(AutoShmSize != WorldShmSize) {
|
||||
int p;
|
||||
for(p=0;p<primes.size();p++) {
|
||||
int prime=primes[p];
|
||||
if ( divides(prime,WorldDims[dim]/ShmDims[dim])
|
||||
&& divides(prime,WorldShmSize/AutoShmSize) ) {
|
||||
AutoShmSize*=prime;
|
||||
ShmDims[dim]*=prime;
|
||||
last_dim = dim;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == primes.size() && last_dim == dim) {
|
||||
std::cerr << "GlobalSharedMemory::GetShmDims failed" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
dim=(dim+1) %ndimension;
|
||||
}
|
||||
}
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
|
@ -27,9 +27,10 @@ Author: Christoph Lehner <christoph@lhnr.de>
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
|
||||
#define Mheader "SharedMemoryMpi: "
|
||||
|
||||
#include <Grid/GridCore.h>
|
||||
#include <pwd.h>
|
||||
#include <syscall.h>
|
||||
|
||||
#ifdef GRID_CUDA
|
||||
#include <cuda_runtime_api.h>
|
||||
@ -39,11 +40,118 @@ Author: Christoph Lehner <christoph@lhnr.de>
|
||||
#endif
|
||||
#ifdef GRID_SYCL
|
||||
#define GRID_SYCL_LEVEL_ZERO_IPC
|
||||
#include <syscall.h>
|
||||
#define SHM_SOCKETS
|
||||
#endif
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
#ifdef SHM_SOCKETS
|
||||
|
||||
/*
|
||||
* Barbaric extra intranode communication route in case we need sockets to pass FDs
|
||||
* Forced by level_zero not being nicely designed
|
||||
*/
|
||||
static int sock;
|
||||
static const char *sock_path_fmt = "/tmp/GridUnixSocket.%d";
|
||||
static char sock_path[256];
|
||||
class UnixSockets {
|
||||
public:
|
||||
static void Open(int rank)
|
||||
{
|
||||
int errnum;
|
||||
|
||||
sock = socket(AF_UNIX, SOCK_DGRAM, 0); assert(sock>0);
|
||||
|
||||
struct sockaddr_un sa_un = { 0 };
|
||||
sa_un.sun_family = AF_UNIX;
|
||||
snprintf(sa_un.sun_path, sizeof(sa_un.sun_path),sock_path_fmt,rank);
|
||||
unlink(sa_un.sun_path);
|
||||
if (bind(sock, (struct sockaddr *)&sa_un, sizeof(sa_un))) {
|
||||
perror("bind failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
static int RecvFileDescriptor(void)
|
||||
{
|
||||
int n;
|
||||
int fd;
|
||||
char buf[1];
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
struct cmsghdr *cmsg;
|
||||
char cms[CMSG_SPACE(sizeof(int))];
|
||||
|
||||
iov.iov_base = buf;
|
||||
iov.iov_len = 1;
|
||||
|
||||
memset(&msg, 0, sizeof msg);
|
||||
msg.msg_name = 0;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
msg.msg_control = (caddr_t)cms;
|
||||
msg.msg_controllen = sizeof cms;
|
||||
|
||||
if((n=recvmsg(sock, &msg, 0)) < 0) {
|
||||
perror("recvmsg failed");
|
||||
return -1;
|
||||
}
|
||||
if(n == 0){
|
||||
perror("recvmsg returned 0");
|
||||
return -1;
|
||||
}
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
|
||||
memmove(&fd, CMSG_DATA(cmsg), sizeof(int));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void SendFileDescriptor(int fildes,int xmit_to_rank)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
struct cmsghdr *cmsg = NULL;
|
||||
char ctrl[CMSG_SPACE(sizeof(int))];
|
||||
char data = ' ';
|
||||
|
||||
memset(&msg, 0, sizeof(struct msghdr));
|
||||
memset(ctrl, 0, CMSG_SPACE(sizeof(int)));
|
||||
iov.iov_base = &data;
|
||||
iov.iov_len = sizeof(data);
|
||||
|
||||
sprintf(sock_path,sock_path_fmt,xmit_to_rank);
|
||||
|
||||
struct sockaddr_un sa_un = { 0 };
|
||||
sa_un.sun_family = AF_UNIX;
|
||||
snprintf(sa_un.sun_path, sizeof(sa_un.sun_path),sock_path_fmt,xmit_to_rank);
|
||||
|
||||
msg.msg_name = (void *)&sa_un;
|
||||
msg.msg_namelen = sizeof(sa_un);
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(int));
|
||||
msg.msg_control = ctrl;
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_RIGHTS;
|
||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
|
||||
*((int *) CMSG_DATA(cmsg)) = fildes;
|
||||
|
||||
sendmsg(sock, &msg, 0);
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
#define header "SharedMemoryMpi: "
|
||||
/*Construct from an MPI communicator*/
|
||||
void GlobalSharedMemory::Init(Grid_MPI_Comm comm)
|
||||
{
|
||||
@ -66,8 +174,8 @@ void GlobalSharedMemory::Init(Grid_MPI_Comm comm)
|
||||
MPI_Comm_size(WorldShmComm ,&WorldShmSize);
|
||||
|
||||
if ( WorldRank == 0) {
|
||||
std::cout << header " World communicator of size " <<WorldSize << std::endl;
|
||||
std::cout << header " Node communicator of size " <<WorldShmSize << std::endl;
|
||||
std::cout << Mheader " World communicator of size " <<WorldSize << std::endl;
|
||||
std::cout << Mheader " Node communicator of size " <<WorldShmSize << std::endl;
|
||||
}
|
||||
// WorldShmComm, WorldShmSize, WorldShmRank
|
||||
|
||||
@ -170,59 +278,7 @@ void GlobalSharedMemory::OptimalCommunicator(const Coordinate &processors,Grid_M
|
||||
if(nscan==3 && HPEhypercube ) OptimalCommunicatorHypercube(processors,optimal_comm,SHM);
|
||||
else OptimalCommunicatorSharedMemory(processors,optimal_comm,SHM);
|
||||
}
|
||||
static inline int divides(int a,int b)
|
||||
{
|
||||
return ( b == ( (b/a)*a ) );
|
||||
}
|
||||
void GlobalSharedMemory::GetShmDims(const Coordinate &WorldDims,Coordinate &ShmDims)
|
||||
{
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Allow user to configure through environment variable
|
||||
////////////////////////////////////////////////////////////////
|
||||
char* str = getenv(("GRID_SHM_DIMS_" + std::to_string(ShmDims.size())).c_str());
|
||||
if ( str ) {
|
||||
std::vector<int> IntShmDims;
|
||||
GridCmdOptionIntVector(std::string(str),IntShmDims);
|
||||
assert(IntShmDims.size() == WorldDims.size());
|
||||
long ShmSize = 1;
|
||||
for (int dim=0;dim<WorldDims.size();dim++) {
|
||||
ShmSize *= (ShmDims[dim] = IntShmDims[dim]);
|
||||
assert(divides(ShmDims[dim],WorldDims[dim]));
|
||||
}
|
||||
assert(ShmSize == WorldShmSize);
|
||||
return;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Powers of 2,3,5 only in prime decomposition for now
|
||||
////////////////////////////////////////////////////////////////
|
||||
int ndimension = WorldDims.size();
|
||||
ShmDims=Coordinate(ndimension,1);
|
||||
|
||||
std::vector<int> primes({2,3,5});
|
||||
|
||||
int dim = 0;
|
||||
int last_dim = ndimension - 1;
|
||||
int AutoShmSize = 1;
|
||||
while(AutoShmSize != WorldShmSize) {
|
||||
int p;
|
||||
for(p=0;p<primes.size();p++) {
|
||||
int prime=primes[p];
|
||||
if ( divides(prime,WorldDims[dim]/ShmDims[dim])
|
||||
&& divides(prime,WorldShmSize/AutoShmSize) ) {
|
||||
AutoShmSize*=prime;
|
||||
ShmDims[dim]*=prime;
|
||||
last_dim = dim;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == primes.size() && last_dim == dim) {
|
||||
std::cerr << "GlobalSharedMemory::GetShmDims failed" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
dim=(dim+1) %ndimension;
|
||||
}
|
||||
}
|
||||
void GlobalSharedMemory::OptimalCommunicatorHypercube(const Coordinate &processors,Grid_MPI_Comm & optimal_comm,Coordinate &SHM)
|
||||
{
|
||||
////////////////////////////////////////////////////////////////
|
||||
@ -396,7 +452,7 @@ void GlobalSharedMemory::OptimalCommunicatorSharedMemory(const Coordinate &proce
|
||||
#ifdef GRID_MPI3_SHMGET
|
||||
void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
{
|
||||
std::cout << header "SharedMemoryAllocate "<< bytes<< " shmget implementation "<<std::endl;
|
||||
std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " shmget implementation "<<std::endl;
|
||||
assert(_ShmSetup==1);
|
||||
assert(_ShmAlloc==0);
|
||||
|
||||
@ -481,7 +537,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << WorldRank << header " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes
|
||||
std::cout << WorldRank << Mheader " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes
|
||||
<< "bytes at "<< std::hex<< ShmCommBuf <<std::dec<<" for comms buffers " <<std::endl;
|
||||
|
||||
SharedMemoryZero(ShmCommBuf,bytes);
|
||||
@ -524,7 +580,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ( WorldRank == 0 ){
|
||||
std::cout << WorldRank << header " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes
|
||||
std::cout << WorldRank << Mheader " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes
|
||||
<< "bytes at "<< std::hex<< ShmCommBuf << " - "<<(bytes-1+(uint64_t)ShmCommBuf) <<std::dec<<" for comms buffers " <<std::endl;
|
||||
}
|
||||
SharedMemoryZero(ShmCommBuf,bytes);
|
||||
@ -532,8 +588,13 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Loop over ranks/gpu's on our node
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef SHM_SOCKETS
|
||||
UnixSockets::Open(WorldShmRank);
|
||||
#endif
|
||||
for(int r=0;r<WorldShmSize;r++){
|
||||
|
||||
MPI_Barrier(WorldShmComm);
|
||||
|
||||
#ifndef GRID_MPI3_SHM_NONE
|
||||
//////////////////////////////////////////////////
|
||||
// If it is me, pass around the IPC access key
|
||||
@ -541,24 +602,32 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
void * thisBuf = ShmCommBuf;
|
||||
if(!Stencil_force_mpi) {
|
||||
#ifdef GRID_SYCL_LEVEL_ZERO_IPC
|
||||
typedef struct { int fd; pid_t pid ; } clone_mem_t;
|
||||
typedef struct { int fd; pid_t pid ; ze_ipc_mem_handle_t ze; } clone_mem_t;
|
||||
|
||||
auto zeDevice = cl::sycl::get_native<cl::sycl::backend::level_zero>(theGridAccelerator->get_device());
|
||||
auto zeContext = cl::sycl::get_native<cl::sycl::backend::level_zero>(theGridAccelerator->get_context());
|
||||
auto zeDevice = cl::sycl::get_native<cl::sycl::backend::ext_oneapi_level_zero>(theGridAccelerator->get_device());
|
||||
auto zeContext = cl::sycl::get_native<cl::sycl::backend::ext_oneapi_level_zero>(theGridAccelerator->get_context());
|
||||
|
||||
ze_ipc_mem_handle_t ihandle;
|
||||
clone_mem_t handle;
|
||||
|
||||
|
||||
if ( r==WorldShmRank ) {
|
||||
auto err = zeMemGetIpcHandle(zeContext,ShmCommBuf,&ihandle);
|
||||
if ( err != ZE_RESULT_SUCCESS ) {
|
||||
std::cout << "SharedMemoryMPI.cc zeMemGetIpcHandle failed for rank "<<r<<" "<<std::hex<<err<<std::dec<<std::endl;
|
||||
std::cerr << "SharedMemoryMPI.cc zeMemGetIpcHandle failed for rank "<<r<<" "<<std::hex<<err<<std::dec<<std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
std::cout << "SharedMemoryMPI.cc zeMemGetIpcHandle succeeded for rank "<<r<<" "<<std::hex<<err<<std::dec<<std::endl;
|
||||
}
|
||||
memcpy((void *)&handle.fd,(void *)&ihandle,sizeof(int));
|
||||
handle.pid = getpid();
|
||||
memcpy((void *)&handle.ze,(void *)&ihandle,sizeof(ihandle));
|
||||
#ifdef SHM_SOCKETS
|
||||
for(int rr=0;rr<WorldShmSize;rr++){
|
||||
if(rr!=r){
|
||||
UnixSockets::SendFileDescriptor(handle.fd,rr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef GRID_CUDA
|
||||
@ -586,6 +655,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
// Share this IPC handle across the Shm Comm
|
||||
//////////////////////////////////////////////////
|
||||
{
|
||||
MPI_Barrier(WorldShmComm);
|
||||
int ierr=MPI_Bcast(&handle,
|
||||
sizeof(handle),
|
||||
MPI_BYTE,
|
||||
@ -601,6 +671,10 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
#ifdef GRID_SYCL_LEVEL_ZERO_IPC
|
||||
if ( r!=WorldShmRank ) {
|
||||
thisBuf = nullptr;
|
||||
int myfd;
|
||||
#ifdef SHM_SOCKETS
|
||||
myfd=UnixSockets::RecvFileDescriptor();
|
||||
#else
|
||||
std::cout<<"mapping seeking remote pid/fd "
|
||||
<<handle.pid<<"/"
|
||||
<<handle.fd<<std::endl;
|
||||
@ -608,16 +682,22 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
int pidfd = syscall(SYS_pidfd_open,handle.pid,0);
|
||||
std::cout<<"Using IpcHandle pidfd "<<pidfd<<"\n";
|
||||
// int myfd = syscall(SYS_pidfd_getfd,pidfd,handle.fd,0);
|
||||
int myfd = syscall(438,pidfd,handle.fd,0);
|
||||
|
||||
std::cout<<"Using IpcHandle myfd "<<myfd<<"\n";
|
||||
|
||||
myfd = syscall(438,pidfd,handle.fd,0);
|
||||
int err_t = errno;
|
||||
if (myfd < 0) {
|
||||
fprintf(stderr,"pidfd_getfd returned %d errno was %d\n", myfd,err_t); fflush(stderr);
|
||||
perror("pidfd_getfd failed ");
|
||||
assert(0);
|
||||
}
|
||||
#endif
|
||||
std::cout<<"Using IpcHandle mapped remote pid "<<handle.pid <<" FD "<<handle.fd <<" to myfd "<<myfd<<"\n";
|
||||
memcpy((void *)&ihandle,(void *)&handle.ze,sizeof(ihandle));
|
||||
memcpy((void *)&ihandle,(void *)&myfd,sizeof(int));
|
||||
|
||||
auto err = zeMemOpenIpcHandle(zeContext,zeDevice,ihandle,0,&thisBuf);
|
||||
if ( err != ZE_RESULT_SUCCESS ) {
|
||||
std::cout << "SharedMemoryMPI.cc "<<zeContext<<" "<<zeDevice<<std::endl;
|
||||
std::cout << "SharedMemoryMPI.cc zeMemOpenIpcHandle failed for rank "<<r<<" "<<std::hex<<err<<std::dec<<std::endl;
|
||||
std::cerr << "SharedMemoryMPI.cc "<<zeContext<<" "<<zeDevice<<std::endl;
|
||||
std::cerr << "SharedMemoryMPI.cc zeMemOpenIpcHandle failed for rank "<<r<<" "<<std::hex<<err<<std::dec<<std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
std::cout << "SharedMemoryMPI.cc zeMemOpenIpcHandle succeeded for rank "<<r<<std::endl;
|
||||
@ -652,6 +732,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
#else
|
||||
WorldShmCommBufs[r] = ShmCommBuf;
|
||||
#endif
|
||||
MPI_Barrier(WorldShmComm);
|
||||
}
|
||||
|
||||
_ShmAllocBytes=bytes;
|
||||
@ -663,7 +744,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
#ifdef GRID_MPI3_SHMMMAP
|
||||
void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
{
|
||||
std::cout << header "SharedMemoryAllocate "<< bytes<< " MMAP implementation "<< GRID_SHM_PATH <<std::endl;
|
||||
std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " MMAP implementation "<< GRID_SHM_PATH <<std::endl;
|
||||
assert(_ShmSetup==1);
|
||||
assert(_ShmAlloc==0);
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -700,7 +781,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
assert(((uint64_t)ptr&0x3F)==0);
|
||||
close(fd);
|
||||
WorldShmCommBufs[r] =ptr;
|
||||
// std::cout << header "Set WorldShmCommBufs["<<r<<"]="<<ptr<< "("<< bytes<< "bytes)"<<std::endl;
|
||||
// std::cout << Mheader "Set WorldShmCommBufs["<<r<<"]="<<ptr<< "("<< bytes<< "bytes)"<<std::endl;
|
||||
}
|
||||
_ShmAlloc=1;
|
||||
_ShmAllocBytes = bytes;
|
||||
@ -710,7 +791,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
#ifdef GRID_MPI3_SHM_NONE
|
||||
void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
{
|
||||
std::cout << header "SharedMemoryAllocate "<< bytes<< " MMAP anonymous implementation "<<std::endl;
|
||||
std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " MMAP anonymous implementation "<<std::endl;
|
||||
assert(_ShmSetup==1);
|
||||
assert(_ShmAlloc==0);
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -757,7 +838,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags)
|
||||
{
|
||||
std::cout << header "SharedMemoryAllocate "<< bytes<< " SHMOPEN implementation "<<std::endl;
|
||||
std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " SHMOPEN implementation "<<std::endl;
|
||||
assert(_ShmSetup==1);
|
||||
assert(_ShmAlloc==0);
|
||||
MPI_Barrier(WorldShmComm);
|
||||
|
@ -47,3 +47,4 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
#include <Grid/lattice/Lattice_transfer.h>
|
||||
#include <Grid/lattice/Lattice_basis.h>
|
||||
#include <Grid/lattice/Lattice_crc.h>
|
||||
#include <Grid/lattice/PaddedCell.h>
|
||||
|
@ -345,7 +345,9 @@ GridUnopClass(UnaryNot, Not(a));
|
||||
GridUnopClass(UnaryTrace, trace(a));
|
||||
GridUnopClass(UnaryTranspose, transpose(a));
|
||||
GridUnopClass(UnaryTa, Ta(a));
|
||||
GridUnopClass(UnarySpTa, SpTa(a));
|
||||
GridUnopClass(UnaryProjectOnGroup, ProjectOnGroup(a));
|
||||
GridUnopClass(UnaryProjectOnSpGroup, ProjectOnSpGroup(a));
|
||||
GridUnopClass(UnaryTimesI, timesI(a));
|
||||
GridUnopClass(UnaryTimesMinusI, timesMinusI(a));
|
||||
GridUnopClass(UnaryAbs, abs(a));
|
||||
@ -456,7 +458,9 @@ GRID_DEF_UNOP(operator!, UnaryNot);
|
||||
GRID_DEF_UNOP(trace, UnaryTrace);
|
||||
GRID_DEF_UNOP(transpose, UnaryTranspose);
|
||||
GRID_DEF_UNOP(Ta, UnaryTa);
|
||||
GRID_DEF_UNOP(SpTa, UnarySpTa);
|
||||
GRID_DEF_UNOP(ProjectOnGroup, UnaryProjectOnGroup);
|
||||
GRID_DEF_UNOP(ProjectOnSpGroup, UnaryProjectOnSpGroup);
|
||||
GRID_DEF_UNOP(timesI, UnaryTimesI);
|
||||
GRID_DEF_UNOP(timesMinusI, UnaryTimesMinusI);
|
||||
GRID_DEF_UNOP(abs, UnaryAbs); // abs overloaded in cmath C++98; DON'T do the
|
||||
|
@ -66,6 +66,65 @@ inline auto TraceIndex(const Lattice<vobj> &lhs) -> Lattice<decltype(traceIndex<
|
||||
return ret;
|
||||
};
|
||||
|
||||
template<int N, class Vec>
|
||||
Lattice<iScalar<iScalar<iScalar<Vec> > > > Determinant(const Lattice<iScalar<iScalar<iMatrix<Vec, N> > > > &Umu)
|
||||
{
|
||||
GridBase *grid=Umu.Grid();
|
||||
auto lvol = grid->lSites();
|
||||
Lattice<iScalar<iScalar<iScalar<Vec> > > > ret(grid);
|
||||
typedef typename Vec::scalar_type scalar;
|
||||
autoView(Umu_v,Umu,CpuRead);
|
||||
autoView(ret_v,ret,CpuWrite);
|
||||
thread_for(site,lvol,{
|
||||
Eigen::MatrixXcd EigenU = Eigen::MatrixXcd::Zero(N,N);
|
||||
Coordinate lcoor;
|
||||
grid->LocalIndexToLocalCoor(site, lcoor);
|
||||
iScalar<iScalar<iMatrix<scalar, N> > > Us;
|
||||
peekLocalSite(Us, Umu_v, lcoor);
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
scalar tmp= Us()()(i,j);
|
||||
ComplexD ztmp(real(tmp),imag(tmp));
|
||||
EigenU(i,j)=ztmp;
|
||||
}}
|
||||
ComplexD detD = EigenU.determinant();
|
||||
typename Vec::scalar_type det(detD.real(),detD.imag());
|
||||
pokeLocalSite(det,ret_v,lcoor);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > Inverse(const Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > &Umu)
|
||||
{
|
||||
GridBase *grid=Umu.Grid();
|
||||
auto lvol = grid->lSites();
|
||||
Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > ret(grid);
|
||||
|
||||
autoView(Umu_v,Umu,CpuRead);
|
||||
autoView(ret_v,ret,CpuWrite);
|
||||
thread_for(site,lvol,{
|
||||
Eigen::MatrixXcd EigenU = Eigen::MatrixXcd::Zero(N,N);
|
||||
Coordinate lcoor;
|
||||
grid->LocalIndexToLocalCoor(site, lcoor);
|
||||
iScalar<iScalar<iMatrix<ComplexD, N> > > Us;
|
||||
iScalar<iScalar<iMatrix<ComplexD, N> > > Ui;
|
||||
peekLocalSite(Us, Umu_v, lcoor);
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
EigenU(i,j) = Us()()(i,j);
|
||||
}}
|
||||
Eigen::MatrixXcd EigenUinv = EigenU.inverse();
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
Ui()()(i,j) = EigenUinv(i,j);
|
||||
}}
|
||||
pokeLocalSite(Ui,ret_v,lcoor);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
#endif
|
||||
|
||||
|
@ -697,8 +697,68 @@ void localCopyRegion(const Lattice<vobj> &From,Lattice<vobj> & To,Coordinate Fro
|
||||
for(int d=0;d<nd;d++){
|
||||
assert(Fg->_processors[d] == Tg->_processors[d]);
|
||||
}
|
||||
|
||||
// the above should guarantee that the operations are local
|
||||
|
||||
#if 1
|
||||
|
||||
size_t nsite = 1;
|
||||
for(int i=0;i<nd;i++) nsite *= RegionSize[i];
|
||||
|
||||
size_t tbytes = 4*nsite*sizeof(int);
|
||||
int *table = (int*)malloc(tbytes);
|
||||
|
||||
thread_for(idx, nsite, {
|
||||
Coordinate from_coor, to_coor;
|
||||
size_t rem = idx;
|
||||
for(int i=0;i<nd;i++){
|
||||
size_t base_i = rem % RegionSize[i]; rem /= RegionSize[i];
|
||||
from_coor[i] = base_i + FromLowerLeft[i];
|
||||
to_coor[i] = base_i + ToLowerLeft[i];
|
||||
}
|
||||
|
||||
int foidx = Fg->oIndex(from_coor);
|
||||
int fiidx = Fg->iIndex(from_coor);
|
||||
int toidx = Tg->oIndex(to_coor);
|
||||
int tiidx = Tg->iIndex(to_coor);
|
||||
int* tt = table + 4*idx;
|
||||
tt[0] = foidx;
|
||||
tt[1] = fiidx;
|
||||
tt[2] = toidx;
|
||||
tt[3] = tiidx;
|
||||
});
|
||||
|
||||
int* table_d = (int*)acceleratorAllocDevice(tbytes);
|
||||
acceleratorCopyToDevice(table,table_d,tbytes);
|
||||
|
||||
typedef typename vobj::vector_type vector_type;
|
||||
typedef typename vobj::scalar_type scalar_type;
|
||||
|
||||
autoView(from_v,From,AcceleratorRead);
|
||||
autoView(to_v,To,AcceleratorWrite);
|
||||
|
||||
accelerator_for(idx,nsite,1,{
|
||||
static const int words=sizeof(vobj)/sizeof(vector_type);
|
||||
int* tt = table_d + 4*idx;
|
||||
int from_oidx = *tt++;
|
||||
int from_lane = *tt++;
|
||||
int to_oidx = *tt++;
|
||||
int to_lane = *tt;
|
||||
|
||||
const vector_type* from = (const vector_type *)&from_v[from_oidx];
|
||||
vector_type* to = (vector_type *)&to_v[to_oidx];
|
||||
|
||||
scalar_type stmp;
|
||||
for(int w=0;w<words;w++){
|
||||
stmp = getlane(from[w], from_lane);
|
||||
putlane(to[w], stmp, to_lane);
|
||||
}
|
||||
});
|
||||
|
||||
acceleratorFreeDevice(table_d);
|
||||
free(table);
|
||||
|
||||
|
||||
#else
|
||||
Coordinate ldf = Fg->_ldimensions;
|
||||
Coordinate rdf = Fg->_rdimensions;
|
||||
Coordinate isf = Fg->_istride;
|
||||
@ -707,9 +767,9 @@ void localCopyRegion(const Lattice<vobj> &From,Lattice<vobj> & To,Coordinate Fro
|
||||
Coordinate ist = Tg->_istride;
|
||||
Coordinate ost = Tg->_ostride;
|
||||
|
||||
autoView( t_v , To, AcceleratorWrite);
|
||||
autoView( f_v , From, AcceleratorRead);
|
||||
accelerator_for(idx,Fg->lSites(),1,{
|
||||
autoView( t_v , To, CpuWrite);
|
||||
autoView( f_v , From, CpuRead);
|
||||
thread_for(idx,Fg->lSites(),{
|
||||
sobj s;
|
||||
Coordinate Fcoor(nd);
|
||||
Coordinate Tcoor(nd);
|
||||
@ -722,17 +782,24 @@ void localCopyRegion(const Lattice<vobj> &From,Lattice<vobj> & To,Coordinate Fro
|
||||
Tcoor[d] = ToLowerLeft[d]+ Fcoor[d]-FromLowerLeft[d];
|
||||
}
|
||||
if (in_region) {
|
||||
Integer idx_f = 0; for(int d=0;d<nd;d++) idx_f+=isf[d]*(Fcoor[d]/rdf[d]);
|
||||
Integer idx_t = 0; for(int d=0;d<nd;d++) idx_t+=ist[d]*(Tcoor[d]/rdt[d]);
|
||||
Integer odx_f = 0; for(int d=0;d<nd;d++) odx_f+=osf[d]*(Fcoor[d]%rdf[d]);
|
||||
Integer odx_t = 0; for(int d=0;d<nd;d++) odx_t+=ost[d]*(Tcoor[d]%rdt[d]);
|
||||
vector_type * fp = (vector_type *)&f_v[odx_f];
|
||||
vector_type * tp = (vector_type *)&t_v[odx_t];
|
||||
#if 0
|
||||
Integer idx_f = 0; for(int d=0;d<nd;d++) idx_f+=isf[d]*(Fcoor[d]/rdf[d]); // inner index from
|
||||
Integer idx_t = 0; for(int d=0;d<nd;d++) idx_t+=ist[d]*(Tcoor[d]/rdt[d]); // inner index to
|
||||
Integer odx_f = 0; for(int d=0;d<nd;d++) odx_f+=osf[d]*(Fcoor[d]%rdf[d]); // outer index from
|
||||
Integer odx_t = 0; for(int d=0;d<nd;d++) odx_t+=ost[d]*(Tcoor[d]%rdt[d]); // outer index to
|
||||
scalar_type * fp = (scalar_type *)&f_v[odx_f];
|
||||
scalar_type * tp = (scalar_type *)&t_v[odx_t];
|
||||
for(int w=0;w<words;w++){
|
||||
tp[w].putlane(fp[w].getlane(idx_f),idx_t);
|
||||
}
|
||||
#else
|
||||
peekLocalSite(s,f_v,Fcoor);
|
||||
pokeLocalSite(s,t_v,Tcoor);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -825,6 +892,8 @@ void ExtractSlice(Lattice<vobj> &lowDim,const Lattice<vobj> & higherDim,int slic
|
||||
}
|
||||
|
||||
|
||||
//Insert subvolume orthogonal to direction 'orthog' with slice index 'slice_lo' from 'lowDim' onto slice index 'slice_hi' of higherDim
|
||||
//The local dimensions of both 'lowDim' and 'higherDim' orthogonal to 'orthog' should be the same
|
||||
template<class vobj>
|
||||
void InsertSliceLocal(const Lattice<vobj> &lowDim, Lattice<vobj> & higherDim,int slice_lo,int slice_hi, int orthog)
|
||||
{
|
||||
@ -841,11 +910,70 @@ void InsertSliceLocal(const Lattice<vobj> &lowDim, Lattice<vobj> & higherDim,int
|
||||
|
||||
for(int d=0;d<nh;d++){
|
||||
if ( d!=orthog ) {
|
||||
assert(lg->_processors[d] == hg->_processors[d]);
|
||||
assert(lg->_ldimensions[d] == hg->_ldimensions[d]);
|
||||
}
|
||||
assert(lg->_processors[d] == hg->_processors[d]);
|
||||
assert(lg->_ldimensions[d] == hg->_ldimensions[d]);
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
size_t nsite = lg->lSites()/lg->LocalDimensions()[orthog];
|
||||
size_t tbytes = 4*nsite*sizeof(int);
|
||||
int *table = (int*)malloc(tbytes);
|
||||
|
||||
thread_for(idx,nsite,{
|
||||
Coordinate lcoor(nl);
|
||||
Coordinate hcoor(nh);
|
||||
lcoor[orthog] = slice_lo;
|
||||
hcoor[orthog] = slice_hi;
|
||||
size_t rem = idx;
|
||||
for(int mu=0;mu<nl;mu++){
|
||||
if(mu != orthog){
|
||||
int xmu = rem % lg->LocalDimensions()[mu]; rem /= lg->LocalDimensions()[mu];
|
||||
lcoor[mu] = hcoor[mu] = xmu;
|
||||
}
|
||||
}
|
||||
int loidx = lg->oIndex(lcoor);
|
||||
int liidx = lg->iIndex(lcoor);
|
||||
int hoidx = hg->oIndex(hcoor);
|
||||
int hiidx = hg->iIndex(hcoor);
|
||||
int* tt = table + 4*idx;
|
||||
tt[0] = loidx;
|
||||
tt[1] = liidx;
|
||||
tt[2] = hoidx;
|
||||
tt[3] = hiidx;
|
||||
});
|
||||
|
||||
int* table_d = (int*)acceleratorAllocDevice(tbytes);
|
||||
acceleratorCopyToDevice(table,table_d,tbytes);
|
||||
|
||||
typedef typename vobj::vector_type vector_type;
|
||||
typedef typename vobj::scalar_type scalar_type;
|
||||
|
||||
autoView(lowDim_v,lowDim,AcceleratorRead);
|
||||
autoView(higherDim_v,higherDim,AcceleratorWrite);
|
||||
|
||||
accelerator_for(idx,nsite,1,{
|
||||
static const int words=sizeof(vobj)/sizeof(vector_type);
|
||||
int* tt = table_d + 4*idx;
|
||||
int from_oidx = *tt++;
|
||||
int from_lane = *tt++;
|
||||
int to_oidx = *tt++;
|
||||
int to_lane = *tt;
|
||||
|
||||
const vector_type* from = (const vector_type *)&lowDim_v[from_oidx];
|
||||
vector_type* to = (vector_type *)&higherDim_v[to_oidx];
|
||||
|
||||
scalar_type stmp;
|
||||
for(int w=0;w<words;w++){
|
||||
stmp = getlane(from[w], from_lane);
|
||||
putlane(to[w], stmp, to_lane);
|
||||
}
|
||||
});
|
||||
|
||||
acceleratorFreeDevice(table_d);
|
||||
free(table);
|
||||
|
||||
#else
|
||||
// the above should guarantee that the operations are local
|
||||
autoView(lowDimv,lowDim,CpuRead);
|
||||
autoView(higherDimv,higherDim,CpuWrite);
|
||||
@ -861,6 +989,7 @@ void InsertSliceLocal(const Lattice<vobj> &lowDim, Lattice<vobj> & higherDim,int
|
||||
pokeLocalSite(s,higherDimv,hcoor);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
174
Grid/lattice/PaddedCell.h
Normal file
174
Grid/lattice/PaddedCell.h
Normal file
@ -0,0 +1,174 @@
|
||||
/*************************************************************************************
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/lattice/PaddedCell.h
|
||||
|
||||
Copyright (C) 2019
|
||||
|
||||
Author: Peter Boyle pboyle@bnl.gov
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
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
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#pragma once
|
||||
|
||||
#include<Grid/cshift/Cshift.h>
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
//Allow the user to specify how the C-shift is performed, e.g. to respect the appropriate boundary conditions
|
||||
template<typename vobj>
|
||||
struct CshiftImplBase{
|
||||
virtual Lattice<vobj> Cshift(const Lattice<vobj> &in, int dir, int shift) const = 0;
|
||||
virtual ~CshiftImplBase(){}
|
||||
};
|
||||
template<typename vobj>
|
||||
struct CshiftImplDefault: public CshiftImplBase<vobj>{
|
||||
Lattice<vobj> Cshift(const Lattice<vobj> &in, int dir, int shift) const override{ return Grid::Cshift(in,dir,shift); }
|
||||
};
|
||||
template<typename Gimpl>
|
||||
struct CshiftImplGauge: public CshiftImplBase<typename Gimpl::GaugeLinkField::vector_object>{
|
||||
typename Gimpl::GaugeLinkField Cshift(const typename Gimpl::GaugeLinkField &in, int dir, int shift) const override{ return Gimpl::CshiftLink(in,dir,shift); }
|
||||
};
|
||||
|
||||
class PaddedCell {
|
||||
public:
|
||||
GridCartesian * unpadded_grid;
|
||||
int dims;
|
||||
int depth;
|
||||
std::vector<GridCartesian *> grids;
|
||||
|
||||
~PaddedCell()
|
||||
{
|
||||
DeleteGrids();
|
||||
}
|
||||
PaddedCell(int _depth,GridCartesian *_grid)
|
||||
{
|
||||
unpadded_grid = _grid;
|
||||
depth=_depth;
|
||||
dims=_grid->Nd();
|
||||
AllocateGrids();
|
||||
Coordinate local =unpadded_grid->LocalDimensions();
|
||||
for(int d=0;d<dims;d++){
|
||||
assert(local[d]>=depth);
|
||||
}
|
||||
}
|
||||
void DeleteGrids(void)
|
||||
{
|
||||
for(int d=0;d<grids.size();d++){
|
||||
delete grids[d];
|
||||
}
|
||||
grids.resize(0);
|
||||
};
|
||||
void AllocateGrids(void)
|
||||
{
|
||||
Coordinate local =unpadded_grid->LocalDimensions();
|
||||
Coordinate simd =unpadded_grid->_simd_layout;
|
||||
Coordinate processors=unpadded_grid->_processors;
|
||||
Coordinate plocal =unpadded_grid->LocalDimensions();
|
||||
Coordinate global(dims);
|
||||
|
||||
// expand up one dim at a time
|
||||
for(int d=0;d<dims;d++){
|
||||
|
||||
plocal[d] += 2*depth;
|
||||
|
||||
for(int d=0;d<dims;d++){
|
||||
global[d] = plocal[d]*processors[d];
|
||||
}
|
||||
|
||||
grids.push_back(new GridCartesian(global,simd,processors));
|
||||
}
|
||||
};
|
||||
template<class vobj>
|
||||
inline Lattice<vobj> Extract(const Lattice<vobj> &in) const
|
||||
{
|
||||
Lattice<vobj> out(unpadded_grid);
|
||||
|
||||
Coordinate local =unpadded_grid->LocalDimensions();
|
||||
Coordinate fll(dims,depth); // depends on the MPI spread
|
||||
Coordinate tll(dims,0); // depends on the MPI spread
|
||||
localCopyRegion(in,out,fll,tll,local);
|
||||
return out;
|
||||
}
|
||||
template<class vobj>
|
||||
inline Lattice<vobj> Exchange(const Lattice<vobj> &in, const CshiftImplBase<vobj> &cshift = CshiftImplDefault<vobj>()) const
|
||||
{
|
||||
GridBase *old_grid = in.Grid();
|
||||
int dims = old_grid->Nd();
|
||||
Lattice<vobj> tmp = in;
|
||||
for(int d=0;d<dims;d++){
|
||||
tmp = Expand(d,tmp,cshift); // rvalue && assignment
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
// expand up one dim at a time
|
||||
template<class vobj>
|
||||
inline Lattice<vobj> Expand(int dim, const Lattice<vobj> &in, const CshiftImplBase<vobj> &cshift = CshiftImplDefault<vobj>()) const
|
||||
{
|
||||
GridBase *old_grid = in.Grid();
|
||||
GridCartesian *new_grid = grids[dim];//These are new grids
|
||||
Lattice<vobj> padded(new_grid);
|
||||
Lattice<vobj> shifted(old_grid);
|
||||
Coordinate local =old_grid->LocalDimensions();
|
||||
Coordinate plocal =new_grid->LocalDimensions();
|
||||
if(dim==0) conformable(old_grid,unpadded_grid);
|
||||
else conformable(old_grid,grids[dim-1]);
|
||||
|
||||
std::cout << " dim "<<dim<<" local "<<local << " padding to "<<plocal<<std::endl;
|
||||
|
||||
double tins=0, tshift=0;
|
||||
|
||||
// Middle bit
|
||||
double t = usecond();
|
||||
for(int x=0;x<local[dim];x++){
|
||||
InsertSliceLocal(in,padded,x,depth+x,dim);
|
||||
}
|
||||
tins += usecond() - t;
|
||||
|
||||
// High bit
|
||||
t = usecond();
|
||||
shifted = cshift.Cshift(in,dim,depth);
|
||||
tshift += usecond() - t;
|
||||
|
||||
t=usecond();
|
||||
for(int x=0;x<depth;x++){
|
||||
InsertSliceLocal(shifted,padded,local[dim]-depth+x,depth+local[dim]+x,dim);
|
||||
}
|
||||
tins += usecond() - t;
|
||||
|
||||
// Low bit
|
||||
t = usecond();
|
||||
shifted = cshift.Cshift(in,dim,-depth);
|
||||
tshift += usecond() - t;
|
||||
|
||||
t = usecond();
|
||||
for(int x=0;x<depth;x++){
|
||||
InsertSliceLocal(shifted,padded,x,x,dim);
|
||||
}
|
||||
tins += usecond() - t;
|
||||
|
||||
std::cout << GridLogPerformance << "PaddedCell::Expand timings: cshift:" << tshift/1000 << "ms, insert-slice:" << tins/1000 << "ms" << std::endl;
|
||||
|
||||
return padded;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
@ -104,6 +104,7 @@ template<typename vtype> using iSpinMatrix = iScalar<iMatrix<iSca
|
||||
template<typename vtype> using iColourMatrix = iScalar<iScalar<iMatrix<vtype, Nc> > > ;
|
||||
template<typename vtype> using iSpinColourMatrix = iScalar<iMatrix<iMatrix<vtype, Nc>, Ns> >;
|
||||
template<typename vtype> using iLorentzColourMatrix = iVector<iScalar<iMatrix<vtype, Nc> >, Nd > ;
|
||||
template<typename vtype> using iLorentzComplex = iVector<iScalar<iScalar<vtype> >, Nd > ;
|
||||
template<typename vtype> using iDoubleStoredColourMatrix = iVector<iScalar<iMatrix<vtype, Nc> >, Nds > ;
|
||||
template<typename vtype> using iSpinVector = iScalar<iVector<iScalar<vtype>, Ns> >;
|
||||
template<typename vtype> using iColourVector = iScalar<iScalar<iVector<vtype, Nc> > >;
|
||||
@ -178,6 +179,15 @@ typedef iLorentzColourMatrix<vComplexF> vLorentzColourMatrixF;
|
||||
typedef iLorentzColourMatrix<vComplexD> vLorentzColourMatrixD;
|
||||
typedef iLorentzColourMatrix<vComplexD2> vLorentzColourMatrixD2;
|
||||
|
||||
// LorentzComplex
|
||||
typedef iLorentzComplex<Complex > LorentzComplex;
|
||||
typedef iLorentzComplex<ComplexF > LorentzComplexF;
|
||||
typedef iLorentzComplex<ComplexD > LorentzComplexD;
|
||||
|
||||
typedef iLorentzComplex<vComplex > vLorentzComplex;
|
||||
typedef iLorentzComplex<vComplexF> vLorentzComplexF;
|
||||
typedef iLorentzComplex<vComplexD> vLorentzComplexD;
|
||||
|
||||
// DoubleStored gauge field
|
||||
typedef iDoubleStoredColourMatrix<Complex > DoubleStoredColourMatrix;
|
||||
typedef iDoubleStoredColourMatrix<ComplexF > DoubleStoredColourMatrixF;
|
||||
@ -307,6 +317,10 @@ typedef Lattice<vLorentzColourMatrixF> LatticeLorentzColourMatrixF;
|
||||
typedef Lattice<vLorentzColourMatrixD> LatticeLorentzColourMatrixD;
|
||||
typedef Lattice<vLorentzColourMatrixD2> LatticeLorentzColourMatrixD2;
|
||||
|
||||
typedef Lattice<vLorentzComplex> LatticeLorentzComplex;
|
||||
typedef Lattice<vLorentzComplexF> LatticeLorentzComplexF;
|
||||
typedef Lattice<vLorentzComplexD> LatticeLorentzComplexD;
|
||||
|
||||
// DoubleStored gauge field
|
||||
typedef Lattice<vDoubleStoredColourMatrix> LatticeDoubleStoredColourMatrix;
|
||||
typedef Lattice<vDoubleStoredColourMatrixF> LatticeDoubleStoredColourMatrixF;
|
||||
|
@ -34,10 +34,24 @@ directory
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
///////////////////////////////////
|
||||
// Smart configuration base class
|
||||
///////////////////////////////////
|
||||
template< class Field >
|
||||
class ConfigurationBase
|
||||
{
|
||||
public:
|
||||
ConfigurationBase() {}
|
||||
virtual ~ConfigurationBase() {}
|
||||
virtual void set_Field(Field& U) =0;
|
||||
virtual void smeared_force(Field&) = 0;
|
||||
virtual Field& get_SmearedU() =0;
|
||||
virtual Field &get_U(bool smeared = false) = 0;
|
||||
};
|
||||
|
||||
template <class GaugeField >
|
||||
class Action
|
||||
{
|
||||
|
||||
public:
|
||||
bool is_smeared = false;
|
||||
RealD deriv_norm_sum;
|
||||
@ -77,11 +91,39 @@ public:
|
||||
void refresh_timer_stop(void) { refresh_us+=usecond(); }
|
||||
void S_timer_start(void) { S_us-=usecond(); }
|
||||
void S_timer_stop(void) { S_us+=usecond(); }
|
||||
/////////////////////////////
|
||||
// Heatbath?
|
||||
/////////////////////////////
|
||||
virtual void refresh(const GaugeField& U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) = 0; // refresh pseudofermions
|
||||
virtual RealD S(const GaugeField& U) = 0; // evaluate the action
|
||||
virtual RealD Sinitial(const GaugeField& U) { return this->S(U); } ; // if the refresh computes the action, can cache it. Alternately refreshAndAction() ?
|
||||
virtual void deriv(const GaugeField& U, GaugeField& dSdU) = 0; // evaluate the action derivative
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// virtual smeared interface through configuration container
|
||||
/////////////////////////////////////////////////////////////
|
||||
virtual void refresh(ConfigurationBase<GaugeField> & U, GridSerialRNG &sRNG, GridParallelRNG& pRNG)
|
||||
{
|
||||
refresh(U.get_U(is_smeared),sRNG,pRNG);
|
||||
}
|
||||
virtual RealD S(ConfigurationBase<GaugeField>& U)
|
||||
{
|
||||
return S(U.get_U(is_smeared));
|
||||
}
|
||||
virtual RealD Sinitial(ConfigurationBase<GaugeField>& U)
|
||||
{
|
||||
return Sinitial(U.get_U(is_smeared));
|
||||
}
|
||||
virtual void deriv(ConfigurationBase<GaugeField>& U, GaugeField& dSdU)
|
||||
{
|
||||
deriv(U.get_U(is_smeared),dSdU);
|
||||
if ( is_smeared ) {
|
||||
U.smeared_force(dSdU);
|
||||
}
|
||||
}
|
||||
///////////////////////////////
|
||||
// Logging
|
||||
///////////////////////////////
|
||||
virtual std::string action_name() = 0; // return the action name
|
||||
virtual std::string LogParameters() = 0; // prints action parameters
|
||||
virtual ~Action(){}
|
||||
|
@ -30,6 +30,8 @@ directory
|
||||
#ifndef QCD_ACTION_CORE
|
||||
#define QCD_ACTION_CORE
|
||||
|
||||
#include <Grid/qcd/action/gauge/GaugeImplementations.h>
|
||||
|
||||
#include <Grid/qcd/action/ActionBase.h>
|
||||
NAMESPACE_CHECK(ActionBase);
|
||||
#include <Grid/qcd/action/ActionSet.h>
|
||||
@ -65,6 +67,7 @@ NAMESPACE_CHECK(Scalar);
|
||||
#include <Grid/qcd/utils/Metric.h>
|
||||
NAMESPACE_CHECK(Metric);
|
||||
#include <Grid/qcd/utils/CovariantLaplacian.h>
|
||||
#include <Grid/qcd/utils/CovariantLaplacianRat.h>
|
||||
NAMESPACE_CHECK(CovariantLaplacian);
|
||||
|
||||
|
||||
|
@ -65,6 +65,19 @@ struct WilsonImplParams {
|
||||
}
|
||||
};
|
||||
|
||||
struct GaugeImplParams {
|
||||
// bool overlapCommsCompute;
|
||||
// AcceleratorVector<Real,Nd> twist_n_2pi_L;
|
||||
AcceleratorVector<Complex,Nd> boundary_phases;
|
||||
GaugeImplParams() {
|
||||
boundary_phases.resize(Nd, 1.0);
|
||||
// twist_n_2pi_L.resize(Nd, 0.0);
|
||||
};
|
||||
GaugeImplParams(const AcceleratorVector<Complex,Nd> phi) : boundary_phases(phi) {
|
||||
// twist_n_2pi_L.resize(Nd, 0.0);
|
||||
}
|
||||
};
|
||||
|
||||
struct StaggeredImplParams {
|
||||
Coordinate dirichlet; // Blocksize of dirichlet BCs
|
||||
int partialDirichlet;
|
||||
|
@ -126,6 +126,16 @@ typedef WilsonFermion<WilsonTwoIndexSymmetricImplD> WilsonTwoIndexSymmetricFermi
|
||||
typedef WilsonFermion<WilsonTwoIndexAntiSymmetricImplF> WilsonTwoIndexAntiSymmetricFermionF;
|
||||
typedef WilsonFermion<WilsonTwoIndexAntiSymmetricImplD> WilsonTwoIndexAntiSymmetricFermionD;
|
||||
|
||||
// Sp(2n)
|
||||
typedef WilsonFermion<SpWilsonImplF> SpWilsonFermionF;
|
||||
typedef WilsonFermion<SpWilsonImplD> SpWilsonFermionD;
|
||||
|
||||
typedef WilsonFermion<SpWilsonTwoIndexAntiSymmetricImplF> SpWilsonTwoIndexAntiSymmetricFermionF;
|
||||
typedef WilsonFermion<SpWilsonTwoIndexAntiSymmetricImplD> SpWilsonTwoIndexAntiSymmetricFermionD;
|
||||
|
||||
typedef WilsonFermion<SpWilsonTwoIndexSymmetricImplF> SpWilsonTwoIndexSymmetricFermionF;
|
||||
typedef WilsonFermion<SpWilsonTwoIndexSymmetricImplD> SpWilsonTwoIndexSymmetricFermionD;
|
||||
|
||||
// Twisted mass fermion
|
||||
typedef WilsonTMFermion<WilsonImplD2> WilsonTMFermionD2;
|
||||
typedef WilsonTMFermion<WilsonImplF> WilsonTMFermionF;
|
||||
|
@ -507,6 +507,7 @@ public:
|
||||
}
|
||||
this->face_table_computed=1;
|
||||
assert(this->u_comm_offset==this->_unified_buffer_size);
|
||||
accelerator_barrier();
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -261,6 +261,22 @@ typedef WilsonImpl<vComplex, TwoIndexAntiSymmetricRepresentation, CoeffReal > W
|
||||
typedef WilsonImpl<vComplexF, TwoIndexAntiSymmetricRepresentation, CoeffReal > WilsonTwoIndexAntiSymmetricImplF; // Float
|
||||
typedef WilsonImpl<vComplexD, TwoIndexAntiSymmetricRepresentation, CoeffReal > WilsonTwoIndexAntiSymmetricImplD; // Double
|
||||
|
||||
//sp 2n
|
||||
|
||||
typedef WilsonImpl<vComplex, SpFundamentalRepresentation, CoeffReal > SpWilsonImplR; // Real.. whichever prec
|
||||
typedef WilsonImpl<vComplexF, SpFundamentalRepresentation, CoeffReal > SpWilsonImplF; // Float
|
||||
typedef WilsonImpl<vComplexD, SpFundamentalRepresentation, CoeffReal > SpWilsonImplD; // Double
|
||||
|
||||
typedef WilsonImpl<vComplex, SpTwoIndexAntiSymmetricRepresentation, CoeffReal > SpWilsonTwoIndexAntiSymmetricImplR; // Real.. whichever prec
|
||||
typedef WilsonImpl<vComplexF, SpTwoIndexAntiSymmetricRepresentation, CoeffReal > SpWilsonTwoIndexAntiSymmetricImplF; // Float
|
||||
typedef WilsonImpl<vComplexD, SpTwoIndexAntiSymmetricRepresentation, CoeffReal > SpWilsonTwoIndexAntiSymmetricImplD; // Double
|
||||
|
||||
typedef WilsonImpl<vComplex, SpTwoIndexSymmetricRepresentation, CoeffReal > SpWilsonTwoIndexSymmetricImplR; // Real.. whichever prec
|
||||
typedef WilsonImpl<vComplexF, SpTwoIndexSymmetricRepresentation, CoeffReal > SpWilsonTwoIndexSymmetricImplF; // Float
|
||||
typedef WilsonImpl<vComplexD, SpTwoIndexSymmetricRepresentation, CoeffReal > SpWilsonTwoIndexSymmetricImplD; // Double
|
||||
|
||||
typedef WilsonImpl<vComplex, SpTwoIndexSymmetricRepresentation, CoeffReal > SpWilsonAdjImplR; // Real.. whichever prec // adj = 2indx symmetric for Sp(2N)
|
||||
typedef WilsonImpl<vComplexF, SpTwoIndexSymmetricRepresentation, CoeffReal > SpWilsonAdjImplF; // Float // adj = 2indx symmetric for Sp(2N)
|
||||
typedef WilsonImpl<vComplexD, SpTwoIndexSymmetricRepresentation, CoeffReal > SpWilsonAdjImplD; // Double // adj = 2indx symmetric for Sp(2N)
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
|
@ -332,8 +332,7 @@ void WilsonFermion5D<Impl>::DhopInternalOverlappedComms(StencilImpl & st, Lebesg
|
||||
/////////////////////////////
|
||||
{
|
||||
GRID_TRACE("Gather");
|
||||
st.HaloExchangeOptGather(in,compressor);
|
||||
accelerator_barrier();
|
||||
st.HaloExchangeOptGather(in,compressor); // Put the barrier in the routine
|
||||
}
|
||||
|
||||
std::vector<std::vector<CommsRequest_t> > requests;
|
||||
|
@ -423,14 +423,14 @@ void WilsonKernels<Impl>::DhopDirKernel( StencilImpl &st, DoubledGaugeField &U,S
|
||||
#define KERNEL_CALL(A) KERNEL_CALLNB(A); accelerator_barrier();
|
||||
|
||||
#define KERNEL_CALL_EXT(A) \
|
||||
const uint64_t NN = Nsite*Ls; \
|
||||
const uint64_t sz = st.surface_list.size(); \
|
||||
auto ptr = &st.surface_list[0]; \
|
||||
accelerator_forNB( ss, sz, Simd::Nsimd(), { \
|
||||
int sF = ptr[ss]; \
|
||||
int sU = ss/Ls; \
|
||||
int sU = sF/Ls; \
|
||||
WilsonKernels<Impl>::A(st_v,U_v,buf,sF,sU,in_v,out_v); \
|
||||
});
|
||||
}); \
|
||||
accelerator_barrier();
|
||||
|
||||
#define ASM_CALL(A) \
|
||||
thread_for( sss, Nsite, { \
|
||||
@ -474,9 +474,10 @@ void WilsonKernels<Impl>::DhopKernel(int Opt,StencilImpl &st, DoubledGaugeField
|
||||
if (Opt == WilsonKernelsStatic::OptInlineAsm ) { ASM_CALL(AsmDhopSiteInt); return;}
|
||||
#endif
|
||||
} else if( exterior ) {
|
||||
// dependent on result of merge
|
||||
acceleratorFenceComputeStream();
|
||||
if (Opt == WilsonKernelsStatic::OptGeneric ) { KERNEL_CALL(GenericDhopSiteExt); return;}
|
||||
if (Opt == WilsonKernelsStatic::OptHandUnroll ) { KERNEL_CALL(HandDhopSiteExt); return;}
|
||||
if (Opt == WilsonKernelsStatic::OptGeneric ) { KERNEL_CALL_EXT(GenericDhopSiteExt); return;}
|
||||
if (Opt == WilsonKernelsStatic::OptHandUnroll ) { KERNEL_CALL_EXT(HandDhopSiteExt); return;}
|
||||
#ifndef GRID_CUDA
|
||||
if (Opt == WilsonKernelsStatic::OptInlineAsm ) { ASM_CALL(AsmDhopSiteExt); return;}
|
||||
#endif
|
||||
@ -506,9 +507,10 @@ void WilsonKernels<Impl>::DhopKernel(int Opt,StencilImpl &st, DoubledGaugeField
|
||||
if (Opt == WilsonKernelsStatic::OptInlineAsm ) { ASM_CALL(AsmDhopSiteDagInt); return;}
|
||||
#endif
|
||||
} else if( exterior ) {
|
||||
// Dependent on result of merge
|
||||
acceleratorFenceComputeStream();
|
||||
if (Opt == WilsonKernelsStatic::OptGeneric ) { KERNEL_CALL(GenericDhopSiteDagExt); return;}
|
||||
if (Opt == WilsonKernelsStatic::OptHandUnroll ) { KERNEL_CALL(HandDhopSiteDagExt); return;}
|
||||
if (Opt == WilsonKernelsStatic::OptGeneric ) { KERNEL_CALL_EXT(GenericDhopSiteDagExt); return;}
|
||||
if (Opt == WilsonKernelsStatic::OptHandUnroll ) { KERNEL_CALL_EXT(HandDhopSiteDagExt); return;}
|
||||
#ifndef GRID_CUDA
|
||||
if (Opt == WilsonKernelsStatic::OptInlineAsm ) { ASM_CALL(AsmDhopSiteDagExt); return;}
|
||||
#endif
|
||||
|
@ -0,0 +1 @@
|
||||
../WilsonCloverFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonKernelsInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonTMFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
#define IMPLEMENTATION SpWilsonImplD
|
@ -0,0 +1 @@
|
||||
../WilsonCloverFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonKernelsInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonTMFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
#define IMPLEMENTATION SpWilsonImplF
|
@ -0,0 +1 @@
|
||||
../WilsonCloverFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonKernelsInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonTMFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
#define IMPLEMENTATION SpWilsonTwoIndexAntiSymmetricImplD
|
@ -0,0 +1 @@
|
||||
../WilsonCloverFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonKernelsInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonTMFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
#define IMPLEMENTATION SpWilsonTwoIndexAntiSymmetricImplF
|
@ -0,0 +1 @@
|
||||
../WilsonCloverFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonKernelsInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonTMFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
#define IMPLEMENTATION SpWilsonTwoIndexSymmetricImplD
|
@ -0,0 +1 @@
|
||||
../WilsonCloverFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonKernelsInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
../WilsonTMFermionInstantiation.cc.master
|
@ -0,0 +1 @@
|
||||
#define IMPLEMENTATION SpWilsonTwoIndexSymmetricImplF
|
@ -10,12 +10,18 @@ WILSON_IMPL_LIST=" \
|
||||
WilsonImplF \
|
||||
WilsonImplD \
|
||||
WilsonImplD2 \
|
||||
SpWilsonImplF \
|
||||
SpWilsonImplD \
|
||||
WilsonAdjImplF \
|
||||
WilsonAdjImplD \
|
||||
WilsonTwoIndexSymmetricImplF \
|
||||
WilsonTwoIndexSymmetricImplD \
|
||||
WilsonTwoIndexAntiSymmetricImplF \
|
||||
WilsonTwoIndexAntiSymmetricImplD \
|
||||
SpWilsonTwoIndexAntiSymmetricImplF \
|
||||
SpWilsonTwoIndexAntiSymmetricImplD \
|
||||
SpWilsonTwoIndexSymmetricImplF \
|
||||
SpWilsonTwoIndexSymmetricImplD \
|
||||
GparityWilsonImplF \
|
||||
GparityWilsonImplD "
|
||||
|
||||
|
@ -39,6 +39,9 @@ NAMESPACE_BEGIN(Grid);
|
||||
typedef WilsonGaugeAction<PeriodicGimplR> WilsonGaugeActionR;
|
||||
typedef WilsonGaugeAction<PeriodicGimplF> WilsonGaugeActionF;
|
||||
typedef WilsonGaugeAction<PeriodicGimplD> WilsonGaugeActionD;
|
||||
typedef WilsonGaugeAction<SpPeriodicGimplR> SpWilsonGaugeActionR;
|
||||
typedef WilsonGaugeAction<SpPeriodicGimplF> SpWilsonGaugeActionF;
|
||||
typedef WilsonGaugeAction<SpPeriodicGimplD> SpWilsonGaugeActionD;
|
||||
typedef PlaqPlusRectangleAction<PeriodicGimplR> PlaqPlusRectangleActionR;
|
||||
typedef PlaqPlusRectangleAction<PeriodicGimplF> PlaqPlusRectangleActionF;
|
||||
typedef PlaqPlusRectangleAction<PeriodicGimplD> PlaqPlusRectangleActionD;
|
||||
|
@ -32,7 +32,7 @@ directory
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
#define CPS_MD_TIME
|
||||
#undef CPS_MD_TIME
|
||||
|
||||
#ifdef CPS_MD_TIME
|
||||
#define HMC_MOMENTUM_DENOMINATOR (2.0)
|
||||
@ -61,7 +61,7 @@ NAMESPACE_BEGIN(Grid);
|
||||
typedef typename Impl::Field Field;
|
||||
|
||||
// hardcodes the exponential approximation in the template
|
||||
template <class S, int Nrepresentation = Nc, int Nexp = 12 > class GaugeImplTypes {
|
||||
template <class S, int Nrepresentation = Nc, int Nexp = 12, class Group = SU<Nc> > class GaugeImplTypes {
|
||||
public:
|
||||
typedef S Simd;
|
||||
typedef typename Simd::scalar_type scalar_type;
|
||||
@ -78,8 +78,6 @@ public:
|
||||
typedef Lattice<SiteLink> LinkField;
|
||||
typedef Lattice<SiteField> Field;
|
||||
|
||||
typedef SU<Nrepresentation> Group;
|
||||
|
||||
// Guido: we can probably separate the types from the HMC functions
|
||||
// this will create 2 kind of implementations
|
||||
// probably confusing the users
|
||||
@ -119,6 +117,7 @@ public:
|
||||
//
|
||||
LinkField Pmu(P.Grid());
|
||||
Pmu = Zero();
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
Group::GaussianFundamentalLieAlgebraMatrix(pRNG, Pmu);
|
||||
RealD scale = ::sqrt(HMC_MOMENTUM_DENOMINATOR) ;
|
||||
@ -126,8 +125,12 @@ public:
|
||||
PokeIndex<LorentzIndex>(P, Pmu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
static inline Field projectForce(Field &P) { return Ta(P); }
|
||||
|
||||
static inline Field projectForce(Field &P) {
|
||||
Field ret(P.Grid());
|
||||
Group::taProj(P, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void update_field(Field& P, Field& U, double ep){
|
||||
//static std::chrono::duration<double> diff;
|
||||
@ -137,14 +140,15 @@ public:
|
||||
autoView(P_v,P,AcceleratorRead);
|
||||
accelerator_for(ss, P.Grid()->oSites(),1,{
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
U_v[ss](mu) = ProjectOnGroup(Exponentiate(P_v[ss](mu), ep, Nexp) * U_v[ss](mu));
|
||||
U_v[ss](mu) = Exponentiate(P_v[ss](mu), ep, Nexp) * U_v[ss](mu);
|
||||
U_v[ss](mu) = Group::ProjectOnGeneralGroup(U_v[ss](mu));
|
||||
}
|
||||
});
|
||||
//auto end = std::chrono::high_resolution_clock::now();
|
||||
// diff += end - start;
|
||||
// std::cout << "Time to exponentiate matrix " << diff.count() << " s\n";
|
||||
}
|
||||
|
||||
|
||||
static inline RealD FieldSquareNorm(Field& U){
|
||||
LatticeComplex Hloc(U.Grid());
|
||||
Hloc = Zero();
|
||||
@ -157,7 +161,7 @@ public:
|
||||
}
|
||||
|
||||
static inline void Project(Field &U) {
|
||||
ProjectSUn(U);
|
||||
Group::ProjectOnSpecialGroup(U);
|
||||
}
|
||||
|
||||
static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) {
|
||||
@ -171,6 +175,7 @@ public:
|
||||
static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) {
|
||||
Group::ColdConfiguration(pRNG, U);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -178,10 +183,17 @@ typedef GaugeImplTypes<vComplex, Nc> GimplTypesR;
|
||||
typedef GaugeImplTypes<vComplexF, Nc> GimplTypesF;
|
||||
typedef GaugeImplTypes<vComplexD, Nc> GimplTypesD;
|
||||
|
||||
typedef GaugeImplTypes<vComplex, Nc, 12, Sp<Nc> > SpGimplTypesR;
|
||||
typedef GaugeImplTypes<vComplexF, Nc, 12, Sp<Nc> > SpGimplTypesF;
|
||||
typedef GaugeImplTypes<vComplexD, Nc, 12, Sp<Nc> > SpGimplTypesD;
|
||||
|
||||
typedef GaugeImplTypes<vComplex, SU<Nc>::AdjointDimension> GimplAdjointTypesR;
|
||||
typedef GaugeImplTypes<vComplexF, SU<Nc>::AdjointDimension> GimplAdjointTypesF;
|
||||
typedef GaugeImplTypes<vComplexD, SU<Nc>::AdjointDimension> GimplAdjointTypesD;
|
||||
|
||||
|
||||
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif // GRID_GAUGE_IMPL_TYPES_H
|
||||
|
@ -176,7 +176,7 @@ public:
|
||||
return PeriodicBC::CshiftLink(Link,mu,shift);
|
||||
}
|
||||
|
||||
static inline void setDirections(std::vector<int> &conjDirs) { _conjDirs=conjDirs; }
|
||||
static inline void setDirections(const std::vector<int> &conjDirs) { _conjDirs=conjDirs; }
|
||||
static inline std::vector<int> getDirections(void) { return _conjDirs; }
|
||||
static inline bool isPeriodicGaugeField(void) { return false; }
|
||||
};
|
||||
@ -193,6 +193,11 @@ typedef ConjugateGaugeImpl<GimplTypesR> ConjugateGimplR; // Real.. whichever pre
|
||||
typedef ConjugateGaugeImpl<GimplTypesF> ConjugateGimplF; // Float
|
||||
typedef ConjugateGaugeImpl<GimplTypesD> ConjugateGimplD; // Double
|
||||
|
||||
typedef PeriodicGaugeImpl<SpGimplTypesR> SpPeriodicGimplR; // Real.. whichever prec
|
||||
typedef PeriodicGaugeImpl<SpGimplTypesF> SpPeriodicGimplF; // Float
|
||||
typedef PeriodicGaugeImpl<SpGimplTypesD> SpPeriodicGimplD; // Double
|
||||
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
private:
|
||||
RealD c_plaq;
|
||||
RealD c_rect;
|
||||
|
||||
typename WilsonLoops<Gimpl>::StapleAndRectStapleAllWorkspace workspace;
|
||||
public:
|
||||
PlaqPlusRectangleAction(RealD b,RealD c): c_plaq(b),c_rect(c){};
|
||||
|
||||
@ -79,27 +79,18 @@ public:
|
||||
GridBase *grid = Umu.Grid();
|
||||
|
||||
std::vector<GaugeLinkField> U (Nd,grid);
|
||||
std::vector<GaugeLinkField> U2(Nd,grid);
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U[mu] = PeekIndex<LorentzIndex>(Umu,mu);
|
||||
WilsonLoops<Gimpl>::RectStapleDouble(U2[mu],U[mu],mu);
|
||||
}
|
||||
std::vector<GaugeLinkField> RectStaple(Nd,grid), Staple(Nd,grid);
|
||||
WilsonLoops<Gimpl>::StapleAndRectStapleAll(Staple, RectStaple, U, workspace);
|
||||
|
||||
GaugeLinkField dSdU_mu(grid);
|
||||
GaugeLinkField staple(grid);
|
||||
|
||||
for (int mu=0; mu < Nd; mu++){
|
||||
|
||||
// Staple in direction mu
|
||||
|
||||
WilsonLoops<Gimpl>::Staple(staple,Umu,mu);
|
||||
|
||||
dSdU_mu = Ta(U[mu]*staple)*factor_p;
|
||||
|
||||
WilsonLoops<Gimpl>::RectStaple(Umu,staple,U2,U,mu);
|
||||
|
||||
dSdU_mu = dSdU_mu + Ta(U[mu]*staple)*factor_r;
|
||||
dSdU_mu = Ta(U[mu]*Staple[mu])*factor_p;
|
||||
dSdU_mu = dSdU_mu + Ta(U[mu]*RectStaple[mu])*factor_r;
|
||||
|
||||
PokeIndex<LorentzIndex>(dSdU, dSdU_mu, mu);
|
||||
}
|
||||
|
@ -42,9 +42,13 @@ template <class Gimpl>
|
||||
class WilsonGaugeAction : public Action<typename Gimpl::GaugeField> {
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl);
|
||||
typedef GaugeImplParams ImplParams;
|
||||
ImplParams Params;
|
||||
|
||||
/////////////////////////// constructors
|
||||
explicit WilsonGaugeAction(RealD beta_):beta(beta_){};
|
||||
explicit WilsonGaugeAction(RealD beta_,
|
||||
const ImplParams &p = ImplParams()
|
||||
):beta(beta_),Params(p){};
|
||||
|
||||
virtual std::string action_name() {return "WilsonGaugeAction";}
|
||||
|
||||
@ -56,14 +60,53 @@ public:
|
||||
|
||||
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG){}; // noop as no pseudoferms
|
||||
|
||||
// Umu<->U maximally confusing
|
||||
virtual void boundary(const GaugeField &Umu, GaugeField &Ub){
|
||||
typedef typename Simd::scalar_type scalar_type;
|
||||
assert(Params.boundary_phases.size() == Nd);
|
||||
GridBase *GaugeGrid=Umu.Grid();
|
||||
GaugeLinkField U(GaugeGrid);
|
||||
GaugeLinkField tmp(GaugeGrid);
|
||||
|
||||
Lattice<iScalar<vInteger> > coor(GaugeGrid);
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
////////// boundary phase /////////////
|
||||
auto pha = Params.boundary_phases[mu];
|
||||
scalar_type phase( real(pha),imag(pha) );
|
||||
std::cout<< GridLogIterative << "[WilsonGaugeAction] boundary "<<mu<<" "<<phase<< std::endl;
|
||||
|
||||
int L = GaugeGrid->GlobalDimensions()[mu];
|
||||
int Lmu = L - 1;
|
||||
|
||||
LatticeCoordinate(coor, mu);
|
||||
|
||||
U = PeekIndex<LorentzIndex>(Umu, mu);
|
||||
tmp = where(coor == Lmu, phase * U, U);
|
||||
PokeIndex<LorentzIndex>(Ub, tmp, mu);
|
||||
// PokeIndex<LorentzIndex>(Ub, U, mu);
|
||||
// PokeIndex<LorentzIndex>(Umu, tmp, mu);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
virtual RealD S(const GaugeField &U) {
|
||||
RealD plaq = WilsonLoops<Gimpl>::avgPlaquette(U);
|
||||
RealD vol = U.Grid()->gSites();
|
||||
GaugeField Ub(U.Grid());
|
||||
this->boundary(U,Ub);
|
||||
static RealD lastG=0.;
|
||||
RealD plaq = WilsonLoops<Gimpl>::avgPlaquette(Ub);
|
||||
RealD vol = Ub.Grid()->gSites();
|
||||
RealD action = beta * (1.0 - plaq) * (Nd * (Nd - 1.0)) * vol * 0.5;
|
||||
std::cout << GridLogMessage << "[WilsonGaugeAction] dH: " << action-lastG << std::endl;
|
||||
RealD plaq_o = WilsonLoops<Gimpl>::avgPlaquette(U);
|
||||
RealD action_o = beta * (1.0 - plaq_o) * (Nd * (Nd - 1.0)) * vol * 0.5;
|
||||
std::cout << GridLogMessage << "[WilsonGaugeAction] U: " << action_o <<" Ub: "<< action << std::endl;
|
||||
lastG=action;
|
||||
return action;
|
||||
};
|
||||
|
||||
virtual void deriv(const GaugeField &U, GaugeField &dSdU) {
|
||||
GaugeField Ub(U.Grid());
|
||||
this->boundary(U,Ub);
|
||||
// not optimal implementation FIXME
|
||||
// extend Ta to include Lorentz indexes
|
||||
|
||||
@ -73,10 +116,9 @@ public:
|
||||
GaugeLinkField dSdU_mu(U.Grid());
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
|
||||
Umu = PeekIndex<LorentzIndex>(U, mu);
|
||||
|
||||
Umu = PeekIndex<LorentzIndex>(Ub, mu);
|
||||
// Staple in direction mu
|
||||
WilsonLoops<Gimpl>::Staple(dSdU_mu, U, mu);
|
||||
WilsonLoops<Gimpl>::Staple(dSdU_mu, Ub, mu);
|
||||
dSdU_mu = Ta(Umu * dSdU_mu) * factor;
|
||||
|
||||
PokeIndex<LorentzIndex>(dSdU, dSdU_mu, mu);
|
||||
|
@ -178,7 +178,10 @@ NAMESPACE_BEGIN(Grid);
|
||||
// Use chronological inverter to forecast solutions across poles
|
||||
std::vector<FermionField> prev_solns;
|
||||
if(use_heatbath_forecasting){ prev_solns.reserve(param.degree); }
|
||||
ChronoForecast<AbstractEOFAFermion<Impl>, FermionField> Forecast;
|
||||
MdagMLinearOperator<AbstractEOFAFermion<Impl> ,FermionField> MdagML(Lop);
|
||||
MdagMLinearOperator<AbstractEOFAFermion<Impl> ,FermionField> MdagMR(Rop);
|
||||
// ChronoForecast<AbstractEOFAFermion<Impl>, FermionField> Forecast;
|
||||
ChronoForecast<MdagMLinearOperator<AbstractEOFAFermion<Impl>, FermionField> , FermionField> Forecast;
|
||||
|
||||
// \Phi = ( \alpha_{0} + \sum_{k=1}^{N_{p}} \alpha_{l} * \gamma_{l} ) * \eta
|
||||
RealD N(PowerNegHalf.norm);
|
||||
@ -198,7 +201,7 @@ NAMESPACE_BEGIN(Grid);
|
||||
heatbathRefreshShiftCoefficients(0, -gamma_l);
|
||||
if(use_heatbath_forecasting){ // Forecast CG guess using solutions from previous poles
|
||||
Lop.Mdag(CG_src, Forecast_src);
|
||||
CG_soln = Forecast(Lop, Forecast_src, prev_solns);
|
||||
CG_soln = Forecast(MdagML, Forecast_src, prev_solns);
|
||||
SolverHBL(Lop, CG_src, CG_soln);
|
||||
prev_solns.push_back(CG_soln);
|
||||
} else {
|
||||
@ -225,7 +228,7 @@ NAMESPACE_BEGIN(Grid);
|
||||
heatbathRefreshShiftCoefficients(1, -gamma_l*PowerNegHalf.poles[k]);
|
||||
if(use_heatbath_forecasting){
|
||||
Rop.Mdag(CG_src, Forecast_src);
|
||||
CG_soln = Forecast(Rop, Forecast_src, prev_solns);
|
||||
CG_soln = Forecast(MdagMR, Forecast_src, prev_solns);
|
||||
SolverHBR(Rop, CG_src, CG_soln);
|
||||
prev_solns.push_back(CG_soln);
|
||||
} else {
|
||||
|
@ -53,9 +53,10 @@ NAMESPACE_BEGIN(Grid);
|
||||
Integer ReliableUpdateFreq;
|
||||
protected:
|
||||
|
||||
//Action evaluation
|
||||
//Allow derived classes to override the multishift CG
|
||||
virtual void multiShiftInverse(bool numerator, const MultiShiftFunction &approx, const Integer MaxIter, const FermionFieldD &in, FermionFieldD &out){
|
||||
#if 0
|
||||
#if 1
|
||||
SchurDifferentiableOperator<ImplD> schurOp(numerator ? NumOpD : DenOpD);
|
||||
ConjugateGradientMultiShift<FermionFieldD> msCG(MaxIter, approx);
|
||||
msCG(schurOp,in, out);
|
||||
@ -70,9 +71,10 @@ NAMESPACE_BEGIN(Grid);
|
||||
msCG(schurOpD, in, out);
|
||||
#endif
|
||||
}
|
||||
//Force evaluation
|
||||
virtual void multiShiftInverse(bool numerator, const MultiShiftFunction &approx, const Integer MaxIter, const FermionFieldD &in, std::vector<FermionFieldD> &out_elems, FermionFieldD &out){
|
||||
SchurDifferentiableOperator<ImplD> schurOpD(numerator ? NumOpD : DenOpD);
|
||||
SchurDifferentiableOperator<ImplF> schurOpF (numerator ? NumOpF : DenOpF);
|
||||
SchurDifferentiableOperator<ImplF> schurOpF(numerator ? NumOpF : DenOpF);
|
||||
|
||||
FermionFieldD inD(NumOpD.FermionRedBlackGrid());
|
||||
FermionFieldD outD(NumOpD.FermionRedBlackGrid());
|
||||
@ -84,20 +86,15 @@ NAMESPACE_BEGIN(Grid);
|
||||
virtual void ImportGauge(const typename ImplD::GaugeField &Ud){
|
||||
|
||||
typename ImplF::GaugeField Uf(NumOpF.GaugeGrid());
|
||||
typename ImplD::GaugeField Ud2(NumOpD.GaugeGrid());
|
||||
precisionChange(Uf, Ud);
|
||||
precisionChange(Ud2, Ud);
|
||||
|
||||
std::cout << "Importing "<<norm2(Ud)<<" "<< norm2(Uf)<<" " << norm2(Ud2)<<std::endl;
|
||||
std::cout << "Importing "<<norm2(Ud)<<" "<< norm2(Uf)<<" " <<std::endl;
|
||||
|
||||
NumOpD.ImportGauge(Ud);
|
||||
DenOpD.ImportGauge(Ud);
|
||||
|
||||
NumOpF.ImportGauge(Uf);
|
||||
DenOpF.ImportGauge(Uf);
|
||||
|
||||
NumOpD.ImportGauge(Ud2);
|
||||
DenOpD.ImportGauge(Ud2);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -207,20 +207,27 @@ NAMESPACE_BEGIN(Grid);
|
||||
//X = (Mdag M)^-1 V^dag phi
|
||||
//Y = (Mdag)^-1 V^dag phi
|
||||
Vpc.MpcDag(PhiOdd,Y); // Y= Vdag phi
|
||||
std::cout << GridLogMessage <<" Y "<<norm2(Y)<<std::endl;
|
||||
X=Zero();
|
||||
DerivativeSolver(Mpc,Y,X); // X= (MdagM)^-1 Vdag phi
|
||||
std::cout << GridLogMessage <<" X "<<norm2(X)<<std::endl;
|
||||
Mpc.Mpc(X,Y); // Y= Mdag^-1 Vdag phi
|
||||
std::cout << GridLogMessage <<" Y "<<norm2(Y)<<std::endl;
|
||||
|
||||
// phi^dag V (Mdag M)^-1 dV^dag phi
|
||||
Vpc.MpcDagDeriv(force , X, PhiOdd ); dSdU = force;
|
||||
std::cout << GridLogMessage <<" deriv "<<norm2(force)<<std::endl;
|
||||
|
||||
// phi^dag dV (Mdag M)^-1 V^dag phi
|
||||
Vpc.MpcDeriv(force , PhiOdd, X ); dSdU = dSdU+force;
|
||||
std::cout << GridLogMessage <<" deriv "<<norm2(force)<<std::endl;
|
||||
|
||||
// - phi^dag V (Mdag M)^-1 Mdag dM (Mdag M)^-1 V^dag phi
|
||||
// - phi^dag V (Mdag M)^-1 dMdag M (Mdag M)^-1 V^dag phi
|
||||
Mpc.MpcDeriv(force,Y,X); dSdU = dSdU-force;
|
||||
std::cout << GridLogMessage <<" deriv "<<norm2(force)<<std::endl;
|
||||
Mpc.MpcDagDeriv(force,X,Y); dSdU = dSdU-force;
|
||||
std::cout << GridLogMessage <<" deriv "<<norm2(force)<<std::endl;
|
||||
|
||||
// FIXME No force contribution from EvenEven assumed here
|
||||
// Needs a fix for clover.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define CPS_MD_TIME
|
||||
#undef CPS_MD_TIME
|
||||
|
||||
#ifdef CPS_MD_TIME
|
||||
#define HMC_MOMENTUM_DENOMINATOR (2.0)
|
||||
|
@ -121,12 +121,19 @@ public:
|
||||
|
||||
template <class SmearingPolicy>
|
||||
void Run(SmearingPolicy &S) {
|
||||
Runner(S);
|
||||
TrivialMetric<typename Implementation::Field> Mtr;
|
||||
Runner(S,Mtr);
|
||||
}
|
||||
|
||||
template <class SmearingPolicy, class Metric>
|
||||
void Run(SmearingPolicy &S, Metric &Mtr) {
|
||||
Runner(S,Mtr);
|
||||
}
|
||||
|
||||
void Run(){
|
||||
NoSmearing<Implementation> S;
|
||||
Runner(S);
|
||||
TrivialMetric<typename Implementation::Field> Mtr;
|
||||
Runner(S,Mtr);
|
||||
}
|
||||
|
||||
//Use the checkpointer to initialize the RNGs and the gauge field, writing the resulting gauge field into U.
|
||||
@ -176,15 +183,15 @@ public:
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
template <class SmearingPolicy>
|
||||
void Runner(SmearingPolicy &Smearing) {
|
||||
template <class SmearingPolicy, class Metric>
|
||||
void Runner(SmearingPolicy &Smearing, Metric &Mtr) {
|
||||
auto UGrid = Resources.GetCartesian();
|
||||
Field U(UGrid);
|
||||
|
||||
initializeGaugeFieldAndRNGs(U);
|
||||
|
||||
typedef IntegratorType<SmearingPolicy> TheIntegrator;
|
||||
TheIntegrator MDynamics(UGrid, Parameters.MD, TheAction, Smearing);
|
||||
TheIntegrator MDynamics(UGrid, Parameters.MD, TheAction, Smearing,Mtr);
|
||||
|
||||
// Sets the momentum filter
|
||||
MDynamics.setMomentumFilter(*(Resources.GetMomentumFilter()));
|
||||
@ -225,6 +232,18 @@ template <class RepresentationsPolicy,
|
||||
using GenericHMCRunnerHirep =
|
||||
HMCWrapperTemplate<PeriodicGimplR, Integrator, RepresentationsPolicy>;
|
||||
|
||||
// sp2n
|
||||
|
||||
template <template <typename, typename, typename> class Integrator>
|
||||
using GenericSpHMCRunner = HMCWrapperTemplate<SpPeriodicGimplR, Integrator>;
|
||||
|
||||
template <class RepresentationsPolicy,
|
||||
template <typename, typename, typename> class Integrator>
|
||||
using GenericSpHMCRunnerHirep =
|
||||
HMCWrapperTemplate<SpPeriodicGimplR, Integrator, RepresentationsPolicy>;
|
||||
|
||||
|
||||
|
||||
template <class Implementation, class RepresentationsPolicy,
|
||||
template <typename, typename, typename> class Integrator>
|
||||
using GenericHMCRunnerTemplate = HMCWrapperTemplate<Implementation, Integrator, RepresentationsPolicy>;
|
||||
|
@ -55,6 +55,8 @@ struct HMCparameters: Serializable {
|
||||
Integer, NoMetropolisUntil,
|
||||
bool, PerformRandomShift, /* @brief Randomly shift the gauge configuration at the start of a trajectory */
|
||||
std::string, StartingType,
|
||||
Integer, SW,
|
||||
RealD, Kappa,
|
||||
IntegratorParameters, MD)
|
||||
|
||||
HMCparameters() {
|
||||
@ -110,6 +112,8 @@ private:
|
||||
IntegratorType &TheIntegrator;
|
||||
ObsListType Observables;
|
||||
|
||||
int traj_num;
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Metropolis step
|
||||
/////////////////////////////////////////////////////////
|
||||
@ -200,14 +204,14 @@ private:
|
||||
|
||||
std::cout << GridLogMessage << "--------------------------------------------------\n";
|
||||
std::cout << GridLogMessage << " Molecular Dynamics evolution ";
|
||||
TheIntegrator.integrate(U);
|
||||
TheIntegrator.integrate(U,traj_num);
|
||||
std::cout << GridLogMessage << "--------------------------------------------------\n";
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// updated state action
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
std::cout << GridLogMessage << "--------------------------------------------------\n";
|
||||
std::cout << GridLogMessage << "Compute final action";
|
||||
std::cout << GridLogMessage << "Compute final action" <<std::endl;
|
||||
RealD H1 = TheIntegrator.S(U);
|
||||
std::cout << GridLogMessage << "--------------------------------------------------\n";
|
||||
|
||||
@ -242,7 +246,7 @@ public:
|
||||
HybridMonteCarlo(HMCparameters _Pams, IntegratorType &_Int,
|
||||
GridSerialRNG &_sRNG, GridParallelRNG &_pRNG,
|
||||
ObsListType _Obs, Field &_U)
|
||||
: Params(_Pams), TheIntegrator(_Int), sRNG(_sRNG), pRNG(_pRNG), Observables(_Obs), Ucur(_U) {}
|
||||
: Params(_Pams), TheIntegrator(_Int), sRNG(_sRNG), pRNG(_pRNG), Observables(_Obs), Ucur(_U),traj_num(0) {}
|
||||
~HybridMonteCarlo(){};
|
||||
|
||||
void evolve(void) {
|
||||
@ -257,9 +261,10 @@ public:
|
||||
unsigned int FinalTrajectory = Params.Trajectories + Params.NoMetropolisUntil + Params.StartTrajectory;
|
||||
|
||||
for (int traj = Params.StartTrajectory; traj < FinalTrajectory; ++traj) {
|
||||
|
||||
|
||||
std::cout << GridLogHMC << "-- # Trajectory = " << traj << "\n";
|
||||
|
||||
traj_num=traj;
|
||||
if (traj < Params.StartTrajectory + Params.NoMetropolisUntil) {
|
||||
std::cout << GridLogHMC << "-- Thermalization" << std::endl;
|
||||
}
|
||||
@ -283,12 +288,13 @@ public:
|
||||
std::cout << GridLogHMC << "Total time for trajectory (s): " << (t1-t0)/1e6 << std::endl;
|
||||
|
||||
TheIntegrator.print_timer();
|
||||
|
||||
|
||||
TheIntegrator.Smearer.set_Field(Ucur);
|
||||
for (int obs = 0; obs < Observables.size(); obs++) {
|
||||
std::cout << GridLogDebug << "Observables # " << obs << std::endl;
|
||||
std::cout << GridLogDebug << "Observables total " << Observables.size() << std::endl;
|
||||
std::cout << GridLogDebug << "Observables pointer " << Observables[obs] << std::endl;
|
||||
Observables[obs]->TrajectoryComplete(traj + 1, Ucur, sRNG, pRNG);
|
||||
Observables[obs]->TrajectoryComplete(traj + 1, TheIntegrator.Smearer, sRNG, pRNG);
|
||||
}
|
||||
std::cout << GridLogHMC << ":::::::::::::::::::::::::::::::::::::::::::" << std::endl;
|
||||
}
|
||||
|
@ -35,13 +35,16 @@ class CheckpointerParameters : Serializable {
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(CheckpointerParameters,
|
||||
std::string, config_prefix,
|
||||
std::string, smeared_prefix,
|
||||
std::string, rng_prefix,
|
||||
int, saveInterval,
|
||||
bool, saveSmeared,
|
||||
std::string, format, );
|
||||
|
||||
CheckpointerParameters(std::string cf = "cfg", std::string rn = "rng",
|
||||
CheckpointerParameters(std::string cf = "cfg", std::string sf="cfg_smr" , std::string rn = "rng",
|
||||
int savemodulo = 1, const std::string &f = "IEEE64BIG")
|
||||
: config_prefix(cf),
|
||||
smeared_prefix(sf),
|
||||
rng_prefix(rn),
|
||||
saveInterval(savemodulo),
|
||||
format(f){};
|
||||
@ -61,13 +64,21 @@ template <class Impl>
|
||||
class BaseHmcCheckpointer : public HmcObservable<typename Impl::Field> {
|
||||
public:
|
||||
void build_filenames(int traj, CheckpointerParameters &Params,
|
||||
std::string &conf_file, std::string &rng_file) {
|
||||
std::string &conf_file,
|
||||
std::string &smear_file,
|
||||
std::string &rng_file) {
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << Params.rng_prefix << "." << traj;
|
||||
rng_file = os.str();
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << Params.smeared_prefix << "." << traj;
|
||||
smear_file = os.str();
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << Params.config_prefix << "." << traj;
|
||||
@ -84,6 +95,11 @@ public:
|
||||
}
|
||||
virtual void initialize(const CheckpointerParameters &Params) = 0;
|
||||
|
||||
virtual void TrajectoryComplete(int traj,
|
||||
typename Impl::Field &U,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG) { assert(0); } ; // HMC should pass the smart config with smeared and unsmeared
|
||||
|
||||
virtual void CheckpointRestore(int traj, typename Impl::Field &U,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG) = 0;
|
||||
|
@ -61,11 +61,14 @@ public:
|
||||
fout.close();
|
||||
}
|
||||
|
||||
void TrajectoryComplete(int traj, Field &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG) {
|
||||
void TrajectoryComplete(int traj,
|
||||
ConfigurationBase<Field> &SmartConfig,
|
||||
GridSerialRNG &sRNG, GridParallelRNG &pRNG)
|
||||
{
|
||||
|
||||
if ((traj % Params.saveInterval) == 0) {
|
||||
std::string config, rng;
|
||||
this->build_filenames(traj, Params, config, rng);
|
||||
std::string config, rng, smr;
|
||||
this->build_filenames(traj, Params, config, smr, rng);
|
||||
|
||||
uint32_t nersc_csum;
|
||||
uint32_t scidac_csuma;
|
||||
@ -74,9 +77,15 @@ public:
|
||||
BinarySimpleUnmunger<sobj_double, sobj> munge;
|
||||
truncate(rng);
|
||||
BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
|
||||
truncate(config);
|
||||
std::cout << GridLogMessage << "Written Binary RNG " << rng
|
||||
<< " checksum " << std::hex
|
||||
<< nersc_csum <<"/"
|
||||
<< scidac_csuma <<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
|
||||
BinaryIO::writeLatticeObject<vobj, sobj_double>(U, config, munge, 0, Params.format,
|
||||
truncate(config);
|
||||
BinaryIO::writeLatticeObject<vobj, sobj_double>(SmartConfig.get_U(false), config, munge, 0, Params.format,
|
||||
nersc_csum,scidac_csuma,scidac_csumb);
|
||||
|
||||
std::cout << GridLogMessage << "Written Binary Configuration " << config
|
||||
@ -85,6 +94,18 @@ public:
|
||||
<< scidac_csuma <<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
|
||||
if ( Params.saveSmeared ) {
|
||||
truncate(smr);
|
||||
BinaryIO::writeLatticeObject<vobj, sobj_double>(SmartConfig.get_U(true), smr, munge, 0, Params.format,
|
||||
nersc_csum,scidac_csuma,scidac_csumb);
|
||||
std::cout << GridLogMessage << "Written Binary Smeared Configuration " << smr
|
||||
<< " checksum " << std::hex
|
||||
<< nersc_csum <<"/"
|
||||
<< scidac_csuma <<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -69,17 +69,27 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void TrajectoryComplete(int traj, GaugeField &U, GridSerialRNG &sRNG,
|
||||
void TrajectoryComplete(int traj,
|
||||
ConfigurationBase<GaugeField> &SmartConfig,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG) {
|
||||
if ((traj % Params.saveInterval) == 0) {
|
||||
std::string config, rng;
|
||||
std::string config, rng, smr;
|
||||
this->build_filenames(traj, Params, config, rng);
|
||||
GridBase *grid = U.Grid();
|
||||
GridBase *grid = SmartConfig.get_U(false).Grid();
|
||||
uint32_t nersc_csum,scidac_csuma,scidac_csumb;
|
||||
BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
|
||||
std::cout << GridLogMessage << "Written BINARY RNG " << rng
|
||||
<< " checksum " << std::hex
|
||||
<< nersc_csum<<"/"
|
||||
<< scidac_csuma<<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
|
||||
|
||||
IldgWriter _IldgWriter(grid->IsBoss());
|
||||
_IldgWriter.open(config);
|
||||
_IldgWriter.writeConfiguration<GaugeStats>(U, traj, config, config);
|
||||
_IldgWriter.writeConfiguration<GaugeStats>(SmartConfig.get_U(false), traj, config, config);
|
||||
_IldgWriter.close();
|
||||
|
||||
std::cout << GridLogMessage << "Written ILDG Configuration on " << config
|
||||
@ -88,6 +98,21 @@ public:
|
||||
<< scidac_csuma<<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
|
||||
if ( Params.saveSmeared ) {
|
||||
IldgWriter _IldgWriter(grid->IsBoss());
|
||||
_IldgWriter.open(smr);
|
||||
_IldgWriter.writeConfiguration<GaugeStats>(SmartConfig.get_U(true), traj, config, config);
|
||||
_IldgWriter.close();
|
||||
|
||||
std::cout << GridLogMessage << "Written ILDG Configuration on " << smr
|
||||
<< " checksum " << std::hex
|
||||
<< nersc_csum<<"/"
|
||||
<< scidac_csuma<<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -52,23 +52,29 @@ public:
|
||||
Params.format = "IEEE64BIG"; // fixed, overwrite any other choice
|
||||
}
|
||||
|
||||
void TrajectoryComplete(int traj, GaugeField &U, GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG) {
|
||||
virtual void TrajectoryComplete(int traj,
|
||||
ConfigurationBase<GaugeField> &SmartConfig,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG)
|
||||
{
|
||||
if ((traj % Params.saveInterval) == 0) {
|
||||
std::string config, rng;
|
||||
this->build_filenames(traj, Params, config, rng);
|
||||
|
||||
std::string config, rng, smr;
|
||||
this->build_filenames(traj, Params, config, smr, rng);
|
||||
|
||||
int precision32 = 1;
|
||||
int tworow = 0;
|
||||
NerscIO::writeRNGState(sRNG, pRNG, rng);
|
||||
NerscIO::writeConfiguration<GaugeStats>(U, config, tworow, precision32);
|
||||
NerscIO::writeConfiguration<GaugeStats>(SmartConfig.get_U(false), config, tworow, precision32);
|
||||
if ( Params.saveSmeared ) {
|
||||
NerscIO::writeConfiguration<GaugeStats>(SmartConfig.get_U(true), smr, tworow, precision32);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void CheckpointRestore(int traj, GaugeField &U, GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG) {
|
||||
std::string config, rng;
|
||||
this->build_filenames(traj, Params, config, rng);
|
||||
std::string config, rng, smr;
|
||||
this->build_filenames(traj, Params, config, smr, rng );
|
||||
this->check_filename(rng);
|
||||
this->check_filename(config);
|
||||
|
||||
|
@ -70,19 +70,37 @@ class ScidacHmcCheckpointer : public BaseHmcCheckpointer<Implementation> {
|
||||
}
|
||||
}
|
||||
|
||||
void TrajectoryComplete(int traj, Field &U, GridSerialRNG &sRNG,
|
||||
void TrajectoryComplete(int traj,
|
||||
ConfigurationBase<Field> &SmartConfig,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG) {
|
||||
if ((traj % Params.saveInterval) == 0) {
|
||||
std::string config, rng;
|
||||
this->build_filenames(traj, Params, config, rng);
|
||||
GridBase *grid = U.Grid();
|
||||
std::string config, rng,smr;
|
||||
this->build_filenames(traj, Params, config, smr, rng);
|
||||
GridBase *grid = SmartConfig.get_U(false).Grid();
|
||||
uint32_t nersc_csum,scidac_csuma,scidac_csumb;
|
||||
BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
|
||||
ScidacWriter _ScidacWriter(grid->IsBoss());
|
||||
_ScidacWriter.open(config);
|
||||
_ScidacWriter.writeScidacFieldRecord(U, MData);
|
||||
_ScidacWriter.close();
|
||||
std::cout << GridLogMessage << "Written Binary RNG " << rng
|
||||
<< " checksum " << std::hex
|
||||
<< nersc_csum <<"/"
|
||||
<< scidac_csuma <<"/"
|
||||
<< scidac_csumb
|
||||
<< std::dec << std::endl;
|
||||
|
||||
|
||||
{
|
||||
ScidacWriter _ScidacWriter(grid->IsBoss());
|
||||
_ScidacWriter.open(config);
|
||||
_ScidacWriter.writeScidacFieldRecord(SmartConfig.get_U(false), MData);
|
||||
_ScidacWriter.close();
|
||||
}
|
||||
|
||||
if ( Params.saveSmeared ) {
|
||||
ScidacWriter _ScidacWriter(grid->IsBoss());
|
||||
_ScidacWriter.open(smr);
|
||||
_ScidacWriter.writeScidacFieldRecord(SmartConfig.get_U(true), MData);
|
||||
_ScidacWriter.close();
|
||||
}
|
||||
std::cout << GridLogMessage << "Written Scidac Configuration on " << config << std::endl;
|
||||
}
|
||||
};
|
||||
|
@ -9,6 +9,7 @@ Copyright (C) 2015
|
||||
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: Guido Cossu <cossu@post.kek.jp>
|
||||
Author: Chulwoo Jung <chulwoo@bnl.gov>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -33,6 +34,7 @@ directory
|
||||
#define INTEGRATOR_INCLUDED
|
||||
|
||||
#include <memory>
|
||||
#include <Grid/parallelIO/NerscIO.h>
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
@ -41,10 +43,19 @@ public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(IntegratorParameters,
|
||||
std::string, name, // name of the integrator
|
||||
unsigned int, MDsteps, // number of outer steps
|
||||
RealD, RMHMCTol,
|
||||
RealD, RMHMCCGTol,
|
||||
RealD, lambda0,
|
||||
RealD, lambda1,
|
||||
RealD, lambda2,
|
||||
RealD, trajL) // trajectory length
|
||||
|
||||
IntegratorParameters(int MDsteps_ = 10, RealD trajL_ = 1.0)
|
||||
: MDsteps(MDsteps_),
|
||||
lambda0(0.1931833275037836),
|
||||
lambda1(0.1931833275037836),
|
||||
lambda2(0.1931833275037836),
|
||||
RMHMCTol(1e-8),RMHMCCGTol(1e-8),
|
||||
trajL(trajL_) {};
|
||||
|
||||
template <class ReaderClass, typename std::enable_if<isReader<ReaderClass>::value, int >::type = 0 >
|
||||
@ -66,6 +77,7 @@ public:
|
||||
template <class FieldImplementation_, class SmearingPolicy, class RepresentationPolicy>
|
||||
class Integrator {
|
||||
protected:
|
||||
public:
|
||||
typedef FieldImplementation_ FieldImplementation;
|
||||
typedef typename FieldImplementation::Field MomentaField; //for readability
|
||||
typedef typename FieldImplementation::Field Field;
|
||||
@ -74,11 +86,14 @@ protected:
|
||||
double t_U; // Track time passing on each level and for U and for P
|
||||
std::vector<double> t_P;
|
||||
|
||||
MomentaField P;
|
||||
// MomentaField P;
|
||||
GeneralisedMomenta<FieldImplementation > P;
|
||||
SmearingPolicy& Smearer;
|
||||
RepresentationPolicy Representations;
|
||||
IntegratorParameters Params;
|
||||
|
||||
RealD Saux,Smom,Sg;
|
||||
|
||||
//Filters allow the user to manipulate the conjugate momentum, for example to freeze links in DDHMC
|
||||
//It is applied whenever the momentum is updated / refreshed
|
||||
//The default filter does nothing
|
||||
@ -95,7 +110,15 @@ protected:
|
||||
void update_P(Field& U, int level, double ep)
|
||||
{
|
||||
t_P[level] += ep;
|
||||
update_P(P, U, level, ep);
|
||||
update_P(P.Mom, U, level, ep);
|
||||
|
||||
std::cout << GridLogIntegrator << "[" << level << "] P " << " dt " << ep << " : t_P " << t_P[level] << std::endl;
|
||||
}
|
||||
|
||||
void update_P2(Field& U, int level, double ep)
|
||||
{
|
||||
t_P[level] += ep;
|
||||
update_P2(P.Mom, U, level, ep);
|
||||
|
||||
std::cout << GridLogIntegrator << "[" << level << "] P " << " dt " << ep << " : t_P " << t_P[level] << std::endl;
|
||||
}
|
||||
@ -119,70 +142,174 @@ protected:
|
||||
}
|
||||
} update_P_hireps{};
|
||||
|
||||
|
||||
void update_P(MomentaField& Mom, Field& U, int level, double ep) {
|
||||
// input U actually not used in the fundamental case
|
||||
// Fundamental updates, include smearing
|
||||
|
||||
for (int a = 0; a < as[level].actions.size(); ++a) {
|
||||
|
||||
double start_full = usecond();
|
||||
Field force(U.Grid());
|
||||
conformable(U.Grid(), Mom.Grid());
|
||||
|
||||
Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared);
|
||||
double start_force = usecond();
|
||||
|
||||
std::cout << GridLogMessage << "AuditForce["<<level<<"]["<<a<<"] before"<<std::endl;
|
||||
|
||||
as[level].actions.at(a)->deriv_timer_start();
|
||||
as[level].actions.at(a)->deriv(Us, force); // deriv should NOT include Ta
|
||||
as[level].actions.at(a)->deriv_timer_stop();
|
||||
|
||||
std::cout << GridLogMessage << "AuditForce["<<level<<"]["<<a<<"] after"<<std::endl;
|
||||
|
||||
std::cout << GridLogIntegrator << "Smearing (on/off): " << as[level].actions.at(a)->is_smeared << std::endl;
|
||||
auto name = as[level].actions.at(a)->action_name();
|
||||
if (as[level].actions.at(a)->is_smeared) Smearer.smeared_force(force);
|
||||
|
||||
force = FieldImplementation::projectForce(force); // Ta for gauge fields
|
||||
double end_force = usecond();
|
||||
|
||||
// DumpSliceNorm("force ",force,Nd-1);
|
||||
MomFilter->applyFilter(force);
|
||||
std::cout << GridLogIntegrator << " update_P : Level [" << level <<"]["<<a <<"] "<<name<<" dt "<<ep<< std::endl;
|
||||
DumpSliceNorm("force filtered ",force,Nd-1);
|
||||
|
||||
Real force_abs = std::sqrt(norm2(force)/U.Grid()->gSites()); //average per-site norm. nb. norm2(latt) = \sum_x norm2(latt[x])
|
||||
Real impulse_abs = force_abs * ep * HMC_MOMENTUM_DENOMINATOR;
|
||||
|
||||
Real force_max = std::sqrt(maxLocalNorm2(force));
|
||||
Real impulse_max = force_max * ep * HMC_MOMENTUM_DENOMINATOR;
|
||||
|
||||
as[level].actions.at(a)->deriv_log(force_abs,force_max,impulse_abs,impulse_max);
|
||||
|
||||
std::cout << GridLogIntegrator<< "["<<level<<"]["<<a<<"] dt : " << ep <<" "<<name<<std::endl;
|
||||
std::cout << GridLogIntegrator<< "["<<level<<"]["<<a<<"] Force average: " << force_abs <<" "<<name<<std::endl;
|
||||
std::cout << GridLogIntegrator<< "["<<level<<"]["<<a<<"] Force max : " << force_max <<" "<<name<<std::endl;
|
||||
std::cout << GridLogIntegrator<< "["<<level<<"]["<<a<<"] Fdt average : " << impulse_abs <<" "<<name<<std::endl;
|
||||
std::cout << GridLogIntegrator<< "["<<level<<"]["<<a<<"] Fdt max : " << impulse_max <<" "<<name<<std::endl;
|
||||
|
||||
Real force_abs = std::sqrt(norm2(force)/U.Grid()->gSites());
|
||||
std::cout << GridLogIntegrator << "["<<level<<"]["<<a<<"] Force average: " << force_abs << std::endl;
|
||||
Mom -= force * ep* HMC_MOMENTUM_DENOMINATOR;;
|
||||
double end_full = usecond();
|
||||
double time_full = (end_full - start_full) / 1e3;
|
||||
double time_force = (end_force - start_force) / 1e3;
|
||||
std::cout << GridLogMessage << "["<<level<<"]["<<a<<"] P update elapsed time: " << time_full << " ms (force: " << time_force << " ms)" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
// Force from the other representations
|
||||
as[level].apply(update_P_hireps, Representations, Mom, U, ep);
|
||||
}
|
||||
|
||||
void update_P2(MomentaField& Mom, Field& U, int level, double ep) {
|
||||
// input U actually not used in the fundamental case
|
||||
// Fundamental updates, include smearing
|
||||
|
||||
std::cout << GridLogIntegrator << "U before update_P2: " << std::sqrt(norm2(U)) << std::endl;
|
||||
// Generalised momenta
|
||||
// Derivative of the kinetic term must be computed before
|
||||
// Mom is the momenta and gets updated by the
|
||||
// actions derivatives
|
||||
MomentaField MomDer(P.Mom.Grid());
|
||||
P.M.ImportGauge(U);
|
||||
P.DerivativeU(P.Mom, MomDer);
|
||||
std::cout << GridLogIntegrator << "MomDer update_P2: " << std::sqrt(norm2(MomDer)) << std::endl;
|
||||
// Mom -= MomDer * ep;
|
||||
Mom -= MomDer * ep * HMC_MOMENTUM_DENOMINATOR;
|
||||
std::cout << GridLogIntegrator << "Mom update_P2: " << std::sqrt(norm2(Mom)) << std::endl;
|
||||
|
||||
// Auxiliary fields
|
||||
P.update_auxiliary_momenta(ep*0.5 );
|
||||
P.AuxiliaryFieldsDerivative(MomDer);
|
||||
std::cout << GridLogIntegrator << "MomDer(Aux) update_P2: " << std::sqrt(norm2(Mom)) << std::endl;
|
||||
// Mom -= MomDer * ep;
|
||||
Mom -= MomDer * ep * HMC_MOMENTUM_DENOMINATOR;
|
||||
P.update_auxiliary_momenta(ep*0.5 );
|
||||
|
||||
for (int a = 0; a < as[level].actions.size(); ++a) {
|
||||
double start_full = usecond();
|
||||
Field force(U.Grid());
|
||||
conformable(U.Grid(), Mom.Grid());
|
||||
|
||||
Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared);
|
||||
double start_force = usecond();
|
||||
as[level].actions.at(a)->deriv(Us, force); // deriv should NOT include Ta
|
||||
|
||||
std::cout << GridLogIntegrator << "Smearing (on/off): " << as[level].actions.at(a)->is_smeared << std::endl;
|
||||
if (as[level].actions.at(a)->is_smeared) Smearer.smeared_force(force);
|
||||
force = FieldImplementation::projectForce(force); // Ta for gauge fields
|
||||
double end_force = usecond();
|
||||
Real force_abs = std::sqrt(norm2(force)/U.Grid()->gSites());
|
||||
std::cout << GridLogIntegrator << "["<<level<<"]["<<a<<"] Force average: " << force_abs << std::endl;
|
||||
Mom -= force * ep* HMC_MOMENTUM_DENOMINATOR;;
|
||||
double end_full = usecond();
|
||||
double time_full = (end_full - start_full) / 1e3;
|
||||
double time_force = (end_force - start_force) / 1e3;
|
||||
std::cout << GridLogMessage << "["<<level<<"]["<<a<<"] P update elapsed time: " << time_full << " ms (force: " << time_force << " ms)" << std::endl;
|
||||
}
|
||||
|
||||
// Force from the other representations
|
||||
as[level].apply(update_P_hireps, Representations, Mom, U, ep);
|
||||
}
|
||||
|
||||
void implicit_update_P(Field& U, int level, double ep, double ep1, bool intermediate = false) {
|
||||
t_P[level] += ep;
|
||||
|
||||
double ep2= ep-ep1;
|
||||
|
||||
std::cout << GridLogIntegrator << "[" << level << "] P "
|
||||
<< " dt " << ep << " : t_P " << t_P[level] << std::endl;
|
||||
std::cout << GridLogIntegrator << "U before implicit_update_P: " << std::sqrt(norm2(U)) << std::endl;
|
||||
// Fundamental updates, include smearing
|
||||
MomentaField Msum(P.Mom.Grid());
|
||||
Msum = Zero();
|
||||
for (int a = 0; a < as[level].actions.size(); ++a) {
|
||||
// Compute the force terms for the lagrangian part
|
||||
// We need to compute the derivative of the actions
|
||||
// only once
|
||||
Field force(U.Grid());
|
||||
conformable(U.Grid(), P.Mom.Grid());
|
||||
Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared);
|
||||
as[level].actions.at(a)->deriv(Us, force); // deriv should NOT include Ta
|
||||
|
||||
std::cout << GridLogIntegrator << "Smearing (on/off): " << as[level].actions.at(a)->is_smeared << std::endl;
|
||||
if (as[level].actions.at(a)->is_smeared) Smearer.smeared_force(force);
|
||||
force = FieldImplementation::projectForce(force); // Ta for gauge fields
|
||||
Real force_abs = std::sqrt(norm2(force) / U.Grid()->gSites());
|
||||
std::cout << GridLogIntegrator << "|Force| site average: " << force_abs
|
||||
<< std::endl;
|
||||
Msum += force;
|
||||
}
|
||||
|
||||
MomentaField NewMom = P.Mom;
|
||||
MomentaField OldMom = P.Mom;
|
||||
double threshold = Params.RMHMCTol;
|
||||
P.M.ImportGauge(U);
|
||||
MomentaField MomDer(P.Mom.Grid());
|
||||
MomentaField MomDer1(P.Mom.Grid());
|
||||
MomentaField AuxDer(P.Mom.Grid());
|
||||
MomDer1 = Zero();
|
||||
MomentaField diff(P.Mom.Grid());
|
||||
double factor = 2.0;
|
||||
if (intermediate){
|
||||
P.DerivativeU(P.Mom, MomDer1);
|
||||
factor = 1.0;
|
||||
}
|
||||
// std::cout << GridLogIntegrator << "MomDer1 implicit_update_P: " << std::sqrt(norm2(MomDer1)) << std::endl;
|
||||
|
||||
// Auxiliary fields
|
||||
P.update_auxiliary_momenta(ep1);
|
||||
P.AuxiliaryFieldsDerivative(AuxDer);
|
||||
Msum += AuxDer;
|
||||
|
||||
|
||||
// Here run recursively
|
||||
int counter = 1;
|
||||
RealD RelativeError;
|
||||
do {
|
||||
std::cout << GridLogIntegrator << "UpdateP implicit step "<< counter << std::endl;
|
||||
|
||||
// Compute the derivative of the kinetic term
|
||||
// with respect to the gauge field
|
||||
P.DerivativeU(NewMom, MomDer);
|
||||
Real force_abs = std::sqrt(norm2(MomDer) / U.Grid()->gSites());
|
||||
std::cout << GridLogIntegrator << "|Force| laplacian site average: " << force_abs
|
||||
<< std::endl;
|
||||
|
||||
// NewMom = P.Mom - ep* 0.5 * HMC_MOMENTUM_DENOMINATOR * (2.0*Msum + factor*MomDer + MomDer1);// simplify
|
||||
NewMom = P.Mom - HMC_MOMENTUM_DENOMINATOR * (ep*Msum + ep1* factor*MomDer + ep2* MomDer1);// simplify
|
||||
diff = NewMom - OldMom;
|
||||
counter++;
|
||||
RelativeError = std::sqrt(norm2(diff))/std::sqrt(norm2(NewMom));
|
||||
std::cout << GridLogIntegrator << "UpdateP RelativeError: " << RelativeError << std::endl;
|
||||
OldMom = NewMom;
|
||||
} while (RelativeError > threshold);
|
||||
|
||||
P.Mom = NewMom;
|
||||
std::cout << GridLogIntegrator << "NewMom implicit_update_P: " << std::sqrt(norm2(NewMom)) << std::endl;
|
||||
|
||||
// update the auxiliary fields momenta
|
||||
P.update_auxiliary_momenta(ep2);
|
||||
}
|
||||
|
||||
void implicit_update_P(Field& U, int level, double ep, bool intermediate = false) {
|
||||
implicit_update_P( U, level, ep, ep*0.5, intermediate );
|
||||
}
|
||||
|
||||
void update_U(Field& U, double ep)
|
||||
{
|
||||
update_U(P, U, ep);
|
||||
update_U(P.Mom, U, ep);
|
||||
|
||||
t_U += ep;
|
||||
int fl = levels - 1;
|
||||
@ -191,12 +318,8 @@ protected:
|
||||
|
||||
void update_U(MomentaField& Mom, Field& U, double ep)
|
||||
{
|
||||
MomentaField MomFiltered(Mom.Grid());
|
||||
MomFiltered = Mom;
|
||||
MomFilter->applyFilter(MomFiltered);
|
||||
|
||||
// exponential of Mom*U in the gauge fields case
|
||||
FieldImplementation::update_field(MomFiltered, U, ep);
|
||||
FieldImplementation::update_field(Mom, U, ep);
|
||||
|
||||
// Update the smeared fields, can be implemented as observer
|
||||
Smearer.set_Field(U);
|
||||
@ -205,18 +328,74 @@ protected:
|
||||
Representations.update(U); // void functions if fundamental representation
|
||||
}
|
||||
|
||||
void implicit_update_U(Field&U, double ep, double ep1 ){
|
||||
double ep2=ep-ep1;
|
||||
t_U += ep;
|
||||
int fl = levels - 1;
|
||||
std::cout << GridLogIntegrator << " " << "[" << fl << "] U " << " dt " << ep << " : t_U " << t_U << std::endl;
|
||||
std::cout << GridLogIntegrator << "U before implicit_update_U: " << std::sqrt(norm2(U)) << std::endl;
|
||||
|
||||
MomentaField Mom1(P.Mom.Grid());
|
||||
MomentaField Mom2(P.Mom.Grid());
|
||||
RealD RelativeError;
|
||||
Field diff(U.Grid());
|
||||
Real threshold = Params.RMHMCTol;
|
||||
int counter = 1;
|
||||
int MaxCounter = 100;
|
||||
|
||||
Field OldU = U;
|
||||
Field NewU = U;
|
||||
|
||||
P.M.ImportGauge(U);
|
||||
P.DerivativeP(Mom1); // first term in the derivative
|
||||
std::cout << GridLogIntegrator << "implicit_update_U: Mom1: " << std::sqrt(norm2(Mom1)) << std::endl;
|
||||
|
||||
P.update_auxiliary_fields(ep1);
|
||||
|
||||
|
||||
MomentaField sum=Mom1;
|
||||
do {
|
||||
std::cout << GridLogIntegrator << "UpdateU implicit step "<< counter << std::endl;
|
||||
|
||||
P.DerivativeP(Mom2); // second term in the derivative, on the updated U
|
||||
std::cout << GridLogIntegrator << "implicit_update_U: Mom1: " << std::sqrt(norm2(Mom1)) << std::endl;
|
||||
sum = (Mom1*ep1 + Mom2*ep2);
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
auto Umu = PeekIndex<LorentzIndex>(U, mu);
|
||||
auto Pmu = PeekIndex<LorentzIndex>(sum, mu);
|
||||
Umu = expMat(Pmu, 1, 12) * Umu;
|
||||
PokeIndex<LorentzIndex>(NewU, ProjectOnGroup(Umu), mu);
|
||||
}
|
||||
|
||||
diff = NewU - OldU;
|
||||
RelativeError = std::sqrt(norm2(diff))/std::sqrt(norm2(NewU));
|
||||
std::cout << GridLogIntegrator << "UpdateU RelativeError: " << RelativeError << std::endl;
|
||||
|
||||
P.M.ImportGauge(NewU);
|
||||
OldU = NewU; // some redundancy to be eliminated
|
||||
counter++;
|
||||
} while (RelativeError > threshold && counter < MaxCounter);
|
||||
|
||||
U = NewU;
|
||||
std::cout << GridLogIntegrator << "NewU implicit_update_U: " << std::sqrt(norm2(U)) << std::endl;
|
||||
P.update_auxiliary_fields(ep2);
|
||||
}
|
||||
|
||||
|
||||
virtual void step(Field& U, int level, int first, int last) = 0;
|
||||
|
||||
public:
|
||||
Integrator(GridBase* grid, IntegratorParameters Par,
|
||||
ActionSet<Field, RepresentationPolicy>& Aset,
|
||||
SmearingPolicy& Sm)
|
||||
SmearingPolicy& Sm, Metric<MomentaField>& M)
|
||||
: Params(Par),
|
||||
as(Aset),
|
||||
P(grid),
|
||||
P(grid, M),
|
||||
levels(Aset.size()),
|
||||
Smearer(Sm),
|
||||
Representations(grid)
|
||||
Representations(grid),
|
||||
Saux(0.),Smom(0.),Sg(0.)
|
||||
{
|
||||
t_P.resize(levels, 0.0);
|
||||
t_U = 0.0;
|
||||
@ -332,7 +511,8 @@ public:
|
||||
|
||||
void reverse_momenta()
|
||||
{
|
||||
P *= -1.0;
|
||||
P.Mom *= -1.0;
|
||||
P.AuxMom *= -1.0;
|
||||
}
|
||||
|
||||
// to be used by the actionlevel class to iterate
|
||||
@ -351,11 +531,14 @@ public:
|
||||
// Initialization of momenta and actions
|
||||
void refresh(Field& U, GridSerialRNG & sRNG, GridParallelRNG& pRNG)
|
||||
{
|
||||
assert(P.Grid() == U.Grid());
|
||||
assert(P.Mom.Grid() == U.Grid());
|
||||
std::cout << GridLogIntegrator << "Integrator refresh" << std::endl;
|
||||
|
||||
std::cout << GridLogIntegrator << "Generating momentum" << std::endl;
|
||||
FieldImplementation::generate_momenta(P, sRNG, pRNG);
|
||||
// FieldImplementation::generate_momenta(P.Mom, sRNG, pRNG);
|
||||
P.M.ImportGauge(U);
|
||||
P.MomentaDistribution(sRNG,pRNG);
|
||||
|
||||
|
||||
// Update the smeared fields, can be implemented as observer
|
||||
// necessary to keep the fields updated even after a reject
|
||||
@ -377,14 +560,9 @@ public:
|
||||
auto name = as[level].actions.at(actionID)->action_name();
|
||||
std::cout << GridLogMessage << "refresh [" << level << "][" << actionID << "] "<<name << std::endl;
|
||||
|
||||
Field& Us = Smearer.get_U(as[level].actions.at(actionID)->is_smeared);
|
||||
|
||||
std::cout << GridLogMessage << "AuditRefresh["<<level<<"]["<<actionID<<"] before"<<std::endl;
|
||||
|
||||
as[level].actions.at(actionID)->refresh_timer_start();
|
||||
as[level].actions.at(actionID)->refresh(Us, sRNG, pRNG);
|
||||
as[level].actions.at(actionID)->refresh(Smearer, sRNG, pRNG);
|
||||
as[level].actions.at(actionID)->refresh_timer_stop();
|
||||
std::cout << GridLogMessage << "AuditRefresh["<<level<<"]["<<actionID<<"] after"<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
@ -415,9 +593,22 @@ public:
|
||||
|
||||
std::cout << GridLogIntegrator << "Integrator action\n";
|
||||
|
||||
RealD H = - FieldImplementation::FieldSquareNorm(P)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
|
||||
// RealD H = - FieldImplementation::FieldSquareNorm(P.Mom)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
|
||||
// RealD Hterm;
|
||||
|
||||
// static RealD Saux=0.,Smom=0.,Sg=0.;
|
||||
|
||||
RealD H = - FieldImplementation::FieldSquareNorm(P.Mom)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
|
||||
std::cout << GridLogMessage << "S:FieldSquareNorm H_p = " << H << "\n";
|
||||
std::cout << GridLogMessage << "S:dSField = " << H-Smom << "\n";
|
||||
Smom=H;
|
||||
P.M.ImportGauge(U);
|
||||
RealD Hterm = - P.MomentaAction();
|
||||
std::cout << GridLogMessage << "S:Momentum action H_p = " << Hterm << "\n";
|
||||
std::cout << GridLogMessage << "S:dSMom = " << Hterm-Saux << "\n";
|
||||
Saux=Hterm;
|
||||
H = Hterm;
|
||||
|
||||
RealD Hterm;
|
||||
|
||||
// Actions
|
||||
for (int level = 0; level < as.size(); ++level) {
|
||||
@ -425,10 +616,9 @@ public:
|
||||
|
||||
// get gauge field from the SmearingPolicy and
|
||||
// based on the boolean is_smeared in actionID
|
||||
Field& Us = Smearer.get_U(as[level].actions.at(actionID)->is_smeared);
|
||||
std::cout << GridLogMessage << "S [" << level << "][" << actionID << "] action eval " << std::endl;
|
||||
as[level].actions.at(actionID)->S_timer_start();
|
||||
Hterm = as[level].actions.at(actionID)->S(Us);
|
||||
Hterm = as[level].actions.at(actionID)->S(Smearer);
|
||||
as[level].actions.at(actionID)->S_timer_stop();
|
||||
std::cout << GridLogMessage << "S [" << level << "][" << actionID << "] H = " << Hterm << std::endl;
|
||||
H += Hterm;
|
||||
@ -460,21 +650,29 @@ public:
|
||||
|
||||
std::cout << GridLogIntegrator << "Integrator initial action\n";
|
||||
|
||||
RealD H = - FieldImplementation::FieldSquareNorm(P)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
|
||||
|
||||
RealD Hterm;
|
||||
// RealD H = - FieldImplementation::FieldSquareNorm(P.Mom)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
|
||||
// RealD Hterm;
|
||||
RealD H = - FieldImplementation::FieldSquareNorm(P.Mom)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
|
||||
std::cout << GridLogMessage << "S:FieldSquareNorm H_p = " << H << "\n";
|
||||
std::cout << GridLogMessage << "S:dSField = " << H-Smom << "\n";
|
||||
Smom=H;
|
||||
P.M.ImportGauge(U);
|
||||
RealD Hterm = - P.MomentaAction();
|
||||
std::cout << GridLogMessage << "S:Momentum action H_p = " << Hterm << "\n";
|
||||
std::cout << GridLogMessage << "S:dSMom = " << Hterm-Saux << "\n";
|
||||
Saux=Hterm;
|
||||
H = Hterm;
|
||||
|
||||
// Actions
|
||||
for (int level = 0; level < as.size(); ++level) {
|
||||
for (int actionID = 0; actionID < as[level].actions.size(); ++actionID) {
|
||||
// get gauge field from the SmearingPolicy and
|
||||
// based on the boolean is_smeared in actionID
|
||||
Field& Us = Smearer.get_U(as[level].actions.at(actionID)->is_smeared);
|
||||
std::cout << GridLogMessage << "S [" << level << "][" << actionID << "] action eval " << std::endl;
|
||||
as[level].actions.at(actionID)->S_timer_start();
|
||||
|
||||
Hterm = as[level].actions.at(actionID)->Sinitial(Us);
|
||||
as[level].actions.at(actionID)->S_timer_stop();
|
||||
as[level].actions.at(actionID)->S_timer_start();
|
||||
Hterm = as[level].actions.at(actionID)->S(Smearer);
|
||||
as[level].actions.at(actionID)->S_timer_stop();
|
||||
|
||||
std::cout << GridLogMessage << "S [" << level << "][" << actionID << "] H = " << Hterm << std::endl;
|
||||
H += Hterm;
|
||||
@ -486,7 +684,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void integrate(Field& U)
|
||||
void integrate(Field& U, int traj=-1 )
|
||||
{
|
||||
// reset the clocks
|
||||
t_U = 0;
|
||||
@ -498,6 +696,12 @@ public:
|
||||
int first_step = (stp == 0);
|
||||
int last_step = (stp == Params.MDsteps - 1);
|
||||
this->step(U, 0, first_step, last_step);
|
||||
if (traj>=0){
|
||||
std::string file("./config."+std::to_string(traj)+"_"+std::to_string(stp+1) );
|
||||
int precision32 = 0;
|
||||
int tworow = 0;
|
||||
NerscIO::writeConfiguration(U,file,tworow,precision32);
|
||||
}
|
||||
}
|
||||
|
||||
// Check the clocks all match on all levels
|
||||
@ -507,7 +711,6 @@ public:
|
||||
}
|
||||
|
||||
FieldImplementation::Project(U);
|
||||
|
||||
// and that we indeed got to the end of the trajectory
|
||||
assert(fabs(t_U - Params.trajL) < 1.0e-6);
|
||||
|
||||
|
@ -102,8 +102,8 @@ public:
|
||||
|
||||
std::string integrator_name(){return "LeapFrog";}
|
||||
|
||||
LeapFrog(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm){};
|
||||
LeapFrog(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm,M){};
|
||||
|
||||
void step(Field& U, int level, int _first, int _last) {
|
||||
int fl = this->as.size() - 1;
|
||||
@ -140,14 +140,14 @@ template <class FieldImplementation_, class SmearingPolicy, class Representation
|
||||
class MinimumNorm2 : public Integrator<FieldImplementation_, SmearingPolicy, RepresentationPolicy>
|
||||
{
|
||||
private:
|
||||
const RealD lambda = 0.1931833275037836;
|
||||
// const RealD lambda = 0.1931833275037836;
|
||||
|
||||
public:
|
||||
typedef FieldImplementation_ FieldImplementation;
|
||||
INHERIT_FIELD_TYPES(FieldImplementation);
|
||||
|
||||
MinimumNorm2(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm){};
|
||||
MinimumNorm2(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm,M){};
|
||||
|
||||
std::string integrator_name(){return "MininumNorm2";}
|
||||
|
||||
@ -155,6 +155,11 @@ public:
|
||||
// level : current level
|
||||
// fl : final level
|
||||
// eps : current step size
|
||||
assert(level<3);
|
||||
RealD lambda= this->Params.lambda0;
|
||||
if (level>0) lambda= this->Params.lambda1;
|
||||
if (level>1) lambda= this->Params.lambda2;
|
||||
std::cout << GridLogMessage << "level: "<<level<< "lambda: "<<lambda<<std::endl;
|
||||
|
||||
int fl = this->as.size() - 1;
|
||||
|
||||
@ -210,9 +215,9 @@ public:
|
||||
// Looks like dH scales as dt^4. tested wilson/wilson 2 level.
|
||||
ForceGradient(GridBase* grid, IntegratorParameters Par,
|
||||
ActionSet<Field, RepresentationPolicy>& Aset,
|
||||
SmearingPolicy& Sm)
|
||||
SmearingPolicy& Sm, Metric<Field>& M)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
|
||||
grid, Par, Aset, Sm){};
|
||||
grid, Par, Aset, Sm,M){};
|
||||
|
||||
std::string integrator_name(){return "ForceGradient";}
|
||||
|
||||
@ -275,6 +280,255 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Riemannian Manifold HMC
|
||||
// Girolami et al
|
||||
////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// correct
|
||||
template <class FieldImplementation, class SmearingPolicy,
|
||||
class RepresentationPolicy =
|
||||
Representations<FundamentalRepresentation> >
|
||||
class ImplicitLeapFrog : public Integrator<FieldImplementation, SmearingPolicy,
|
||||
RepresentationPolicy> {
|
||||
public:
|
||||
typedef ImplicitLeapFrog<FieldImplementation, SmearingPolicy, RepresentationPolicy>
|
||||
Algorithm;
|
||||
INHERIT_FIELD_TYPES(FieldImplementation);
|
||||
|
||||
// Riemannian manifold metric operator
|
||||
// Hermitian operator Fisher
|
||||
|
||||
std::string integrator_name(){return "ImplicitLeapFrog";}
|
||||
|
||||
ImplicitLeapFrog(GridBase* grid, IntegratorParameters Par,
|
||||
ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
|
||||
grid, Par, Aset, Sm, M){};
|
||||
|
||||
void step(Field& U, int level, int _first, int _last) {
|
||||
int fl = this->as.size() - 1;
|
||||
// level : current level
|
||||
// fl : final level
|
||||
// eps : current step size
|
||||
|
||||
// Get current level step size
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps;
|
||||
for (int l = 0; l <= level; ++l) eps /= this->as[l].multiplier;
|
||||
|
||||
int multiplier = this->as[level].multiplier;
|
||||
for (int e = 0; e < multiplier; ++e) {
|
||||
int first_step = _first && (e == 0);
|
||||
int last_step = _last && (e == multiplier - 1);
|
||||
|
||||
if (first_step) { // initial half step
|
||||
this->implicit_update_P(U, level, eps / 2.0);
|
||||
}
|
||||
|
||||
if (level == fl) { // lowest level
|
||||
this->implicit_update_U(U, eps,eps/2.);
|
||||
} else { // recursive function call
|
||||
this->step(U, level + 1, first_step, last_step);
|
||||
}
|
||||
|
||||
//int mm = last_step ? 1 : 2;
|
||||
if (last_step){
|
||||
this->update_P2(U, level, eps / 2.0);
|
||||
} else {
|
||||
this->implicit_update_P(U, level, eps, true);// works intermediate step
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class FieldImplementation, class SmearingPolicy,
|
||||
class RepresentationPolicy =
|
||||
Representations<FundamentalRepresentation> >
|
||||
class ImplicitMinimumNorm2 : public Integrator<FieldImplementation, SmearingPolicy,
|
||||
RepresentationPolicy> {
|
||||
private:
|
||||
// const RealD lambda = 0.1931833275037836;
|
||||
|
||||
public:
|
||||
INHERIT_FIELD_TYPES(FieldImplementation);
|
||||
|
||||
ImplicitMinimumNorm2(GridBase* grid, IntegratorParameters Par,
|
||||
ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
|
||||
grid, Par, Aset, Sm, M){};
|
||||
|
||||
std::string integrator_name(){return "ImplicitMininumNorm2";}
|
||||
|
||||
void step(Field& U, int level, int _first, int _last) {
|
||||
// level : current level
|
||||
// fl : final level
|
||||
// eps : current step size
|
||||
|
||||
int fl = this->as.size() - 1;
|
||||
// assert(Params.lambda.size()>level);
|
||||
// RealD lambda= Params.lambda[level];
|
||||
assert(level<3);
|
||||
RealD lambda= this->Params.lambda0;
|
||||
if (level>0) lambda= this->Params.lambda1;
|
||||
if (level>1) lambda= this->Params.lambda2;
|
||||
std::cout << GridLogMessage << "level: "<<level<< "lambda: "<<lambda<<std::endl;
|
||||
|
||||
if(level<fl){
|
||||
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
|
||||
for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
|
||||
|
||||
// Nesting: 2xupdate_U of size eps/2
|
||||
// Next level is eps/2/multiplier
|
||||
|
||||
int multiplier = this->as[level].multiplier;
|
||||
for (int e = 0; e < multiplier; ++e) { // steps per step
|
||||
|
||||
int first_step = _first && (e == 0);
|
||||
int last_step = _last && (e == multiplier - 1);
|
||||
|
||||
if (first_step) { // initial half step
|
||||
this->update_P(U, level, lambda * eps);
|
||||
}
|
||||
|
||||
this->step(U, level + 1, first_step, 0);
|
||||
|
||||
this->update_P(U, level, (1.0 - 2.0 * lambda) * eps);
|
||||
|
||||
this->step(U, level + 1, 0, last_step);
|
||||
|
||||
int mm = (last_step) ? 1 : 2;
|
||||
this->update_P(U, level, lambda * eps * mm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // last level
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
|
||||
for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
|
||||
|
||||
// Nesting: 2xupdate_U of size eps/2
|
||||
// Next level is eps/2/multiplier
|
||||
|
||||
int multiplier = this->as[level].multiplier;
|
||||
for (int e = 0; e < multiplier; ++e) { // steps per step
|
||||
|
||||
int first_step = _first && (e == 0);
|
||||
int last_step = _last && (e == multiplier - 1);
|
||||
|
||||
if (first_step) { // initial half step
|
||||
this->implicit_update_P(U, level, lambda * eps);
|
||||
}
|
||||
|
||||
this->implicit_update_U(U, 0.5 * eps,lambda*eps);
|
||||
|
||||
this->implicit_update_P(U, level, (1.0 - 2.0 * lambda) * eps, true);
|
||||
|
||||
this->implicit_update_U(U, 0.5 * eps, (0.5-lambda)*eps);
|
||||
|
||||
if (last_step) {
|
||||
this->update_P2(U, level, eps * lambda);
|
||||
} else {
|
||||
this->implicit_update_P(U, level, lambda * eps*2.0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template <class FieldImplementation, class SmearingPolicy,
|
||||
class RepresentationPolicy =
|
||||
Representations<FundamentalRepresentation> >
|
||||
class ImplicitCampostrini : public Integrator<FieldImplementation, SmearingPolicy,
|
||||
RepresentationPolicy> {
|
||||
private:
|
||||
// const RealD lambda = 0.1931833275037836;
|
||||
|
||||
public:
|
||||
INHERIT_FIELD_TYPES(FieldImplementation);
|
||||
|
||||
ImplicitCampostrini(GridBase* grid, IntegratorParameters Par,
|
||||
ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
|
||||
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
|
||||
grid, Par, Aset, Sm, M){};
|
||||
|
||||
std::string integrator_name(){return "ImplicitCampostrini";}
|
||||
|
||||
void step(Field& U, int level, int _first, int _last) {
|
||||
// level : current level
|
||||
// fl : final level
|
||||
// eps : current step size
|
||||
|
||||
int fl = this->as.size() - 1;
|
||||
// assert(Params.lambda.size()>level);
|
||||
// RealD lambda= Params.lambda[level];
|
||||
assert(level<3);
|
||||
RealD lambda= this->Params.lambda0;
|
||||
if (level>0) lambda= this->Params.lambda1;
|
||||
if (level>1) lambda= this->Params.lambda2;
|
||||
std::cout << GridLogMessage << "level: "<<level<< "lambda: "<<lambda<<std::endl;
|
||||
|
||||
RealD sigma=pow(2.0,1./3.);
|
||||
|
||||
if(level<fl){
|
||||
//Still Omelyan. Needs to change step() to accept variable stepsize
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
|
||||
for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
|
||||
|
||||
// Nesting: 2xupdate_U of size eps/2
|
||||
// Next level is eps/2/multiplier
|
||||
|
||||
int multiplier = this->as[level].multiplier;
|
||||
for (int e = 0; e < multiplier; ++e) { // steps per step
|
||||
|
||||
int first_step = _first && (e == 0);
|
||||
int last_step = _last && (e == multiplier - 1);
|
||||
|
||||
if (first_step) { // initial half step
|
||||
this->update_P(U, level, lambda * eps);
|
||||
}
|
||||
|
||||
this->step(U, level + 1, first_step, 0);
|
||||
|
||||
this->update_P(U, level, (1.0 - 2.0 * lambda) * eps);
|
||||
|
||||
this->step(U, level + 1, 0, last_step);
|
||||
|
||||
int mm = (last_step) ? 1 : 2;
|
||||
this->update_P(U, level, lambda * eps * mm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // last level
|
||||
RealD dt = this->Params.trajL/this->Params.MDsteps * 2.0;
|
||||
for (int l = 0; l <= level; ++l) dt /= 2.0 * this->as[l].multiplier;
|
||||
|
||||
RealD epsilon = dt/(2.0 - sigma);
|
||||
|
||||
int multiplier = this->as[level].multiplier;
|
||||
for (int e = 0; e < multiplier; ++e) { // steps per step
|
||||
|
||||
int first_step = _first && (e == 0);
|
||||
int last_step = _last && (e == multiplier - 1);
|
||||
// initial half step
|
||||
if (first_step) { this->implicit_update_P(U, level, epsilon*0.5); }
|
||||
this->implicit_update_U(U, epsilon,epsilon*0.5);
|
||||
this->implicit_update_P(U, level, (1.0 - sigma) * epsilon *0.5, epsilon*0.5, true);
|
||||
this->implicit_update_U(U, -epsilon*sigma, -epsilon*sigma*0.5);
|
||||
this->implicit_update_P(U, level, (1.0 - sigma) * epsilon *0.5, -epsilon*sigma*0.5, true);
|
||||
this->implicit_update_U(U, epsilon,epsilon*0.5);
|
||||
if (last_step) { this->update_P2(U, level, epsilon*0.5 ); }
|
||||
else
|
||||
this->implicit_update_P(U, level, epsilon,epsilon*0.5);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif // INTEGRATOR_INCLUDED
|
||||
|
@ -34,6 +34,13 @@ NAMESPACE_BEGIN(Grid);
|
||||
template <class Field>
|
||||
class HmcObservable {
|
||||
public:
|
||||
virtual void TrajectoryComplete(int traj,
|
||||
ConfigurationBase<Field> &SmartConfig,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG)
|
||||
{
|
||||
TrajectoryComplete(traj,SmartConfig.get_U(false),sRNG,pRNG); // Unsmeared observable
|
||||
};
|
||||
virtual void TrajectoryComplete(int traj,
|
||||
Field &U,
|
||||
GridSerialRNG &sRNG,
|
||||
|
@ -42,6 +42,18 @@ public:
|
||||
// necessary for HmcObservable compatibility
|
||||
typedef typename Impl::Field Field;
|
||||
|
||||
virtual void TrajectoryComplete(int traj,
|
||||
ConfigurationBase<Field> &SmartConfig,
|
||||
GridSerialRNG &sRNG,
|
||||
GridParallelRNG &pRNG)
|
||||
{
|
||||
std::cout << GridLogMessage << "+++++++++++++++++++"<<std::endl;
|
||||
std::cout << GridLogMessage << "Unsmeared plaquette"<<std::endl;
|
||||
TrajectoryComplete(traj,SmartConfig.get_U(false),sRNG,pRNG); // Unsmeared observable
|
||||
std::cout << GridLogMessage << "Smeared plaquette"<<std::endl;
|
||||
TrajectoryComplete(traj,SmartConfig.get_U(true),sRNG,pRNG); // Unsmeared observable
|
||||
std::cout << GridLogMessage << "+++++++++++++++++++"<<std::endl;
|
||||
};
|
||||
void TrajectoryComplete(int traj,
|
||||
Field &U,
|
||||
GridSerialRNG &sRNG,
|
||||
|
@ -13,7 +13,7 @@ NAMESPACE_BEGIN(Grid);
|
||||
* Empty since HMC updates already the fundamental representation
|
||||
*/
|
||||
|
||||
template <int ncolour>
|
||||
template <int ncolour, class group_name>
|
||||
class FundamentalRep {
|
||||
public:
|
||||
static const int Dimension = ncolour;
|
||||
@ -21,7 +21,7 @@ public:
|
||||
|
||||
// typdef to be used by the Representations class in HMC to get the
|
||||
// types for the higher representation fields
|
||||
typedef typename SU<ncolour>::LatticeMatrix LatticeMatrix;
|
||||
typedef typename GaugeGroup<ncolour,group_name>::LatticeMatrix LatticeMatrix;
|
||||
typedef LatticeGaugeField LatticeField;
|
||||
|
||||
explicit FundamentalRep(GridBase* grid) {} //do nothing
|
||||
@ -45,7 +45,8 @@ public:
|
||||
|
||||
|
||||
|
||||
typedef FundamentalRep<Nc> FundamentalRepresentation;
|
||||
typedef FundamentalRep<Nc,GroupName::SU> FundamentalRepresentation;
|
||||
typedef FundamentalRep<Nc,GroupName::Sp> SpFundamentalRepresentation;
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
|
@ -20,14 +20,14 @@ NAMESPACE_BEGIN(Grid);
|
||||
* in the SUnTwoIndex.h file
|
||||
*/
|
||||
|
||||
template <int ncolour, TwoIndexSymmetry S>
|
||||
template <int ncolour, TwoIndexSymmetry S, class group_name = GroupName::SU>
|
||||
class TwoIndexRep {
|
||||
public:
|
||||
// typdef to be used by the Representations class in HMC to get the
|
||||
// types for the higher representation fields
|
||||
typedef typename SU_TwoIndex<ncolour, S>::LatticeTwoIndexMatrix LatticeMatrix;
|
||||
typedef typename SU_TwoIndex<ncolour, S>::LatticeTwoIndexField LatticeField;
|
||||
static const int Dimension = ncolour * (ncolour + S) / 2;
|
||||
typedef typename GaugeGroupTwoIndex<ncolour, S, group_name>::LatticeTwoIndexMatrix LatticeMatrix;
|
||||
typedef typename GaugeGroupTwoIndex<ncolour, S, group_name>::LatticeTwoIndexField LatticeField;
|
||||
static const int Dimension = GaugeGroupTwoIndex<ncolour,S,group_name>::Dimension;
|
||||
static const bool isFundamental = false;
|
||||
|
||||
LatticeField U;
|
||||
@ -43,10 +43,10 @@ public:
|
||||
U = Zero();
|
||||
LatticeColourMatrix tmp(Uin.Grid());
|
||||
|
||||
Vector<typename SU<ncolour>::Matrix> eij(Dimension);
|
||||
Vector<typename GaugeGroup<ncolour,group_name>::Matrix> eij(Dimension);
|
||||
|
||||
for (int a = 0; a < Dimension; a++)
|
||||
SU_TwoIndex<ncolour, S>::base(a, eij[a]);
|
||||
GaugeGroupTwoIndex<ncolour, S, group_name>::base(a, eij[a]);
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
auto Uin_mu = peekLorentz(Uin, mu);
|
||||
@ -71,7 +71,7 @@ public:
|
||||
|
||||
out_mu = Zero();
|
||||
|
||||
typename SU<ncolour>::LatticeAlgebraVector h(in.Grid());
|
||||
typename GaugeGroup<ncolour, group_name>::LatticeAlgebraVector h(in.Grid());
|
||||
projectOnAlgebra(h, in_mu, double(Nc + 2 * S)); // factor T(r)/T(fund)
|
||||
FundamentalLieAlgebraMatrix(h, out_mu); // apply scale only once
|
||||
pokeLorentz(out, out_mu, mu);
|
||||
@ -80,20 +80,23 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void projectOnAlgebra(typename SU<ncolour>::LatticeAlgebraVector &h_out,
|
||||
void projectOnAlgebra(typename GaugeGroup<ncolour, group_name>::LatticeAlgebraVector &h_out,
|
||||
const LatticeMatrix &in, Real scale = 1.0) const {
|
||||
SU_TwoIndex<ncolour, S>::projectOnAlgebra(h_out, in, scale);
|
||||
GaugeGroupTwoIndex<ncolour, S,group_name>::projectOnAlgebra(h_out, in, scale);
|
||||
}
|
||||
|
||||
void FundamentalLieAlgebraMatrix(
|
||||
typename SU<ncolour>::LatticeAlgebraVector &h,
|
||||
typename SU<ncolour>::LatticeMatrix &out, Real scale = 1.0) const {
|
||||
SU<ncolour>::FundamentalLieAlgebraMatrix(h, out, scale);
|
||||
typename GaugeGroup<ncolour, group_name>::LatticeAlgebraVector &h,
|
||||
typename GaugeGroup<ncolour, group_name>::LatticeMatrix &out, Real scale = 1.0) const {
|
||||
GaugeGroup<ncolour,group_name>::FundamentalLieAlgebraMatrix(h, out, scale);
|
||||
}
|
||||
};
|
||||
|
||||
typedef TwoIndexRep<Nc, Symmetric> TwoIndexSymmetricRepresentation;
|
||||
typedef TwoIndexRep<Nc, AntiSymmetric> TwoIndexAntiSymmetricRepresentation;
|
||||
typedef TwoIndexRep<Nc, Symmetric, GroupName::SU> TwoIndexSymmetricRepresentation;
|
||||
typedef TwoIndexRep<Nc, AntiSymmetric, GroupName::SU> TwoIndexAntiSymmetricRepresentation;
|
||||
|
||||
typedef TwoIndexRep<Nc, Symmetric, GroupName::Sp> SpTwoIndexSymmetricRepresentation;
|
||||
typedef TwoIndexRep<Nc, AntiSymmetric, GroupName::Sp> SpTwoIndexAntiSymmetricRepresentation;
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
|
@ -7,26 +7,27 @@
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
|
||||
//trivial class for no smearing
|
||||
template< class Impl >
|
||||
class NoSmearing
|
||||
class NoSmearing : public ConfigurationBase<typename Impl::Field>
|
||||
{
|
||||
public:
|
||||
INHERIT_FIELD_TYPES(Impl);
|
||||
|
||||
Field* ThinField;
|
||||
Field* ThinLinks;
|
||||
|
||||
NoSmearing(): ThinField(NULL) {}
|
||||
NoSmearing(): ThinLinks(NULL) {}
|
||||
|
||||
void set_Field(Field& U) { ThinField = &U; }
|
||||
virtual void set_Field(Field& U) { ThinLinks = &U; }
|
||||
|
||||
void smeared_force(Field&) const {}
|
||||
virtual void smeared_force(Field&) {}
|
||||
|
||||
Field& get_SmearedU() { return *ThinField; }
|
||||
virtual Field& get_SmearedU() { return *ThinLinks; }
|
||||
|
||||
Field &get_U(bool smeared = false)
|
||||
virtual Field &get_U(bool smeared = false)
|
||||
{
|
||||
return *ThinField;
|
||||
return *ThinLinks;
|
||||
}
|
||||
};
|
||||
|
||||
@ -42,19 +43,24 @@ public:
|
||||
It stores a list of smeared configurations.
|
||||
*/
|
||||
template <class Gimpl>
|
||||
class SmearedConfiguration
|
||||
class SmearedConfiguration : public ConfigurationBase<typename Gimpl::Field>
|
||||
{
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl);
|
||||
|
||||
private:
|
||||
protected:
|
||||
const unsigned int smearingLevels;
|
||||
Smear_Stout<Gimpl> *StoutSmearing;
|
||||
std::vector<GaugeField> SmearedSet;
|
||||
|
||||
public:
|
||||
GaugeField* ThinLinks; /* Pointer to the thin links configuration */ // move to base???
|
||||
protected:
|
||||
|
||||
// Member functions
|
||||
//====================================================================
|
||||
void fill_smearedSet(GaugeField &U)
|
||||
|
||||
// Overridden in masked version
|
||||
virtual void fill_smearedSet(GaugeField &U)
|
||||
{
|
||||
ThinLinks = &U; // attach the smearing routine to the field U
|
||||
|
||||
@ -82,9 +88,10 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
//====================================================================
|
||||
GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime,
|
||||
const GaugeField& GaugeK) const
|
||||
|
||||
//overridden in masked verson
|
||||
virtual GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime,
|
||||
const GaugeField& GaugeK) const
|
||||
{
|
||||
GridBase* grid = GaugeK.Grid();
|
||||
GaugeField C(grid), SigmaK(grid), iLambda(grid);
|
||||
@ -213,8 +220,6 @@ private:
|
||||
|
||||
//====================================================================
|
||||
public:
|
||||
GaugeField*
|
||||
ThinLinks; /* Pointer to the thin links configuration */
|
||||
|
||||
/* Standard constructor */
|
||||
SmearedConfiguration(GridCartesian* UGrid, unsigned int Nsmear,
|
||||
@ -230,7 +235,7 @@ public:
|
||||
: smearingLevels(0), StoutSmearing(nullptr), SmearedSet(), ThinLinks(NULL) {}
|
||||
|
||||
// attach the smeared routines to the thin links U and fill the smeared set
|
||||
void set_Field(GaugeField &U)
|
||||
virtual void set_Field(GaugeField &U)
|
||||
{
|
||||
double start = usecond();
|
||||
fill_smearedSet(U);
|
||||
@ -240,7 +245,7 @@ public:
|
||||
}
|
||||
|
||||
//====================================================================
|
||||
void smeared_force(GaugeField &SigmaTilde) const
|
||||
virtual void smeared_force(GaugeField &SigmaTilde)
|
||||
{
|
||||
if (smearingLevels > 0)
|
||||
{
|
||||
@ -267,14 +272,16 @@ public:
|
||||
}
|
||||
double end = usecond();
|
||||
double time = (end - start)/ 1e3;
|
||||
std::cout << GridLogMessage << "Smearing force in " << time << " ms" << std::endl;
|
||||
std::cout << GridLogMessage << " GaugeConfiguration: Smeared Force chain rule took " << time << " ms" << std::endl;
|
||||
} // if smearingLevels = 0 do nothing
|
||||
SigmaTilde=Gimpl::projectForce(SigmaTilde); // Ta
|
||||
|
||||
}
|
||||
//====================================================================
|
||||
|
||||
GaugeField& get_SmearedU() { return SmearedSet[smearingLevels - 1]; }
|
||||
virtual GaugeField& get_SmearedU() { return SmearedSet[smearingLevels - 1]; }
|
||||
|
||||
GaugeField &get_U(bool smeared = false)
|
||||
virtual GaugeField &get_U(bool smeared = false)
|
||||
{
|
||||
// get the config, thin links by default
|
||||
if (smeared)
|
||||
|
813
Grid/qcd/smearing/GaugeConfigurationMasked.h
Normal file
813
Grid/qcd/smearing/GaugeConfigurationMasked.h
Normal file
@ -0,0 +1,813 @@
|
||||
/*!
|
||||
@file GaugeConfiguration.h
|
||||
@brief Declares the GaugeConfiguration class
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
/*!
|
||||
@brief Smeared configuration masked container
|
||||
Modified for a multi-subset smearing (aka Luscher Flowed HMC)
|
||||
*/
|
||||
template <class Gimpl>
|
||||
class SmearedConfigurationMasked : public SmearedConfiguration<Gimpl>
|
||||
{
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl);
|
||||
|
||||
private:
|
||||
// These live in base class
|
||||
// const unsigned int smearingLevels;
|
||||
// Smear_Stout<Gimpl> *StoutSmearing;
|
||||
// std::vector<GaugeField> SmearedSet;
|
||||
|
||||
std::vector<LatticeLorentzComplex> masks;
|
||||
|
||||
typedef typename SU3Adjoint::AMatrix AdjMatrix;
|
||||
typedef typename SU3Adjoint::LatticeAdjMatrix AdjMatrixField;
|
||||
typedef typename SU3Adjoint::LatticeAdjVector AdjVectorField;
|
||||
|
||||
// Adjoint vector to GaugeField force
|
||||
void InsertForce(GaugeField &Fdet,AdjVectorField &Fdet_nu,int nu)
|
||||
{
|
||||
Complex ci(0,1);
|
||||
GaugeLinkField Fdet_pol(Fdet.Grid());
|
||||
Fdet_pol=Zero();
|
||||
for(int e=0;e<8;e++){
|
||||
ColourMatrix te;
|
||||
SU3::generator(e, te);
|
||||
auto tmp=peekColour(Fdet_nu,e);
|
||||
Fdet_pol=Fdet_pol + ci*tmp*te; // but norm of te is different.. why?
|
||||
}
|
||||
pokeLorentz(Fdet, Fdet_pol, nu);
|
||||
}
|
||||
void Compute_MpInvJx_dNxxdSy(const GaugeLinkField &PlaqL,const GaugeLinkField &PlaqR, AdjMatrixField MpInvJx,AdjVectorField &Fdet2 )
|
||||
{
|
||||
GaugeLinkField UtaU(PlaqL.Grid());
|
||||
GaugeLinkField D(PlaqL.Grid());
|
||||
AdjMatrixField Dbc(PlaqL.Grid());
|
||||
LatticeComplex tmp(PlaqL.Grid());
|
||||
const int Ngen = SU3Adjoint::Dimension;
|
||||
Complex ci(0,1);
|
||||
ColourMatrix ta,tb,tc;
|
||||
|
||||
for(int a=0;a<Ngen;a++) {
|
||||
SU3::generator(a, ta);
|
||||
// Qlat Tb = 2i Tb^Grid
|
||||
UtaU= 2.0*ci*adj(PlaqL)*ta*PlaqR;
|
||||
for(int c=0;c<Ngen;c++) {
|
||||
SU3::generator(c, tc);
|
||||
D = Ta( (2.0)*ci*tc *UtaU);
|
||||
for(int b=0;b<Ngen;b++){
|
||||
SU3::generator(b, tb);
|
||||
tmp =-trace(ci*tb*D);
|
||||
PokeIndex<ColourIndex>(Dbc,tmp,b,c); // Adjoint rep
|
||||
}
|
||||
}
|
||||
tmp = trace(MpInvJx * Dbc);
|
||||
PokeIndex<ColourIndex>(Fdet2,tmp,a);
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeNxy(const GaugeLinkField &PlaqL,const GaugeLinkField &PlaqR,AdjMatrixField &NxAd)
|
||||
{
|
||||
GaugeLinkField Nx(PlaqL.Grid());
|
||||
const int Ngen = SU3Adjoint::Dimension;
|
||||
Complex ci(0,1);
|
||||
ColourMatrix tb;
|
||||
ColourMatrix tc;
|
||||
for(int b=0;b<Ngen;b++) {
|
||||
SU3::generator(b, tb);
|
||||
Nx = (2.0)*Ta( adj(PlaqL)*ci*tb * PlaqR );
|
||||
for(int c=0;c<Ngen;c++) {
|
||||
SU3::generator(c, tc);
|
||||
auto tmp =closure( -trace(ci*tc*Nx));
|
||||
PokeIndex<ColourIndex>(NxAd,tmp,c,b);
|
||||
}
|
||||
}
|
||||
}
|
||||
void ApplyMask(GaugeField &U,int smr)
|
||||
{
|
||||
LatticeComplex tmp(U.Grid());
|
||||
GaugeLinkField Umu(U.Grid());
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
Umu=PeekIndex<LorentzIndex>(U,mu);
|
||||
tmp=PeekIndex<LorentzIndex>(masks[smr],mu);
|
||||
Umu=Umu*tmp;
|
||||
PokeIndex<LorentzIndex>(U, Umu, mu);
|
||||
}
|
||||
}
|
||||
public:
|
||||
|
||||
void logDetJacobianForceLevel(const GaugeField &U, GaugeField &force ,int smr)
|
||||
{
|
||||
GridBase* grid = U.Grid();
|
||||
ColourMatrix tb;
|
||||
ColourMatrix tc;
|
||||
ColourMatrix ta;
|
||||
GaugeField C(grid);
|
||||
GaugeField Umsk(grid);
|
||||
std::vector<GaugeLinkField> Umu(Nd,grid);
|
||||
GaugeLinkField Cmu(grid); // U and staple; C contains factor of epsilon
|
||||
GaugeLinkField Zx(grid); // U times Staple, contains factor of epsilon
|
||||
GaugeLinkField Nxx(grid); // Nxx fundamental space
|
||||
GaugeLinkField Utmp(grid);
|
||||
GaugeLinkField PlaqL(grid);
|
||||
GaugeLinkField PlaqR(grid);
|
||||
const int Ngen = SU3Adjoint::Dimension;
|
||||
AdjMatrix TRb;
|
||||
ColourMatrix Ident;
|
||||
LatticeComplex cplx(grid);
|
||||
|
||||
AdjVectorField dJdXe_nMpInv(grid);
|
||||
AdjVectorField dJdXe_nMpInv_y(grid);
|
||||
AdjMatrixField MpAd(grid); // Mprime luchang's notes
|
||||
AdjMatrixField MpAdInv(grid); // Mprime inverse
|
||||
AdjMatrixField NxxAd(grid); // Nxx in adjoint space
|
||||
AdjMatrixField JxAd(grid);
|
||||
AdjMatrixField ZxAd(grid);
|
||||
AdjMatrixField mZxAd(grid);
|
||||
AdjMatrixField X(grid);
|
||||
Complex ci(0,1);
|
||||
|
||||
RealD t0 = usecond();
|
||||
Ident = ComplexD(1.0);
|
||||
for(int d=0;d<Nd;d++){
|
||||
Umu[d] = peekLorentz(U, d);
|
||||
}
|
||||
int mu= (smr/2) %Nd;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Mask the gauge field
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
auto mask=PeekIndex<LorentzIndex>(masks[smr],mu); // the cb mask
|
||||
|
||||
Umsk = U;
|
||||
ApplyMask(Umsk,smr);
|
||||
Utmp = peekLorentz(Umsk,mu);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Retrieve the eps/rho parameter(s) -- could allow all different but not so far
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
double rho=this->StoutSmearing->SmearRho[1];
|
||||
int idx=0;
|
||||
for(int mu=0;mu<4;mu++){
|
||||
for(int nu=0;nu<4;nu++){
|
||||
if ( mu!=nu) assert(this->StoutSmearing->SmearRho[idx]==rho);
|
||||
else assert(this->StoutSmearing->SmearRho[idx]==0.0);
|
||||
idx++;
|
||||
}}
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Assemble the N matrix
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Computes ALL the staples -- could compute one only and do it here
|
||||
RealD time;
|
||||
time=-usecond();
|
||||
this->StoutSmearing->BaseSmear(C, U);
|
||||
Cmu = peekLorentz(C, mu);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Assemble Luscher exp diff map J matrix
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Ta so Z lives in Lie algabra
|
||||
Zx = Ta(Cmu * adj(Umu[mu]));
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "Z took "<<time<< " us"<<std::endl;
|
||||
|
||||
time=-usecond();
|
||||
// Move Z to the Adjoint Rep == make_adjoint_representation
|
||||
ZxAd = Zero();
|
||||
for(int b=0;b<8;b++) {
|
||||
// Adj group sets traceless antihermitian T's -- Guido, really????
|
||||
SU3::generator(b, tb); // Fund group sets traceless hermitian T's
|
||||
SU3Adjoint::generator(b,TRb);
|
||||
TRb=-TRb;
|
||||
cplx = 2.0*trace(ci*tb*Zx); // my convention 1/2 delta ba
|
||||
ZxAd = ZxAd + cplx * TRb; // is this right? YES - Guido used Anti herm Ta's and with bloody wrong sign.
|
||||
}
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "ZxAd took "<<time<< " us"<<std::endl;
|
||||
|
||||
//////////////////////////////////////
|
||||
// J(x) = 1 + Sum_k=1..N (-Zac)^k/(k+1)!
|
||||
//////////////////////////////////////
|
||||
time=-usecond();
|
||||
X=1.0;
|
||||
JxAd = X;
|
||||
mZxAd = (-1.0)*ZxAd;
|
||||
RealD kpfac = 1;
|
||||
for(int k=1;k<12;k++){
|
||||
X=X*mZxAd;
|
||||
kpfac = kpfac /(k+1);
|
||||
JxAd = JxAd + X * kpfac;
|
||||
}
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "Jx took "<<time<< " us"<<std::endl;
|
||||
|
||||
//////////////////////////////////////
|
||||
// dJ(x)/dxe
|
||||
//////////////////////////////////////
|
||||
time=-usecond();
|
||||
std::vector<AdjMatrixField> dJdX; dJdX.resize(8,grid);
|
||||
AdjMatrixField tbXn(grid);
|
||||
AdjMatrixField sumXtbX(grid);
|
||||
AdjMatrixField t2(grid);
|
||||
AdjMatrixField dt2(grid);
|
||||
AdjMatrixField t3(grid);
|
||||
AdjMatrixField dt3(grid);
|
||||
AdjMatrixField aunit(grid);
|
||||
for(int b=0;b<8;b++){
|
||||
aunit = ComplexD(1.0);
|
||||
SU3Adjoint::generator(b, TRb); //dt2
|
||||
|
||||
X = (-1.0)*ZxAd;
|
||||
t2 = X;
|
||||
dt2 = TRb;
|
||||
for (int j = 20; j > 1; --j) {
|
||||
t3 = t2*(1.0 / (j + 1)) + aunit;
|
||||
dt3 = dt2*(1.0 / (j + 1));
|
||||
t2 = X * t3;
|
||||
dt2 = TRb * t3 + X * dt3;
|
||||
}
|
||||
dJdX[b] = -dt2;
|
||||
}
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "dJx took "<<time<< " us"<<std::endl;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Mask Umu for this link
|
||||
/////////////////////////////////////////////////////////////////
|
||||
time=-usecond();
|
||||
PlaqL = Ident;
|
||||
PlaqR = Utmp*adj(Cmu);
|
||||
ComputeNxy(PlaqL,PlaqR,NxxAd);
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "ComputeNxy took "<<time<< " us"<<std::endl;
|
||||
|
||||
////////////////////////////
|
||||
// Mab
|
||||
////////////////////////////
|
||||
MpAd = Complex(1.0,0.0);
|
||||
MpAd = MpAd - JxAd * NxxAd;
|
||||
|
||||
/////////////////////////
|
||||
// invert the 8x8
|
||||
/////////////////////////
|
||||
time=-usecond();
|
||||
MpAdInv = Inverse(MpAd);
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "MpAdInv took "<<time<< " us"<<std::endl;
|
||||
|
||||
RealD t3a = usecond();
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Nxx Mp^-1
|
||||
/////////////////////////////////////////////////////////////////
|
||||
AdjVectorField FdetV(grid);
|
||||
AdjVectorField Fdet1_nu(grid);
|
||||
AdjVectorField Fdet2_nu(grid);
|
||||
AdjVectorField Fdet2_mu(grid);
|
||||
AdjVectorField Fdet1_mu(grid);
|
||||
|
||||
AdjMatrixField nMpInv(grid);
|
||||
nMpInv= NxxAd *MpAdInv;
|
||||
|
||||
AdjMatrixField MpInvJx(grid);
|
||||
AdjMatrixField MpInvJx_nu(grid);
|
||||
MpInvJx = (-1.0)*MpAdInv * JxAd;// rho is on the plaq factor
|
||||
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx,FdetV);
|
||||
Fdet2_mu=FdetV;
|
||||
Fdet1_mu=Zero();
|
||||
|
||||
for(int e =0 ; e<8 ; e++){
|
||||
LatticeComplexD tr(grid);
|
||||
ColourMatrix te;
|
||||
SU3::generator(e, te);
|
||||
tr = trace(dJdX[e] * nMpInv);
|
||||
pokeColour(dJdXe_nMpInv,tr,e);
|
||||
}
|
||||
///////////////////////////////
|
||||
// Mask it off
|
||||
///////////////////////////////
|
||||
auto tmp=PeekIndex<LorentzIndex>(masks[smr],mu);
|
||||
dJdXe_nMpInv = dJdXe_nMpInv*tmp;
|
||||
|
||||
// dJdXe_nMpInv needs to multiply:
|
||||
// Nxx_mu (site local) (1)
|
||||
// Nxy_mu one site forward in each nu direction (3)
|
||||
// Nxy_mu one site backward in each nu direction (3)
|
||||
// Nxy_nu 0,0 ; +mu,0; 0,-nu; +mu-nu [ 3x4 = 12]
|
||||
// 19 terms.
|
||||
AdjMatrixField Nxy(grid);
|
||||
|
||||
GaugeField Fdet1(grid);
|
||||
GaugeField Fdet2(grid);
|
||||
GaugeLinkField Fdet_pol(grid); // one polarisation
|
||||
|
||||
RealD t4 = usecond();
|
||||
for(int nu=0;nu<Nd;nu++){
|
||||
|
||||
if (nu!=mu) {
|
||||
///////////////// +ve nu /////////////////
|
||||
// __
|
||||
// | |
|
||||
// x== // nu polarisation -- clockwise
|
||||
|
||||
time=-usecond();
|
||||
PlaqL=Ident;
|
||||
|
||||
PlaqR=(-rho)*Gimpl::CovShiftForward(Umu[nu], nu,
|
||||
Gimpl::CovShiftForward(Umu[mu], mu,
|
||||
Gimpl::CovShiftBackward(Umu[nu], nu,
|
||||
Gimpl::CovShiftIdentityBackward(Utmp, mu))));
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "PlaqLR took "<<time<< " us"<<std::endl;
|
||||
|
||||
time=-usecond();
|
||||
dJdXe_nMpInv_y = dJdXe_nMpInv;
|
||||
ComputeNxy(PlaqL,PlaqR,Nxy);
|
||||
Fdet1_nu = transpose(Nxy)*dJdXe_nMpInv_y;
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "ComputeNxy (occurs 6x) took "<<time<< " us"<<std::endl;
|
||||
|
||||
time=-usecond();
|
||||
PlaqR=(-1.0)*PlaqR;
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx,FdetV);
|
||||
Fdet2_nu = FdetV;
|
||||
time+=usecond();
|
||||
std::cout << GridLogMessage << "Compute_MpInvJx_dNxxSy (occurs 6x) took "<<time<< " us"<<std::endl;
|
||||
|
||||
// x==
|
||||
// | |
|
||||
// .__| // nu polarisation -- anticlockwise
|
||||
|
||||
PlaqR=(rho)*Gimpl::CovShiftForward(Umu[nu], nu,
|
||||
Gimpl::CovShiftBackward(Umu[mu], mu,
|
||||
Gimpl::CovShiftIdentityBackward(Umu[nu], nu)));
|
||||
|
||||
PlaqL=Gimpl::CovShiftIdentityBackward(Utmp, mu);
|
||||
|
||||
dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,mu,-1);
|
||||
ComputeNxy(PlaqL, PlaqR,Nxy);
|
||||
Fdet1_nu = Fdet1_nu+transpose(Nxy)*dJdXe_nMpInv_y;
|
||||
|
||||
|
||||
MpInvJx_nu = Cshift(MpInvJx,mu,-1);
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV);
|
||||
Fdet2_nu = Fdet2_nu+FdetV;
|
||||
|
||||
///////////////// -ve nu /////////////////
|
||||
// __
|
||||
// | |
|
||||
// x== // nu polarisation -- clockwise
|
||||
|
||||
PlaqL=(rho)* Gimpl::CovShiftForward(Umu[mu], mu,
|
||||
Gimpl::CovShiftForward(Umu[nu], nu,
|
||||
Gimpl::CovShiftIdentityBackward(Utmp, mu)));
|
||||
|
||||
PlaqR = Gimpl::CovShiftIdentityForward(Umu[nu], nu);
|
||||
|
||||
dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,nu,1);
|
||||
ComputeNxy(PlaqL,PlaqR,Nxy);
|
||||
Fdet1_nu = Fdet1_nu + transpose(Nxy)*dJdXe_nMpInv_y;
|
||||
|
||||
MpInvJx_nu = Cshift(MpInvJx,nu,1);
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV);
|
||||
Fdet2_nu = Fdet2_nu+FdetV;
|
||||
|
||||
// x==
|
||||
// | |
|
||||
// |__| // nu polarisation
|
||||
|
||||
PlaqL=(-rho)*Gimpl::CovShiftForward(Umu[nu], nu,
|
||||
Gimpl::CovShiftIdentityBackward(Utmp, mu));
|
||||
|
||||
PlaqR=Gimpl::CovShiftBackward(Umu[mu], mu,
|
||||
Gimpl::CovShiftIdentityForward(Umu[nu], nu));
|
||||
|
||||
dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,mu,-1);
|
||||
dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv_y,nu,1);
|
||||
|
||||
ComputeNxy(PlaqL,PlaqR,Nxy);
|
||||
Fdet1_nu = Fdet1_nu + transpose(Nxy)*dJdXe_nMpInv_y;
|
||||
|
||||
MpInvJx_nu = Cshift(MpInvJx,mu,-1);
|
||||
MpInvJx_nu = Cshift(MpInvJx_nu,nu,1);
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV);
|
||||
Fdet2_nu = Fdet2_nu+FdetV;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Set up the determinant force contribution in 3x3 algebra basis
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
InsertForce(Fdet1,Fdet1_nu,nu);
|
||||
InsertForce(Fdet2,Fdet2_nu,nu);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Parallel direction terms
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
// __
|
||||
// | "
|
||||
// |__"x // mu polarisation
|
||||
PlaqL=(-rho)*Gimpl::CovShiftForward(Umu[mu], mu,
|
||||
Gimpl::CovShiftBackward(Umu[nu], nu,
|
||||
Gimpl::CovShiftIdentityBackward(Utmp, mu)));
|
||||
|
||||
PlaqR=Gimpl::CovShiftIdentityBackward(Umu[nu], nu);
|
||||
|
||||
dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,nu,-1);
|
||||
|
||||
ComputeNxy(PlaqL,PlaqR,Nxy);
|
||||
Fdet1_mu = Fdet1_mu + transpose(Nxy)*dJdXe_nMpInv_y;
|
||||
|
||||
MpInvJx_nu = Cshift(MpInvJx,nu,-1);
|
||||
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV);
|
||||
Fdet2_mu = Fdet2_mu+FdetV;
|
||||
|
||||
// __
|
||||
// " |
|
||||
// x__| // mu polarisation
|
||||
|
||||
PlaqL=(-rho)*Gimpl::CovShiftForward(Umu[mu], mu,
|
||||
Gimpl::CovShiftForward(Umu[nu], nu,
|
||||
Gimpl::CovShiftIdentityBackward(Utmp, mu)));
|
||||
|
||||
PlaqR=Gimpl::CovShiftIdentityForward(Umu[nu], nu);
|
||||
|
||||
dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,nu,1);
|
||||
|
||||
ComputeNxy(PlaqL,PlaqR,Nxy);
|
||||
Fdet1_mu = Fdet1_mu + transpose(Nxy)*dJdXe_nMpInv_y;
|
||||
|
||||
MpInvJx_nu = Cshift(MpInvJx,nu,1);
|
||||
|
||||
Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV);
|
||||
Fdet2_mu = Fdet2_mu+FdetV;
|
||||
|
||||
}
|
||||
}
|
||||
RealD t5 = usecond();
|
||||
|
||||
Fdet1_mu = Fdet1_mu + transpose(NxxAd)*dJdXe_nMpInv;
|
||||
|
||||
InsertForce(Fdet1,Fdet1_mu,mu);
|
||||
InsertForce(Fdet2,Fdet2_mu,mu);
|
||||
|
||||
force= (-0.5)*( Fdet1 + Fdet2);
|
||||
RealD t1 = usecond();
|
||||
std::cout << GridLogMessage << " logDetJacobianForce level took "<<t1-t0<<" us "<<std::endl;
|
||||
std::cout << GridLogMessage << " logDetJacobianForce t3-t0 "<<t3a-t0<<" us "<<std::endl;
|
||||
std::cout << GridLogMessage << " logDetJacobianForce t4-t3 dJdXe_nMpInv "<<t4-t3a<<" us "<<std::endl;
|
||||
std::cout << GridLogMessage << " logDetJacobianForce t5-t4 mu nu loop "<<t5-t4<<" us "<<std::endl;
|
||||
std::cout << GridLogMessage << " logDetJacobianForce t1-t5 "<<t1-t5<<" us "<<std::endl;
|
||||
std::cout << GridLogMessage << " logDetJacobianForce level took "<<t1-t0<<" us "<<std::endl;
|
||||
}
|
||||
RealD logDetJacobianLevel(const GaugeField &U,int smr)
|
||||
{
|
||||
GridBase* grid = U.Grid();
|
||||
GaugeField C(grid);
|
||||
GaugeLinkField Nb(grid);
|
||||
GaugeLinkField Z(grid);
|
||||
GaugeLinkField Umu(grid), Cmu(grid);
|
||||
ColourMatrix Tb;
|
||||
ColourMatrix Tc;
|
||||
typedef typename SU3Adjoint::AMatrix AdjMatrix;
|
||||
typedef typename SU3Adjoint::LatticeAdjMatrix AdjMatrixField;
|
||||
typedef typename SU3Adjoint::LatticeAdjVector AdjVectorField;
|
||||
const int Ngen = SU3Adjoint::Dimension;
|
||||
AdjMatrix TRb;
|
||||
LatticeComplex cplx(grid);
|
||||
AdjVectorField AlgV(grid);
|
||||
AdjMatrixField Mab(grid);
|
||||
AdjMatrixField Ncb(grid);
|
||||
AdjMatrixField Jac(grid);
|
||||
AdjMatrixField Zac(grid);
|
||||
AdjMatrixField mZac(grid);
|
||||
AdjMatrixField X(grid);
|
||||
|
||||
int mu= (smr/2) %Nd;
|
||||
|
||||
auto mask=PeekIndex<LorentzIndex>(masks[smr],mu); // the cb mask
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Assemble the N matrix
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Computes ALL the staples -- could compute one only here
|
||||
this->StoutSmearing->BaseSmear(C, U);
|
||||
Cmu = peekLorentz(C, mu);
|
||||
Umu = peekLorentz(U, mu);
|
||||
Complex ci(0,1);
|
||||
for(int b=0;b<Ngen;b++) {
|
||||
SU3::generator(b, Tb);
|
||||
// Qlat Tb = 2i Tb^Grid
|
||||
Nb = (2.0)*Ta( ci*Tb * Umu * adj(Cmu));
|
||||
for(int c=0;c<Ngen;c++) {
|
||||
SU3::generator(c, Tc);
|
||||
auto tmp = -trace(ci*Tc*Nb); // Luchang's norm: (2Tc) (2Td) N^db = -2 delta cd N^db // - was important
|
||||
PokeIndex<ColourIndex>(Ncb,tmp,c,b);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Assemble Luscher exp diff map J matrix
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Ta so Z lives in Lie algabra
|
||||
Z = Ta(Cmu * adj(Umu));
|
||||
|
||||
// Move Z to the Adjoint Rep == make_adjoint_representation
|
||||
Zac = Zero();
|
||||
for(int b=0;b<8;b++) {
|
||||
// Adj group sets traceless antihermitian T's -- Guido, really????
|
||||
// Is the mapping of these the same? Same structure constants
|
||||
// Might never have been checked.
|
||||
SU3::generator(b, Tb); // Fund group sets traceless hermitian T's
|
||||
SU3Adjoint::generator(b,TRb);
|
||||
TRb=-TRb;
|
||||
cplx = 2.0*trace(ci*Tb*Z); // my convention 1/2 delta ba
|
||||
Zac = Zac + cplx * TRb; // is this right? YES - Guido used Anti herm Ta's and with bloody wrong sign.
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// J(x) = 1 + Sum_k=1..N (-Zac)^k/(k+1)!
|
||||
//////////////////////////////////////
|
||||
X=1.0;
|
||||
Jac = X;
|
||||
mZac = (-1.0)*Zac;
|
||||
RealD kpfac = 1;
|
||||
for(int k=1;k<12;k++){
|
||||
X=X*mZac;
|
||||
kpfac = kpfac /(k+1);
|
||||
Jac = Jac + X * kpfac;
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// Mab
|
||||
////////////////////////////
|
||||
Mab = Complex(1.0,0.0);
|
||||
Mab = Mab - Jac * Ncb;
|
||||
|
||||
////////////////////////////
|
||||
// det
|
||||
////////////////////////////
|
||||
LatticeComplex det(grid);
|
||||
det = Determinant(Mab);
|
||||
|
||||
////////////////////////////
|
||||
// ln det
|
||||
////////////////////////////
|
||||
LatticeComplex ln_det(grid);
|
||||
ln_det = log(det);
|
||||
|
||||
////////////////////////////
|
||||
// Masked sum
|
||||
////////////////////////////
|
||||
ln_det = ln_det * mask;
|
||||
Complex result = sum(ln_det);
|
||||
return result.real();
|
||||
}
|
||||
public:
|
||||
RealD logDetJacobian(void)
|
||||
{
|
||||
RealD ln_det = 0;
|
||||
if (this->smearingLevels > 0)
|
||||
{
|
||||
double start = usecond();
|
||||
for (int ismr = this->smearingLevels - 1; ismr > 0; --ismr) {
|
||||
ln_det+= logDetJacobianLevel(this->get_smeared_conf(ismr-1),ismr);
|
||||
}
|
||||
ln_det +=logDetJacobianLevel(*(this->ThinLinks),0);
|
||||
|
||||
double end = usecond();
|
||||
double time = (end - start)/ 1e3;
|
||||
std::cout << GridLogMessage << "GaugeConfigurationMasked: logDetJacobian took " << time << " ms" << std::endl;
|
||||
}
|
||||
return ln_det;
|
||||
}
|
||||
void logDetJacobianForce(GaugeField &force)
|
||||
{
|
||||
force =Zero();
|
||||
GaugeField force_det(force.Grid());
|
||||
|
||||
if (this->smearingLevels > 0)
|
||||
{
|
||||
double start = usecond();
|
||||
|
||||
GaugeLinkField tmp_mu(force.Grid());
|
||||
|
||||
for (int ismr = this->smearingLevels - 1; ismr > 0; --ismr) {
|
||||
|
||||
// remove U in UdSdU...
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
tmp_mu = adj(peekLorentz(this->get_smeared_conf(ismr), mu)) * peekLorentz(force, mu);
|
||||
pokeLorentz(force, tmp_mu, mu);
|
||||
}
|
||||
|
||||
// Propagate existing force
|
||||
force = this->AnalyticSmearedForce(force, this->get_smeared_conf(ismr - 1), ismr);
|
||||
|
||||
// Add back U in UdSdU...
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
tmp_mu = peekLorentz(this->get_smeared_conf(ismr - 1), mu) * peekLorentz(force, mu);
|
||||
pokeLorentz(force, tmp_mu, mu);
|
||||
}
|
||||
|
||||
// Get this levels determinant force
|
||||
force_det = Zero();
|
||||
logDetJacobianForceLevel(this->get_smeared_conf(ismr-1),force_det,ismr);
|
||||
|
||||
// Sum the contributions
|
||||
force = force + force_det;
|
||||
}
|
||||
|
||||
// remove U in UdSdU...
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
tmp_mu = adj(peekLorentz(this->get_smeared_conf(0), mu)) * peekLorentz(force, mu);
|
||||
pokeLorentz(force, tmp_mu, mu);
|
||||
}
|
||||
|
||||
force = this->AnalyticSmearedForce(force, *this->ThinLinks,0);
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
tmp_mu = peekLorentz(*this->ThinLinks, mu) * peekLorentz(force, mu);
|
||||
pokeLorentz(force, tmp_mu, mu);
|
||||
}
|
||||
|
||||
force_det = Zero();
|
||||
|
||||
logDetJacobianForceLevel(*this->ThinLinks,force_det,0);
|
||||
|
||||
force = force + force_det;
|
||||
|
||||
force=Ta(force); // Ta
|
||||
|
||||
double end = usecond();
|
||||
double time = (end - start)/ 1e3;
|
||||
std::cout << GridLogMessage << "GaugeConfigurationMasked: lnDetJacobianForce took " << time << " ms" << std::endl;
|
||||
} // if smearingLevels = 0 do nothing
|
||||
}
|
||||
|
||||
private:
|
||||
//====================================================================
|
||||
// Override base clas here to mask it
|
||||
virtual void fill_smearedSet(GaugeField &U)
|
||||
{
|
||||
this->ThinLinks = &U; // attach the smearing routine to the field U
|
||||
|
||||
// check the pointer is not null
|
||||
if (this->ThinLinks == NULL)
|
||||
std::cout << GridLogError << "[SmearedConfigurationMasked] Error in ThinLinks pointer\n";
|
||||
|
||||
if (this->smearingLevels > 0)
|
||||
{
|
||||
std::cout << GridLogMessage << "[SmearedConfigurationMasked] Filling SmearedSet\n";
|
||||
GaugeField previous_u(this->ThinLinks->Grid());
|
||||
|
||||
GaugeField smeared_A(this->ThinLinks->Grid());
|
||||
GaugeField smeared_B(this->ThinLinks->Grid());
|
||||
|
||||
previous_u = *this->ThinLinks;
|
||||
double start = usecond();
|
||||
for (int smearLvl = 0; smearLvl < this->smearingLevels; ++smearLvl)
|
||||
{
|
||||
this->StoutSmearing->smear(smeared_A, previous_u);
|
||||
ApplyMask(smeared_A,smearLvl);
|
||||
smeared_B = previous_u;
|
||||
ApplyMask(smeared_B,smearLvl);
|
||||
// Replace only the masked portion
|
||||
this->SmearedSet[smearLvl] = previous_u-smeared_B + smeared_A;
|
||||
previous_u = this->SmearedSet[smearLvl];
|
||||
|
||||
// For debug purposes
|
||||
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(previous_u);
|
||||
std::cout << GridLogMessage << "[SmearedConfigurationMasked] smeared Plaq: " << impl_plaq << std::endl;
|
||||
}
|
||||
double end = usecond();
|
||||
double time = (end - start)/ 1e3;
|
||||
std::cout << GridLogMessage << "GaugeConfigurationMasked: Link smearing took " << time << " ms" << std::endl;
|
||||
}
|
||||
}
|
||||
//====================================================================
|
||||
// Override base to add masking
|
||||
virtual GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime,
|
||||
const GaugeField& GaugeK,int level)
|
||||
{
|
||||
GridBase* grid = GaugeK.Grid();
|
||||
GaugeField C(grid), SigmaK(grid), iLambda(grid);
|
||||
GaugeField SigmaKPrimeA(grid);
|
||||
GaugeField SigmaKPrimeB(grid);
|
||||
GaugeLinkField iLambda_mu(grid);
|
||||
GaugeLinkField iQ(grid), e_iQ(grid);
|
||||
GaugeLinkField SigmaKPrime_mu(grid);
|
||||
GaugeLinkField GaugeKmu(grid), Cmu(grid);
|
||||
|
||||
this->StoutSmearing->BaseSmear(C, GaugeK);
|
||||
SigmaK = Zero();
|
||||
iLambda = Zero();
|
||||
|
||||
SigmaKPrimeA = SigmaKPrime;
|
||||
ApplyMask(SigmaKPrimeA,level);
|
||||
SigmaKPrimeB = SigmaKPrime - SigmaKPrimeA;
|
||||
|
||||
// Could get away with computing only one polarisation here
|
||||
// int mu= (smr/2) %Nd;
|
||||
// SigmaKprime_A has only one component
|
||||
for (int mu = 0; mu < Nd; mu++)
|
||||
{
|
||||
Cmu = peekLorentz(C, mu);
|
||||
GaugeKmu = peekLorentz(GaugeK, mu);
|
||||
SigmaKPrime_mu = peekLorentz(SigmaKPrimeA, mu);
|
||||
iQ = Ta(Cmu * adj(GaugeKmu));
|
||||
this->set_iLambda(iLambda_mu, e_iQ, iQ, SigmaKPrime_mu, GaugeKmu);
|
||||
pokeLorentz(SigmaK, SigmaKPrime_mu * e_iQ + adj(Cmu) * iLambda_mu, mu);
|
||||
pokeLorentz(iLambda, iLambda_mu, mu);
|
||||
}
|
||||
this->StoutSmearing->derivative(SigmaK, iLambda,GaugeK); // derivative of SmearBase
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// propagate the rest of the force as identity map, just add back
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
SigmaK = SigmaK+SigmaKPrimeB;
|
||||
|
||||
return SigmaK;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/* Standard constructor */
|
||||
SmearedConfigurationMasked(GridCartesian* _UGrid, unsigned int Nsmear, Smear_Stout<Gimpl>& Stout)
|
||||
: SmearedConfiguration<Gimpl>(_UGrid, Nsmear,Stout)
|
||||
{
|
||||
assert(Nsmear%(2*Nd)==0); // Or multiply by 8??
|
||||
|
||||
// was resized in base class
|
||||
assert(this->SmearedSet.size()==Nsmear);
|
||||
|
||||
GridRedBlackCartesian * UrbGrid;
|
||||
UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(_UGrid);
|
||||
LatticeComplex one(_UGrid); one = ComplexD(1.0,0.0);
|
||||
LatticeComplex tmp(_UGrid);
|
||||
|
||||
for (unsigned int i = 0; i < this->smearingLevels; ++i) {
|
||||
|
||||
masks.push_back(*(new LatticeLorentzComplex(_UGrid)));
|
||||
|
||||
int mu= (i/2) %Nd;
|
||||
int cb= (i%2);
|
||||
LatticeComplex tmpcb(UrbGrid);
|
||||
|
||||
masks[i]=Zero();
|
||||
////////////////////
|
||||
// Setup the mask
|
||||
////////////////////
|
||||
tmp = Zero();
|
||||
pickCheckerboard(cb,tmpcb,one);
|
||||
setCheckerboard(tmp,tmpcb);
|
||||
PokeIndex<LorentzIndex>(masks[i],tmp, mu);
|
||||
|
||||
}
|
||||
delete UrbGrid;
|
||||
}
|
||||
|
||||
virtual void smeared_force(GaugeField &SigmaTilde)
|
||||
{
|
||||
if (this->smearingLevels > 0)
|
||||
{
|
||||
double start = usecond();
|
||||
GaugeField force = SigmaTilde; // actually = U*SigmaTilde
|
||||
GaugeLinkField tmp_mu(SigmaTilde.Grid());
|
||||
|
||||
// Remove U from UdSdU
|
||||
for (int mu = 0; mu < Nd; mu++)
|
||||
{
|
||||
// to get just SigmaTilde
|
||||
tmp_mu = adj(peekLorentz(this->SmearedSet[this->smearingLevels - 1], mu)) * peekLorentz(force, mu);
|
||||
pokeLorentz(force, tmp_mu, mu);
|
||||
}
|
||||
|
||||
for (int ismr = this->smearingLevels - 1; ismr > 0; --ismr) {
|
||||
force = this->AnalyticSmearedForce(force, this->get_smeared_conf(ismr - 1),ismr);
|
||||
}
|
||||
|
||||
force = this->AnalyticSmearedForce(force, *this->ThinLinks,0);
|
||||
|
||||
// Add U to UdSdU
|
||||
for (int mu = 0; mu < Nd; mu++)
|
||||
{
|
||||
tmp_mu = peekLorentz(*this->ThinLinks, mu) * peekLorentz(force, mu);
|
||||
pokeLorentz(SigmaTilde, tmp_mu, mu);
|
||||
}
|
||||
|
||||
|
||||
double end = usecond();
|
||||
double time = (end - start)/ 1e3;
|
||||
std::cout << GridLogMessage << " GaugeConfigurationMasked: Smeared Force chain rule took " << time << " ms" << std::endl;
|
||||
|
||||
} // if smearingLevels = 0 do nothing
|
||||
SigmaTilde=Gimpl::projectForce(SigmaTilde); // Ta
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
87
Grid/qcd/smearing/JacobianAction.h
Normal file
87
Grid/qcd/smearing/JacobianAction.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/action/gauge/JacobianAction.h
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
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
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#pragma once
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Jacobian Action ..
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
template <class Gimpl>
|
||||
class JacobianAction : public Action<typename Gimpl::GaugeField> {
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl);
|
||||
|
||||
SmearedConfigurationMasked<Gimpl> * smearer;
|
||||
/////////////////////////// constructors
|
||||
explicit JacobianAction(SmearedConfigurationMasked<Gimpl> * _smearer ) { smearer=_smearer;};
|
||||
|
||||
virtual std::string action_name() {return "JacobianAction";}
|
||||
|
||||
virtual std::string LogParameters(){
|
||||
std::stringstream sstream;
|
||||
sstream << GridLogMessage << "[JacobianAction] " << std::endl;
|
||||
return sstream.str();
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// Usual cases are not used
|
||||
//////////////////////////////////
|
||||
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG){ assert(0);};
|
||||
virtual RealD S(const GaugeField &U) { assert(0); }
|
||||
virtual void deriv(const GaugeField &U, GaugeField &dSdU) { assert(0); }
|
||||
|
||||
//////////////////////////////////
|
||||
// Functions of smart configs only
|
||||
//////////////////////////////////
|
||||
virtual void refresh(ConfigurationBase<GaugeField> & U, GridSerialRNG &sRNG, GridParallelRNG& pRNG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
virtual RealD S(ConfigurationBase<GaugeField>& U)
|
||||
{
|
||||
// det M = e^{ - ( - logDetM) }
|
||||
assert( &U == smearer );
|
||||
return -smearer->logDetJacobian();
|
||||
}
|
||||
virtual RealD Sinitial(ConfigurationBase<GaugeField>& U)
|
||||
{
|
||||
return S(U);
|
||||
}
|
||||
virtual void deriv(ConfigurationBase<GaugeField>& U, GaugeField& dSdU)
|
||||
{
|
||||
assert( &U == smearer );
|
||||
smearer->logDetJacobianForce(dSdU);
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
@ -40,7 +40,9 @@ template <class Gimpl>
|
||||
class Smear_Stout : public Smear<Gimpl> {
|
||||
private:
|
||||
int OrthogDim = -1;
|
||||
public:
|
||||
const std::vector<double> SmearRho;
|
||||
private:
|
||||
// Smear<Gimpl>* ownership semantics:
|
||||
// Smear<Gimpl>* passed in to constructor are owned by caller, so we don't delete them here
|
||||
// Smear<Gimpl>* created within constructor need to be deleted as part of the destructor
|
||||
|
@ -37,13 +37,14 @@ NAMESPACE_BEGIN(Grid);
|
||||
// Make these members of an Impl class for BC's.
|
||||
|
||||
namespace PeriodicBC {
|
||||
|
||||
//Out(x) = Link(x)*field(x+mu)
|
||||
template<class covariant,class gauge> Lattice<covariant> CovShiftForward(const Lattice<gauge> &Link,
|
||||
int mu,
|
||||
const Lattice<covariant> &field)
|
||||
{
|
||||
return Link*Cshift(field,mu,1);// moves towards negative mu
|
||||
}
|
||||
//Out(x) = Link^dag(x-mu)*field(x-mu)
|
||||
template<class covariant,class gauge> Lattice<covariant> CovShiftBackward(const Lattice<gauge> &Link,
|
||||
int mu,
|
||||
const Lattice<covariant> &field)
|
||||
@ -52,19 +53,19 @@ namespace PeriodicBC {
|
||||
tmp = adj(Link)*field;
|
||||
return Cshift(tmp,mu,-1);// moves towards positive mu
|
||||
}
|
||||
|
||||
//Out(x) = Link^dag(x-mu)
|
||||
template<class gauge> Lattice<gauge>
|
||||
CovShiftIdentityBackward(const Lattice<gauge> &Link, int mu)
|
||||
{
|
||||
return Cshift(adj(Link), mu, -1);
|
||||
}
|
||||
|
||||
//Out(x) = Link(x)
|
||||
template<class gauge> Lattice<gauge>
|
||||
CovShiftIdentityForward(const Lattice<gauge> &Link, int mu)
|
||||
{
|
||||
return Link;
|
||||
}
|
||||
|
||||
//Link(x) = Link(x+mu)
|
||||
template<class gauge> Lattice<gauge>
|
||||
ShiftStaple(const Lattice<gauge> &Link, int mu)
|
||||
{
|
||||
|
@ -54,7 +54,361 @@ struct LaplacianParams : Serializable {
|
||||
precision(precision){};
|
||||
};
|
||||
|
||||
#define LEG_LOAD(Dir) \
|
||||
SE = st.GetEntry(ptype, Dir, ss); \
|
||||
if (SE->_is_local ) { \
|
||||
int perm= SE->_permute; \
|
||||
chi = coalescedReadPermute(in[SE->_offset],ptype,perm,lane); \
|
||||
} else { \
|
||||
chi = coalescedRead(buf[SE->_offset],lane); \
|
||||
} \
|
||||
acceleratorSynchronise();
|
||||
|
||||
const std::vector<int> directions4D ({Xdir,Ydir,Zdir,Tdir,Xdir,Ydir,Zdir,Tdir});
|
||||
const std::vector<int> displacements4D({1,1,1,1,-1,-1,-1,-1});
|
||||
|
||||
template<class Gimpl,class Field> class CovariantAdjointLaplacianStencil : public SparseMatrixBase<Field>
|
||||
{
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl);
|
||||
// RealD kappa;
|
||||
|
||||
typedef typename Field::vector_object siteObject;
|
||||
|
||||
template <typename vtype> using iImplDoubledGaugeField = iVector<iScalar<iMatrix<vtype, Nc> >, Nds>;
|
||||
typedef iImplDoubledGaugeField<Simd> SiteDoubledGaugeField;
|
||||
typedef Lattice<SiteDoubledGaugeField> DoubledGaugeField;
|
||||
typedef CartesianStencil<siteObject, siteObject, DefaultImplParams> StencilImpl;
|
||||
|
||||
GridBase *grid;
|
||||
StencilImpl Stencil;
|
||||
SimpleCompressor<siteObject> Compressor;
|
||||
DoubledGaugeField Uds;
|
||||
|
||||
CovariantAdjointLaplacianStencil( GridBase *_grid)
|
||||
: grid(_grid),
|
||||
Stencil (grid,8,Even,directions4D,displacements4D),
|
||||
Uds(grid){}
|
||||
|
||||
CovariantAdjointLaplacianStencil(GaugeField &Umu)
|
||||
:
|
||||
grid(Umu.Grid()),
|
||||
Stencil (grid,8,Even,directions4D,displacements4D),
|
||||
Uds(grid)
|
||||
{ GaugeImport(Umu); }
|
||||
|
||||
void GaugeImport (const GaugeField &Umu)
|
||||
{
|
||||
assert(grid == Umu.Grid());
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
auto U = PeekIndex<LorentzIndex>(Umu, mu);
|
||||
PokeIndex<LorentzIndex>(Uds, U, mu );
|
||||
U = adj(Cshift(U, mu, -1));
|
||||
PokeIndex<LorentzIndex>(Uds, U, mu + 4);
|
||||
}
|
||||
};
|
||||
|
||||
virtual GridBase *Grid(void) { return grid; };
|
||||
//broken
|
||||
#if 0
|
||||
virtual void MDeriv(const Field &_left, Field &_right,Field &_der, int mu)
|
||||
{
|
||||
///////////////////////////////////////////////
|
||||
// Halo exchange for this geometry of stencil
|
||||
///////////////////////////////////////////////
|
||||
Stencil.HaloExchange(_lef, Compressor);
|
||||
|
||||
///////////////////////////////////
|
||||
// Arithmetic expressions
|
||||
///////////////////////////////////
|
||||
autoView( st , Stencil , AcceleratorRead);
|
||||
auto buf = st.CommBuf();
|
||||
|
||||
autoView( in , _left , AcceleratorRead);
|
||||
autoView( right , _right , AcceleratorRead);
|
||||
autoView( der , _der , AcceleratorWrite);
|
||||
autoView( U , Uds , AcceleratorRead);
|
||||
|
||||
typedef typename Field::vector_object vobj;
|
||||
typedef decltype(coalescedRead(left[0])) calcObj;
|
||||
typedef decltype(coalescedRead(U[0](0))) calcLink;
|
||||
|
||||
const int Nsimd = vobj::Nsimd();
|
||||
const uint64_t NN = grid->oSites();
|
||||
|
||||
accelerator_for( ss, NN, Nsimd, {
|
||||
|
||||
StencilEntry *SE;
|
||||
|
||||
const int lane=acceleratorSIMTlane(Nsimd);
|
||||
|
||||
calcObj chi;
|
||||
calcObj phi;
|
||||
calcObj res;
|
||||
calcObj Uchi;
|
||||
calcObj Utmp;
|
||||
calcObj Utmp2;
|
||||
calcLink UU;
|
||||
calcLink Udag;
|
||||
int ptype;
|
||||
|
||||
res = coalescedRead(def[ss]);
|
||||
phi = coalescedRead(right[ss]);
|
||||
|
||||
#define LEG_LOAD_MULT_LINK(leg,polarisation) \
|
||||
UU = coalescedRead(U[ss](polarisation)); \
|
||||
Udag = adj(UU); \
|
||||
LEG_LOAD(leg); \
|
||||
mult(&Utmp(), &UU, &chi()); \
|
||||
Utmp2 = adj(Utmp); \
|
||||
mult(&Utmp(), &UU, &Utmp2()); \
|
||||
Utmp2 = adj(Utmp); \
|
||||
mult(&Uchi(), &phi(), &Utmp2()); \
|
||||
res = res + Uchi;
|
||||
|
||||
LEG_LOAD_MULT_LINK(0,Xp);
|
||||
LEG_LOAD_MULT_LINK(1,Yp);
|
||||
LEG_LOAD_MULT_LINK(2,Zp);
|
||||
LEG_LOAD_MULT_LINK(3,Tp);
|
||||
|
||||
coalescedWrite(der[ss], res,lane);
|
||||
});
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
virtual void Morig(const Field &_in, Field &_out)
|
||||
{
|
||||
///////////////////////////////////////////////
|
||||
// Halo exchange for this geometry of stencil
|
||||
///////////////////////////////////////////////
|
||||
Stencil.HaloExchange(_in, Compressor);
|
||||
|
||||
///////////////////////////////////
|
||||
// Arithmetic expressions
|
||||
///////////////////////////////////
|
||||
// auto st = Stencil.View(AcceleratorRead);
|
||||
autoView( st , Stencil , AcceleratorRead);
|
||||
auto buf = st.CommBuf();
|
||||
|
||||
autoView( in , _in , AcceleratorRead);
|
||||
autoView( out , _out , AcceleratorWrite);
|
||||
autoView( U , Uds , AcceleratorRead);
|
||||
|
||||
typedef typename Field::vector_object vobj;
|
||||
typedef decltype(coalescedRead(in[0])) calcObj;
|
||||
typedef decltype(coalescedRead(U[0](0))) calcLink;
|
||||
|
||||
const int Nsimd = vobj::Nsimd();
|
||||
const uint64_t NN = grid->oSites();
|
||||
|
||||
accelerator_for( ss, NN, Nsimd, {
|
||||
|
||||
StencilEntry *SE;
|
||||
|
||||
const int lane=acceleratorSIMTlane(Nsimd);
|
||||
|
||||
calcObj chi;
|
||||
calcObj res;
|
||||
calcObj Uchi;
|
||||
calcObj Utmp;
|
||||
calcObj Utmp2;
|
||||
calcLink UU;
|
||||
calcLink Udag;
|
||||
int ptype;
|
||||
|
||||
res = coalescedRead(in[ss])*(-8.0);
|
||||
|
||||
#define LEG_LOAD_MULT(leg,polarisation) \
|
||||
UU = coalescedRead(U[ss](polarisation)); \
|
||||
Udag = adj(UU); \
|
||||
LEG_LOAD(leg); \
|
||||
mult(&Utmp(), &UU, &chi()); \
|
||||
Utmp2 = adj(Utmp); \
|
||||
mult(&Utmp(), &UU, &Utmp2()); \
|
||||
Uchi = adj(Utmp); \
|
||||
res = res + Uchi;
|
||||
|
||||
LEG_LOAD_MULT(0,Xp);
|
||||
LEG_LOAD_MULT(1,Yp);
|
||||
LEG_LOAD_MULT(2,Zp);
|
||||
LEG_LOAD_MULT(3,Tp);
|
||||
LEG_LOAD_MULT(4,Xm);
|
||||
LEG_LOAD_MULT(5,Ym);
|
||||
LEG_LOAD_MULT(6,Zm);
|
||||
LEG_LOAD_MULT(7,Tm);
|
||||
|
||||
coalescedWrite(out[ss], res,lane);
|
||||
});
|
||||
|
||||
};
|
||||
virtual void Mnew (const Field &_in, Field &_out)
|
||||
{
|
||||
///////////////////////////////////////////////
|
||||
// Halo exchange for this geometry of stencil
|
||||
///////////////////////////////////////////////
|
||||
// Stencil.HaloExchange(_in, Compressor);
|
||||
std::vector<std::vector<CommsRequest_t> > requests;
|
||||
Stencil.Prepare();
|
||||
{
|
||||
GRID_TRACE("Laplace Gather");
|
||||
Stencil.HaloGather(_in,Compressor);
|
||||
}
|
||||
|
||||
tracePush("Laplace Communication");
|
||||
Stencil.CommunicateBegin(requests);
|
||||
{
|
||||
GRID_TRACE("MergeSHM");
|
||||
Stencil.CommsMergeSHM(Compressor);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// Arithmetic expressions
|
||||
///////////////////////////////////
|
||||
// auto st = Stencil.View(AcceleratorRead);
|
||||
autoView( st , Stencil , AcceleratorRead);
|
||||
auto buf = st.CommBuf();
|
||||
|
||||
autoView( in , _in , AcceleratorRead);
|
||||
autoView( out , _out , AcceleratorWrite);
|
||||
autoView( U , Uds , AcceleratorRead);
|
||||
|
||||
typedef typename Field::vector_object vobj;
|
||||
typedef decltype(coalescedRead(in[0])) calcObj;
|
||||
typedef decltype(coalescedRead(U[0](0))) calcLink;
|
||||
|
||||
const int Nsimd = vobj::Nsimd();
|
||||
const uint64_t NN = grid->oSites();
|
||||
|
||||
accelerator_for( ss, NN, Nsimd, {
|
||||
|
||||
StencilEntry *SE;
|
||||
|
||||
const int lane=acceleratorSIMTlane(Nsimd);
|
||||
|
||||
calcObj chi;
|
||||
calcObj res;
|
||||
calcObj Uchi;
|
||||
calcObj Utmp;
|
||||
calcObj Utmp2;
|
||||
calcLink UU;
|
||||
calcLink Udag;
|
||||
int ptype;
|
||||
|
||||
res = coalescedRead(in[ss])*(-8.0);
|
||||
|
||||
|
||||
SE = st.GetEntry(ptype, 0, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(0,Xp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 1, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(1,Yp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 2, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(2,Zp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 3, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(3,Tp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 4, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(4,Xm);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 5, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(5,Ym);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 6, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(6,Zm);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 7, ss);
|
||||
if (SE->_is_local ) {
|
||||
LEG_LOAD_MULT(7,Tm);
|
||||
}
|
||||
|
||||
coalescedWrite(out[ss], res,lane);
|
||||
});
|
||||
|
||||
Stencil.CommunicateComplete(requests);
|
||||
tracePop("Communication");
|
||||
|
||||
{
|
||||
GRID_TRACE("Merge");
|
||||
Stencil.CommsMerge(Compressor);
|
||||
}
|
||||
|
||||
|
||||
accelerator_for( ss, NN, Nsimd, {
|
||||
|
||||
StencilEntry *SE;
|
||||
|
||||
const int lane=acceleratorSIMTlane(Nsimd);
|
||||
|
||||
calcObj chi;
|
||||
calcObj res;
|
||||
calcObj Uchi;
|
||||
calcObj Utmp;
|
||||
calcObj Utmp2;
|
||||
calcLink UU;
|
||||
calcLink Udag;
|
||||
int ptype;
|
||||
|
||||
// res = coalescedRead(in[ss])*(-8.0);
|
||||
res = coalescedRead(out[ss]);
|
||||
|
||||
SE = st.GetEntry(ptype, 0, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(0,Xp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 1, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(1,Yp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 2, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(2,Zp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 3, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(3,Tp);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 4, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(4,Xm);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 5, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(5,Ym);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 6, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(6,Zm);
|
||||
}
|
||||
SE = st.GetEntry(ptype, 7, ss);
|
||||
if ((SE->_is_local )==0){
|
||||
LEG_LOAD_MULT(7,Tm);
|
||||
}
|
||||
|
||||
coalescedWrite(out[ss], res,lane);
|
||||
});
|
||||
};
|
||||
|
||||
virtual void M(const Field &in, Field &out) {Mnew(in,out);};
|
||||
virtual void Mdag (const Field &in, Field &out) { M(in,out);}; // Laplacian is hermitian
|
||||
virtual void Mdiag (const Field &in, Field &out) {assert(0);}; // Unimplemented need only for multigrid
|
||||
virtual void Mdir (const Field &in, Field &out,int dir, int disp){assert(0);}; // Unimplemented need only for multigrid
|
||||
virtual void MdirAll (const Field &in, std::vector<Field> &out) {assert(0);}; // Unimplemented need only for multigrid
|
||||
};
|
||||
|
||||
#undef LEG_LOAD_MULT
|
||||
#undef LEG_LOAD_MULT_LINK
|
||||
#undef LEG_LOAD
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Laplacian operator L on adjoint fields
|
||||
@ -76,29 +430,40 @@ class LaplacianAdjointField: public Metric<typename Impl::Field> {
|
||||
LaplacianParams param;
|
||||
MultiShiftFunction PowerHalf;
|
||||
MultiShiftFunction PowerInvHalf;
|
||||
//template<class Gimpl,class Field> class CovariantAdjointLaplacianStencil : public SparseMatrixBase<Field>
|
||||
CovariantAdjointLaplacianStencil<Impl,typename Impl::LinkField> LapStencil;
|
||||
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Impl);
|
||||
|
||||
LaplacianAdjointField(GridBase* grid, OperatorFunction<GaugeField>& S, LaplacianParams& p, const RealD k = 1.0)
|
||||
: U(Nd, grid), Solver(S), param(p), kappa(k){
|
||||
LaplacianAdjointField(GridBase* grid, OperatorFunction<GaugeField>& S, LaplacianParams& p, const RealD k = 1.0, bool if_remez=true)
|
||||
: U(Nd, grid), Solver(S), param(p), kappa(k)
|
||||
,LapStencil(grid){
|
||||
AlgRemez remez(param.lo,param.hi,param.precision);
|
||||
std::cout<<GridLogMessage << "Generating degree "<<param.degree<<" for x^(1/2)"<<std::endl;
|
||||
if(if_remez){
|
||||
remez.generateApprox(param.degree,1,2);
|
||||
PowerHalf.Init(remez,param.tolerance,false);
|
||||
PowerInvHalf.Init(remez,param.tolerance,true);
|
||||
}
|
||||
this->triv=0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
LaplacianAdjointField(){this->triv=0; printf("triv=%d\n",this->Trivial());}
|
||||
void Mdir(const GaugeField&, GaugeField&, int, int){ assert(0);}
|
||||
void MdirAll(const GaugeField&, std::vector<GaugeField> &){ assert(0);}
|
||||
void Mdiag(const GaugeField&, GaugeField&){ assert(0);}
|
||||
|
||||
void ImportGauge(const GaugeField& _U) {
|
||||
RealD total=0.;
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
U[mu] = PeekIndex<LorentzIndex>(_U, mu);
|
||||
total += norm2(U[mu]);
|
||||
}
|
||||
LapStencil.GaugeImport (_U);
|
||||
|
||||
std::cout << GridLogDebug <<"ImportGauge:norm2(U _U) = "<<total<<std::endl;
|
||||
}
|
||||
|
||||
void M(const GaugeField& in, GaugeField& out) {
|
||||
@ -106,10 +471,12 @@ public:
|
||||
// test
|
||||
//GaugeField herm = in + adj(in);
|
||||
//std::cout << "AHermiticity: " << norm2(herm) << std::endl;
|
||||
// std::cout << GridLogDebug <<"M:Kappa = "<<kappa<<std::endl;
|
||||
|
||||
GaugeLinkField sum(in.Grid());
|
||||
#if 0
|
||||
GaugeLinkField tmp(in.Grid());
|
||||
GaugeLinkField tmp2(in.Grid());
|
||||
GaugeLinkField sum(in.Grid());
|
||||
|
||||
for (int nu = 0; nu < Nd; nu++) {
|
||||
sum = Zero();
|
||||
@ -123,10 +490,22 @@ public:
|
||||
out_nu = (1.0 - kappa) * in_nu - kappa / (double(4 * Nd)) * sum;
|
||||
PokeIndex<LorentzIndex>(out, out_nu, nu);
|
||||
}
|
||||
#else
|
||||
for (int nu = 0; nu < Nd; nu++) {
|
||||
GaugeLinkField in_nu = PeekIndex<LorentzIndex>(in, nu);
|
||||
GaugeLinkField out_nu(out.Grid());
|
||||
LapStencil.M(in_nu,sum);
|
||||
out_nu = (1.0 - kappa) * in_nu - kappa / (double(4 * Nd)) * sum;
|
||||
PokeIndex<LorentzIndex>(out, out_nu, nu);
|
||||
}
|
||||
#endif
|
||||
// std::cout << GridLogDebug <<"M:norm2(out) = "<<norm2(out)<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void MDeriv(const GaugeField& in, GaugeField& der) {
|
||||
// in is anti-hermitian
|
||||
// std::cout << GridLogDebug <<"MDeriv:Kappa = "<<kappa<<std::endl;
|
||||
RealD factor = -kappa / (double(4 * Nd));
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++){
|
||||
@ -140,6 +519,7 @@ public:
|
||||
// adjoint in the last multiplication
|
||||
PokeIndex<LorentzIndex>(der, -2.0 * factor * der_mu, mu);
|
||||
}
|
||||
std::cout << GridLogDebug <<"MDeriv: Kappa= "<< kappa << " norm2(der) = "<<norm2(der)<<std::endl;
|
||||
}
|
||||
|
||||
// separating this temporarily
|
||||
@ -159,11 +539,22 @@ public:
|
||||
}
|
||||
PokeIndex<LorentzIndex>(der, -factor * der_mu, mu);
|
||||
}
|
||||
std::cout << GridLogDebug <<"MDeriv: Kappa= "<< kappa << " norm2(der) = "<<norm2(der)<<std::endl;
|
||||
}
|
||||
|
||||
void Minv(const GaugeField& in, GaugeField& inverted){
|
||||
HermitianLinearOperator<LaplacianAdjointField<Impl>,GaugeField> HermOp(*this);
|
||||
Solver(HermOp, in, inverted);
|
||||
std::cout << GridLogDebug <<"Minv:norm2(inverted) = "<<norm2(inverted)<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void MinvDeriv(const GaugeField& in, GaugeField& der) {
|
||||
GaugeField X(in.Grid());
|
||||
Minv(in,X);
|
||||
MDeriv(X,der);
|
||||
der *=-1.0;
|
||||
std::cout << GridLogDebug <<"MinvDeriv:norm2(der) = "<<norm2(der)<<std::endl;
|
||||
}
|
||||
|
||||
void MSquareRoot(GaugeField& P){
|
||||
@ -172,6 +563,7 @@ public:
|
||||
ConjugateGradientMultiShift<GaugeField> msCG(param.MaxIter,PowerHalf);
|
||||
msCG(HermOp,P,Gp);
|
||||
P = Gp;
|
||||
std::cout << GridLogDebug <<"MSquareRoot:norm2(P) = "<<norm2(P)<<std::endl;
|
||||
}
|
||||
|
||||
void MInvSquareRoot(GaugeField& P){
|
||||
@ -180,6 +572,7 @@ public:
|
||||
ConjugateGradientMultiShift<GaugeField> msCG(param.MaxIter,PowerInvHalf);
|
||||
msCG(HermOp,P,Gp);
|
||||
P = Gp;
|
||||
std::cout << GridLogDebug <<"MInvSquareRoot:norm2(P) = "<<norm2(P)<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
403
Grid/qcd/utils/CovariantLaplacianRat.h
Normal file
403
Grid/qcd/utils/CovariantLaplacianRat.h
Normal file
@ -0,0 +1,403 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/action/scalar/CovariantLaplacianRat.h
|
||||
|
||||
Copyright (C) 2021
|
||||
|
||||
Author: Chulwoo Jung <chulwoo@bnl.gov>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
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
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#pragma once
|
||||
#define MIXED_CG
|
||||
//enable/disable push_back
|
||||
#undef USE_CHRONO
|
||||
|
||||
//#include <roctracer/roctx.h>
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
struct LaplacianRatParams {
|
||||
|
||||
RealD offset;
|
||||
int order;
|
||||
std::vector<RealD> a0;
|
||||
std::vector<RealD> a1;
|
||||
std::vector<RealD> b0;
|
||||
std::vector<RealD> b1;
|
||||
RealD b2; //for debugging
|
||||
int MaxIter;
|
||||
RealD tolerance;
|
||||
int precision;
|
||||
|
||||
// constructor
|
||||
LaplacianRatParams(int ord = 1,
|
||||
int maxit = 1000,
|
||||
RealD tol = 1.0e-8,
|
||||
int precision = 64)
|
||||
: offset(1.), order(ord),b2(1.),
|
||||
MaxIter(maxit),
|
||||
tolerance(tol),
|
||||
precision(precision){
|
||||
a0.resize(ord,0.);
|
||||
a1.resize(ord,0.);
|
||||
b0.resize(ord,0.);
|
||||
b1.resize(ord,0.);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Laplacian operator L on adjoint fields
|
||||
//
|
||||
// phi: adjoint field
|
||||
// L: D_mu^dag D_mu
|
||||
//
|
||||
// L phi(x) = Sum_mu [ U_mu(x)phi(x+mu)U_mu(x)^dag +
|
||||
// U_mu(x-mu)^dag phi(x-mu)U_mu(x-mu)
|
||||
// -2phi(x)]
|
||||
//
|
||||
// Operator designed to be encapsulated by
|
||||
// an HermitianLinearOperator<.. , ..>
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
template <class Impl, class ImplF>
|
||||
class LaplacianAdjointRat: public Metric<typename Impl::Field> {
|
||||
OperatorFunction<typename Impl::Field> &Solver;
|
||||
LaplacianRatParams Gparam;
|
||||
LaplacianRatParams Mparam;
|
||||
GridBase *grid;
|
||||
GridBase *grid_f;
|
||||
CovariantAdjointLaplacianStencil<Impl,typename Impl::LinkField> LapStencil;
|
||||
CovariantAdjointLaplacianStencil<ImplF,typename ImplF::LinkField> LapStencilF;
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Impl);
|
||||
// typedef typename GImpl::LinkField GaugeLinkField; \
|
||||
// typedef typename GImpl::Field GaugeField;
|
||||
typedef typename ImplF::Field GaugeFieldF;
|
||||
typedef typename ImplF::LinkField GaugeLinkFieldF; \
|
||||
GaugeField Usav;
|
||||
GaugeFieldF UsavF;
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solnsM;
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solnsMinv;
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solnsMDeriv;
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solnsMinvDeriv;
|
||||
|
||||
LaplacianAdjointRat(GridBase* _grid, GridBase* _grid_f, OperatorFunction<GaugeField>& S, LaplacianRatParams& gpar, LaplacianRatParams& mpar)
|
||||
: grid(_grid),grid_f(_grid_f), LapStencil(_grid), LapStencilF(_grid_f), U(Nd, _grid), Solver(S), Gparam(gpar), Mparam(mpar),Usav(_grid), UsavF(_grid_f),
|
||||
prev_solnsM(4),prev_solnsMinv(4),prev_solnsMDeriv(4),prev_solnsMinvDeriv(4) {
|
||||
// std::cout<<GridLogMessage << "Generating degree "<<param.degree<<" for x^(1/2)"<<std::endl;
|
||||
this->triv=0;
|
||||
|
||||
|
||||
};
|
||||
LaplacianAdjointRat(){this->triv=0; printf("triv=%d\n",this->Trivial());}
|
||||
void Mdir(const GaugeField&, GaugeField&, int, int){ assert(0);}
|
||||
void MdirAll(const GaugeField&, std::vector<GaugeField> &){ assert(0);}
|
||||
void Mdiag(const GaugeField&, GaugeField&){ assert(0);}
|
||||
|
||||
void ImportGauge(const GaugeField& _U) {
|
||||
RealD total=0.;
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
U[mu] = PeekIndex<LorentzIndex>(_U, mu);
|
||||
total += norm2(U[mu]);
|
||||
}
|
||||
Usav = _U;
|
||||
precisionChange(UsavF,Usav);
|
||||
std::cout <<GridLogDebug << "ImportGauge:norm2(_U) = "<<" "<<total<<std::endl;
|
||||
}
|
||||
|
||||
void MDerivLink(const GaugeLinkField& left, const GaugeLinkField& right,
|
||||
GaugeField& der) {
|
||||
std::cout<<GridLogMessage << "MDerivLink start "<< std::endl;
|
||||
RealD factor = -1. / (double(4 * Nd));
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
GaugeLinkField der_mu(der.Grid());
|
||||
der_mu = Zero();
|
||||
// for (int nu = 0; nu < Nd; nu++) {
|
||||
// GaugeLinkField left_nu = PeekIndex<LorentzIndex>(left, nu);
|
||||
// GaugeLinkField right_nu = PeekIndex<LorentzIndex>(right, nu);
|
||||
der_mu += U[mu] * Cshift(left, mu, 1) * adj(U[mu]) * right;
|
||||
der_mu += U[mu] * Cshift(right, mu, 1) * adj(U[mu]) * left;
|
||||
// }
|
||||
PokeIndex<LorentzIndex>(der, -factor * der_mu, mu);
|
||||
}
|
||||
// std::cout << GridLogDebug <<"MDerivLink: norm2(der) = "<<norm2(der)<<std::endl;
|
||||
std::cout<<GridLogMessage << "MDerivLink end "<< std::endl;
|
||||
}
|
||||
|
||||
void MDerivLink(const GaugeLinkField& left, const GaugeLinkField& right,
|
||||
std::vector<GaugeLinkField> & der) {
|
||||
// std::cout<<GridLogMessage << "MDerivLink "<< std::endl;
|
||||
RealD factor = -1. / (double(4 * Nd));
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
GaugeLinkField der_mu(left.Grid());
|
||||
der_mu = Zero();
|
||||
der_mu += U[mu] * Cshift(left, mu, 1) * adj(U[mu]) * right;
|
||||
der_mu += U[mu] * Cshift(right, mu, 1) * adj(U[mu]) * left;
|
||||
// PokeIndex<LorentzIndex>(der, -factor * der_mu, mu);
|
||||
der[mu] = -factor*der_mu;
|
||||
// std::cout << GridLogDebug <<"MDerivLink: norm2(der) = "<<norm2(der[mu])<<std::endl;
|
||||
|
||||
}
|
||||
// std::cout<<GridLogMessage << "MDerivLink end "<< std::endl;
|
||||
}
|
||||
|
||||
void MDerivInt(LaplacianRatParams &par, const GaugeField& left, const GaugeField& right,
|
||||
GaugeField& der , std::vector< std::vector<GaugeLinkField> >& prev_solns ) {
|
||||
|
||||
// get rid of this please
|
||||
std::cout<<GridLogMessage << "LaplaceStart " <<std::endl;
|
||||
RealD fac = - 1. / (double(4 * Nd)) ;
|
||||
RealD coef=0.5;
|
||||
LapStencil.GaugeImport(Usav);
|
||||
LapStencilF.GaugeImport(UsavF);
|
||||
|
||||
|
||||
for (int nu=0;nu<Nd;nu++){
|
||||
GaugeLinkField right_nu = PeekIndex<LorentzIndex>(right, nu);
|
||||
GaugeLinkField left_nu = PeekIndex<LorentzIndex>(left, nu);
|
||||
GaugeLinkField LMinvMom(left.Grid());
|
||||
|
||||
GaugeLinkField GMom(left.Grid());
|
||||
GaugeLinkField LMinvGMom(left.Grid());
|
||||
|
||||
GaugeLinkField AGMom(left.Grid());
|
||||
GaugeLinkField MinvAGMom(left.Grid());
|
||||
GaugeLinkField LMinvAGMom(left.Grid());
|
||||
|
||||
GaugeLinkField AMinvMom(left.Grid());
|
||||
GaugeLinkField LMinvAMom(left.Grid());
|
||||
GaugeLinkField temp(left.Grid());
|
||||
GaugeLinkField temp2(left.Grid());
|
||||
|
||||
std::vector<GaugeLinkField> MinvMom(par.order,left.Grid());
|
||||
|
||||
GaugeLinkField MinvGMom(left.Grid());
|
||||
GaugeLinkField Gtemp(left.Grid());
|
||||
GaugeLinkField Gtemp2(left.Grid());
|
||||
|
||||
|
||||
ConjugateGradient<GaugeLinkField> CG(par.tolerance,10000,false);
|
||||
// ConjugateGradient<GaugeFieldF> CG_f(par.tolerance,10000,false);
|
||||
LaplacianParams LapPar(0.0001, 1.0, 10000, 1e-8, 12, 64);
|
||||
|
||||
ChronoForecast< QuadLinearOperator<CovariantAdjointLaplacianStencil<Impl,GaugeLinkField>,GaugeLinkField> , GaugeLinkField> Forecast;
|
||||
|
||||
GMom = par.offset * right_nu;
|
||||
|
||||
for(int i =0;i<par.order;i++){
|
||||
QuadLinearOperator<CovariantAdjointLaplacianStencil<Impl,typename Impl::LinkField>,GaugeLinkField> QuadOp(LapStencil,par.b0[i],fac*par.b1[i],fac*fac*par.b2);
|
||||
#if USE_CHRONO
|
||||
MinvMom[i] = Forecast(QuadOp, right_nu, prev_solns[nu]);
|
||||
#endif
|
||||
#ifndef MIXED_CG
|
||||
CG(QuadOp,right_nu,MinvMom[i]);
|
||||
#else
|
||||
QuadLinearOperator<CovariantAdjointLaplacianStencil<ImplF,typename ImplF::LinkField>,GaugeLinkFieldF> QuadOpF(LapStencilF,par.b0[i],fac*par.b1[i],fac*fac*par.b2);
|
||||
// QuadLinearOperator<LaplacianAdjointField<ImplF>,GaugeLinkFieldF> QuadOpF(LapStencilF,par.b0[i],par.b1[i],par.b2);
|
||||
MixedPrecisionConjugateGradient<GaugeLinkField,GaugeLinkFieldF> MixedCG(par.tolerance,10000,10000,grid_f,QuadOpF,QuadOp);
|
||||
MixedCG.InnerTolerance=par.tolerance;
|
||||
MixedCG(right_nu,MinvMom[i]);
|
||||
#endif
|
||||
#if USE_CHRONO
|
||||
prev_solns[nu].push_back(MinvMom[i]);
|
||||
#endif
|
||||
|
||||
GMom += par.a0[i]*MinvMom[i];
|
||||
LapStencil.M(MinvMom[i],Gtemp2);
|
||||
GMom += par.a1[i]*fac*Gtemp2;
|
||||
}
|
||||
for(int i =0;i<par.order;i++){
|
||||
QuadLinearOperator<CovariantAdjointLaplacianStencil<Impl,typename Impl::LinkField>,GaugeLinkField> QuadOp(LapStencil,par.b0[i],fac*par.b1[i],fac*fac*par.b2);
|
||||
|
||||
MinvGMom = Forecast(QuadOp, GMom, prev_solns[nu]);
|
||||
#ifndef MIXED_CG
|
||||
CG(QuadOp,GMom,MinvGMom);
|
||||
LapStencil.M(MinvGMom, Gtemp2); LMinvGMom=fac*Gtemp2;
|
||||
CG(QuadOp,right_nu,MinvMom[i]);
|
||||
#else
|
||||
QuadLinearOperator<CovariantAdjointLaplacianStencil<ImplF,typename ImplF::LinkField>,GaugeLinkFieldF> QuadOpF(LapStencilF,par.b0[i],fac*par.b1[i],fac*fac*par.b2);
|
||||
// QuadLinearOperator<LaplacianAdjointField<ImplF>,GaugeLinkFieldF> QuadOpF(LapStencilF,par.b0[i],par.b1[i],par.b2);
|
||||
MixedPrecisionConjugateGradient<GaugeLinkField,GaugeLinkFieldF> MixedCG(par.tolerance,10000,10000,grid_f,QuadOpF,QuadOp);
|
||||
MixedCG.InnerTolerance=par.tolerance;
|
||||
MixedCG(GMom,MinvGMom);
|
||||
LapStencil.M(MinvGMom, Gtemp2); LMinvGMom=fac*Gtemp2;
|
||||
// Laplacian.M(MinvGMom, LMinvGMom);
|
||||
MixedCG(right_nu,MinvMom[i]);
|
||||
#endif
|
||||
#if USE_CHRONO
|
||||
prev_solns[nu].push_back(MinvGMom);
|
||||
#endif
|
||||
|
||||
LapStencil.M(MinvMom[i], Gtemp2); LMinvMom=fac*Gtemp2;
|
||||
AMinvMom = par.a1[i]*LMinvMom;
|
||||
AMinvMom += par.a0[i]*MinvMom[i];
|
||||
|
||||
LapStencil.M(AMinvMom, Gtemp2); LMinvAMom=fac*Gtemp2;
|
||||
LapStencil.M(MinvGMom, Gtemp2); temp=fac*Gtemp2;
|
||||
MinvAGMom = par.a1[i]*temp;
|
||||
MinvAGMom += par.a0[i]*MinvGMom;
|
||||
LapStencil.M(MinvAGMom, Gtemp2); LMinvAGMom=fac*Gtemp2;
|
||||
|
||||
|
||||
GaugeField tempDer(left.Grid());
|
||||
std::vector<GaugeLinkField> DerLink(Nd,left.Grid());
|
||||
std::vector<GaugeLinkField> tempDerLink(Nd,left.Grid());
|
||||
|
||||
std::cout<<GridLogMessage << "force contraction "<< i <<std::endl;
|
||||
// roctxRangePushA("RMHMC force contraction");
|
||||
#if 0
|
||||
MDerivLink(GMom,MinvMom[i],tempDer); der += coef*2*par.a1[i]*tempDer;
|
||||
MDerivLink(left_nu,MinvGMom,tempDer); der += coef*2*par.a1[i]*tempDer;
|
||||
MDerivLink(LMinvAGMom,MinvMom[i],tempDer); der += coef*-2.*par.b2*tempDer;
|
||||
MDerivLink(LMinvAMom,MinvGMom,tempDer); der += coef*-2.*par.b2*tempDer;
|
||||
MDerivLink(MinvAGMom,LMinvMom,tempDer); der += coef*-2.*par.b2*tempDer;
|
||||
MDerivLink(AMinvMom,LMinvGMom,tempDer); der += coef*-2.*par.b2*tempDer;
|
||||
MDerivLink(MinvAGMom,MinvMom[i],tempDer); der += coef*-2.*par.b1[i]*tempDer;
|
||||
MDerivLink(AMinvMom,MinvGMom,tempDer); der += coef*-2.*par.b1[i]*tempDer;
|
||||
#else
|
||||
for (int mu=0;mu<Nd;mu++) DerLink[mu]=Zero();
|
||||
MDerivLink(GMom,MinvMom[i],tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*2*par.a1[i]*tempDerLink[mu];
|
||||
MDerivLink(left_nu,MinvGMom,tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*2*par.a1[i]*tempDerLink[mu];
|
||||
MDerivLink(LMinvAGMom,MinvMom[i],tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*-2.*par.b2*tempDerLink[mu];
|
||||
MDerivLink(LMinvAMom,MinvGMom,tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*-2.*par.b2*tempDerLink[mu];
|
||||
MDerivLink(MinvAGMom,LMinvMom,tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*-2.*par.b2*tempDerLink[mu];
|
||||
MDerivLink(AMinvMom,LMinvGMom,tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*-2.*par.b2*tempDerLink[mu];
|
||||
MDerivLink(MinvAGMom,MinvMom[i],tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*-2.*par.b1[i]*tempDerLink[mu];
|
||||
MDerivLink(AMinvMom,MinvGMom,tempDerLink); for (int mu=0;mu<Nd;mu++) DerLink[mu] += coef*-2.*par.b1[i]*tempDerLink[mu];
|
||||
// PokeIndex<LorentzIndex>(der, -factor * der_mu, mu);
|
||||
for (int mu=0;mu<Nd;mu++) PokeIndex<LorentzIndex>(tempDer, tempDerLink[mu], mu);
|
||||
|
||||
der += tempDer;
|
||||
#endif
|
||||
std::cout<<GridLogMessage << "coef = force contraction "<< i << "done "<< coef <<std::endl;
|
||||
// roctxRangePop();
|
||||
|
||||
}
|
||||
}
|
||||
std::cout<<GridLogMessage << "LaplaceEnd " <<std::endl;
|
||||
// exit(-42);
|
||||
}
|
||||
|
||||
void MDeriv(const GaugeField& in, GaugeField& der) {
|
||||
MDeriv(in,in, der);
|
||||
}
|
||||
|
||||
void MDeriv(const GaugeField& left, const GaugeField& right,
|
||||
GaugeField& der) {
|
||||
|
||||
der=Zero();
|
||||
MDerivInt(Mparam, left, right, der,prev_solnsMDeriv );
|
||||
std::cout <<GridLogDebug << "MDeriv:norm2(der) = "<<norm2(der)<<std::endl;
|
||||
}
|
||||
|
||||
void MinvDeriv(const GaugeField& in, GaugeField& der) {
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solns(4);
|
||||
der=Zero();
|
||||
MDerivInt(Gparam, in, in, der,prev_solnsMinvDeriv);
|
||||
std::cout <<GridLogDebug << "MinvDeriv:norm2(der) = "<<norm2(der)<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
void MSquareRootInt(LaplacianRatParams &par, GaugeField& P, std::vector< std::vector<GaugeLinkField> > & prev_solns ){
|
||||
|
||||
std::cout<<GridLogMessage << "LaplaceStart " <<std::endl;
|
||||
RealD fac = -1. / (double(4 * Nd));
|
||||
LapStencil.GaugeImport(Usav);
|
||||
LapStencilF.GaugeImport(UsavF);
|
||||
for(int nu=0; nu<Nd;nu++){
|
||||
GaugeLinkField P_nu = PeekIndex<LorentzIndex>(P, nu);
|
||||
GaugeLinkField Gp(P.Grid());
|
||||
Gp = par.offset * P_nu;
|
||||
ConjugateGradient<GaugeLinkField> CG(par.tolerance,10000);
|
||||
// ConjugateGradient<GaugeLinkFieldF> CG_f(1.0e-8,10000);
|
||||
|
||||
ChronoForecast< QuadLinearOperator<CovariantAdjointLaplacianStencil<Impl,typename Impl::LinkField>,GaugeLinkField> , GaugeLinkField> Forecast;
|
||||
|
||||
GaugeLinkField Gtemp(P.Grid());
|
||||
GaugeLinkField Gtemp2(P.Grid());
|
||||
|
||||
|
||||
for(int i =0;i<par.order;i++){
|
||||
QuadLinearOperator<CovariantAdjointLaplacianStencil<Impl,typename Impl::LinkField>,GaugeLinkField> QuadOp(LapStencil,par.b0[i],fac*par.b1[i],fac*fac*par.b2);
|
||||
|
||||
Gtemp = Forecast(QuadOp, P_nu, prev_solns[nu]);
|
||||
#ifndef MIXED_CG
|
||||
CG(QuadOp,P_nu,Gtemp);
|
||||
#else
|
||||
QuadLinearOperator<CovariantAdjointLaplacianStencil<ImplF,typename ImplF::LinkField>,GaugeLinkFieldF> QuadOpF(LapStencilF,par.b0[i],fac*par.b1[i],fac*fac*par.b2);
|
||||
// QuadLinearOperator<LaplacianAdjointField<ImplF>,GaugeFieldF> QuadOpF(LapStencilF,par.b0[i],par.b1[i],par.b2);
|
||||
MixedPrecisionConjugateGradient<GaugeLinkField,GaugeLinkFieldF> MixedCG(par.tolerance,10000,10000,grid_f,QuadOpF,QuadOp);
|
||||
MixedCG.InnerTolerance=par.tolerance;
|
||||
MixedCG(P_nu,Gtemp);
|
||||
#endif
|
||||
#if USE_CHRONO
|
||||
prev_solns[nu].push_back(Gtemp);
|
||||
#endif
|
||||
|
||||
Gp += par.a0[i]*Gtemp;
|
||||
LapStencil.M(Gtemp,Gtemp2);
|
||||
Gp += par.a1[i]*fac*Gtemp2;
|
||||
}
|
||||
PokeIndex<LorentzIndex>(P, Gp, nu);
|
||||
}
|
||||
std::cout<<GridLogMessage << "LaplaceEnd " <<std::endl;
|
||||
}
|
||||
|
||||
void MSquareRoot(GaugeField& P){
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solns(4);
|
||||
MSquareRootInt(Mparam,P,prev_solns);
|
||||
std::cout <<GridLogDebug << "MSquareRoot:norm2(P) = "<<norm2(P)<<std::endl;
|
||||
}
|
||||
|
||||
void MInvSquareRoot(GaugeField& P){
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solns(4);
|
||||
MSquareRootInt(Gparam,P,prev_solns);
|
||||
std::cout <<GridLogDebug << "MInvSquareRoot:norm2(P) = "<<norm2(P)<<std::endl;
|
||||
}
|
||||
|
||||
void M(const GaugeField& in, GaugeField& out) {
|
||||
out = in;
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solns(4);
|
||||
MSquareRootInt(Mparam,out,prev_solns);
|
||||
MSquareRootInt(Mparam,out,prev_solns);
|
||||
std::cout <<GridLogDebug << "M:norm2(out) = "<<norm2(out)<<std::endl;
|
||||
}
|
||||
|
||||
void Minv(const GaugeField& in, GaugeField& inverted){
|
||||
inverted = in;
|
||||
std::vector< std::vector<GaugeLinkField> > prev_solns(4);
|
||||
MSquareRootInt(Gparam,inverted,prev_solns);
|
||||
MSquareRootInt(Gparam,inverted,prev_solns);
|
||||
std::cout <<GridLogDebug << "Minv:norm2(inverted) = "<<norm2(inverted)<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::vector<GaugeLinkField> U;
|
||||
};
|
||||
#undef MIXED_CG
|
||||
|
||||
NAMESPACE_END(Grid);
|
470
Grid/qcd/utils/GaugeGroup.h
Normal file
470
Grid/qcd/utils/GaugeGroup.h
Normal file
@ -0,0 +1,470 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/utils/GaugeGroup.h
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: neo <cossu@post.kek.jp>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
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
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef QCD_UTIL_GAUGEGROUP_H
|
||||
#define QCD_UTIL_GAUGEGROUP_H
|
||||
|
||||
// Important detail: nvcc requires all template parameters to have names.
|
||||
// This is the only reason why the second template parameter has a name.
|
||||
#define ONLY_IF_SU \
|
||||
typename dummy_name = group_name, \
|
||||
typename named_dummy = std::enable_if_t < \
|
||||
std::is_same<dummy_name, group_name>::value && \
|
||||
is_su<dummy_name>::value >
|
||||
|
||||
#define ONLY_IF_Sp \
|
||||
typename dummy_name = group_name, \
|
||||
typename named_dummy = std::enable_if_t < \
|
||||
std::is_same<dummy_name, group_name>::value && \
|
||||
is_sp<dummy_name>::value >
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
namespace GroupName {
|
||||
class SU {};
|
||||
class Sp {};
|
||||
} // namespace GroupName
|
||||
|
||||
template <typename group_name>
|
||||
struct is_su {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct is_su<GroupName::SU> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template <typename group_name>
|
||||
struct is_sp {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct is_sp<GroupName::Sp> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template <typename group_name>
|
||||
constexpr int compute_adjoint_dimension(int ncolour);
|
||||
|
||||
template <>
|
||||
constexpr int compute_adjoint_dimension<GroupName::SU>(int ncolour) {
|
||||
return ncolour * ncolour - 1;
|
||||
}
|
||||
|
||||
template <>
|
||||
constexpr int compute_adjoint_dimension<GroupName::Sp>(int ncolour) {
|
||||
return ncolour / 2 * (ncolour + 1);
|
||||
}
|
||||
|
||||
template <int ncolour, class group_name>
|
||||
class GaugeGroup {
|
||||
public:
|
||||
static const int Dimension = ncolour;
|
||||
static const int AdjointDimension =
|
||||
compute_adjoint_dimension<group_name>(ncolour);
|
||||
static const int AlgebraDimension =
|
||||
compute_adjoint_dimension<group_name>(ncolour);
|
||||
|
||||
template <typename vtype>
|
||||
using iSU2Matrix = iScalar<iScalar<iMatrix<vtype, 2> > >;
|
||||
template <typename vtype>
|
||||
using iGroupMatrix = iScalar<iScalar<iMatrix<vtype, ncolour> > >;
|
||||
template <typename vtype>
|
||||
using iAlgebraVector = iScalar<iScalar<iVector<vtype, AdjointDimension> > >;
|
||||
static int su2subgroups(void) { return su2subgroups(group_name()); }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Types can be accessed as SU<2>::Matrix , SU<2>::vSUnMatrix,
|
||||
// SU<2>::LatticeMatrix etc...
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
typedef iGroupMatrix<Complex> Matrix;
|
||||
typedef iGroupMatrix<ComplexF> MatrixF;
|
||||
typedef iGroupMatrix<ComplexD> MatrixD;
|
||||
|
||||
typedef iGroupMatrix<vComplex> vMatrix;
|
||||
typedef iGroupMatrix<vComplexF> vMatrixF;
|
||||
typedef iGroupMatrix<vComplexD> vMatrixD;
|
||||
|
||||
// For the projectors to the algebra
|
||||
// these should be real...
|
||||
// keeping complex for consistency with the SIMD vector types
|
||||
typedef iAlgebraVector<Complex> AlgebraVector;
|
||||
typedef iAlgebraVector<ComplexF> AlgebraVectorF;
|
||||
typedef iAlgebraVector<ComplexD> AlgebraVectorD;
|
||||
|
||||
typedef iAlgebraVector<vComplex> vAlgebraVector;
|
||||
typedef iAlgebraVector<vComplexF> vAlgebraVectorF;
|
||||
typedef iAlgebraVector<vComplexD> vAlgebraVectorD;
|
||||
|
||||
typedef Lattice<vMatrix> LatticeMatrix;
|
||||
typedef Lattice<vMatrixF> LatticeMatrixF;
|
||||
typedef Lattice<vMatrixD> LatticeMatrixD;
|
||||
|
||||
typedef Lattice<vAlgebraVector> LatticeAlgebraVector;
|
||||
typedef Lattice<vAlgebraVectorF> LatticeAlgebraVectorF;
|
||||
typedef Lattice<vAlgebraVectorD> LatticeAlgebraVectorD;
|
||||
|
||||
typedef iSU2Matrix<Complex> SU2Matrix;
|
||||
typedef iSU2Matrix<ComplexF> SU2MatrixF;
|
||||
typedef iSU2Matrix<ComplexD> SU2MatrixD;
|
||||
|
||||
typedef iSU2Matrix<vComplex> vSU2Matrix;
|
||||
typedef iSU2Matrix<vComplexF> vSU2MatrixF;
|
||||
typedef iSU2Matrix<vComplexD> vSU2MatrixD;
|
||||
|
||||
typedef Lattice<vSU2Matrix> LatticeSU2Matrix;
|
||||
typedef Lattice<vSU2MatrixF> LatticeSU2MatrixF;
|
||||
typedef Lattice<vSU2MatrixD> LatticeSU2MatrixD;
|
||||
|
||||
// Private implementation details are specified in the following files:
|
||||
// Grid/qcd/utils/SUn.impl
|
||||
// Grid/qcd/utils/SUn.impl
|
||||
// The public part of the interface follows below and refers to these
|
||||
// private member functions.
|
||||
|
||||
#include <Grid/qcd/utils/SUn.impl.h>
|
||||
#include <Grid/qcd/utils/Sp2n.impl.h>
|
||||
|
||||
public:
|
||||
template <class cplx>
|
||||
static void generator(int lieIndex, iGroupMatrix<cplx> &ta) {
|
||||
return generator(lieIndex, ta, group_name());
|
||||
}
|
||||
|
||||
static void su2SubGroupIndex(int &i1, int &i2, int su2_index) {
|
||||
return su2SubGroupIndex(i1, i2, su2_index, group_name());
|
||||
}
|
||||
|
||||
static void testGenerators(void) { testGenerators(group_name()); }
|
||||
|
||||
static void printGenerators(void) {
|
||||
for (int gen = 0; gen < AlgebraDimension; gen++) {
|
||||
Matrix ta;
|
||||
generator(gen, ta);
|
||||
std::cout << GridLogMessage << "Nc = " << ncolour << " t_" << gen
|
||||
<< std::endl;
|
||||
std::cout << GridLogMessage << ta << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename LatticeMatrixType>
|
||||
static void LieRandomize(GridParallelRNG &pRNG, LatticeMatrixType &out,
|
||||
double scale = 1.0) {
|
||||
GridBase *grid = out.Grid();
|
||||
|
||||
typedef typename LatticeMatrixType::vector_type vector_type;
|
||||
|
||||
typedef iSinglet<vector_type> vTComplexType;
|
||||
|
||||
typedef Lattice<vTComplexType> LatticeComplexType;
|
||||
typedef typename GridTypeMapper<
|
||||
typename LatticeMatrixType::vector_object>::scalar_object MatrixType;
|
||||
|
||||
LatticeComplexType ca(grid);
|
||||
LatticeMatrixType lie(grid);
|
||||
LatticeMatrixType la(grid);
|
||||
ComplexD ci(0.0, scale);
|
||||
MatrixType ta;
|
||||
|
||||
lie = Zero();
|
||||
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
random(pRNG, ca);
|
||||
|
||||
ca = (ca + conjugate(ca)) * 0.5;
|
||||
ca = ca - 0.5;
|
||||
|
||||
generator(a, ta);
|
||||
|
||||
la = ci * ca * ta;
|
||||
|
||||
lie = lie + la; // e^{i la ta}
|
||||
}
|
||||
taExp(lie, out);
|
||||
}
|
||||
|
||||
static void GaussianFundamentalLieAlgebraMatrix(GridParallelRNG &pRNG,
|
||||
LatticeMatrix &out,
|
||||
Real scale = 1.0) {
|
||||
GridBase *grid = out.Grid();
|
||||
LatticeReal ca(grid);
|
||||
LatticeMatrix la(grid);
|
||||
Complex ci(0.0, scale);
|
||||
Matrix ta;
|
||||
|
||||
out = Zero();
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
gaussian(pRNG, ca);
|
||||
generator(a, ta);
|
||||
la = toComplex(ca) * ta;
|
||||
out += la;
|
||||
}
|
||||
out *= ci;
|
||||
}
|
||||
|
||||
static void FundamentalLieAlgebraMatrix(const LatticeAlgebraVector &h,
|
||||
LatticeMatrix &out,
|
||||
Real scale = 1.0) {
|
||||
conformable(h, out);
|
||||
GridBase *grid = out.Grid();
|
||||
LatticeMatrix la(grid);
|
||||
Matrix ta;
|
||||
|
||||
out = Zero();
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
generator(a, ta);
|
||||
la = peekColour(h, a) * timesI(ta) * scale;
|
||||
out += la;
|
||||
}
|
||||
}
|
||||
|
||||
// Projects the algebra components a lattice matrix (of dimension ncol*ncol -1
|
||||
// ) inverse operation: FundamentalLieAlgebraMatrix
|
||||
static void projectOnAlgebra(LatticeAlgebraVector &h_out,
|
||||
const LatticeMatrix &in, Real scale = 1.0) {
|
||||
conformable(h_out, in);
|
||||
h_out = Zero();
|
||||
Matrix Ta;
|
||||
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
generator(a, Ta);
|
||||
pokeColour(h_out, -2.0 * (trace(timesI(Ta) * in)) * scale, a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class vtype>
|
||||
accelerator_inline static iScalar<vtype> ProjectOnGeneralGroup(const iScalar<vtype> &r) {
|
||||
return ProjectOnGeneralGroup(r, group_name());
|
||||
}
|
||||
|
||||
template <class vtype, int N>
|
||||
accelerator_inline static iVector<vtype,N> ProjectOnGeneralGroup(const iVector<vtype,N> &r) {
|
||||
return ProjectOnGeneralGroup(r, group_name());
|
||||
}
|
||||
|
||||
template <class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
accelerator_inline static iMatrix<vtype,N> ProjectOnGeneralGroup(const iMatrix<vtype,N> &arg) {
|
||||
return ProjectOnGeneralGroup(arg, group_name());
|
||||
}
|
||||
|
||||
template <int N,class vComplex_t> // Projects on the general groups U(N), Sp(2N)xZ2 i.e. determinant is allowed a complex phase.
|
||||
static void ProjectOnGeneralGroup(Lattice<iVector<iScalar<iMatrix<vComplex_t, N> >, Nd> > &U) {
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
auto Umu = PeekIndex<LorentzIndex>(U, mu);
|
||||
Umu = ProjectOnGeneralGroup(Umu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <int N,class vComplex_t>
|
||||
static Lattice<iScalar<iScalar<iMatrix<vComplex_t, N> > > > ProjectOnGeneralGroup(const Lattice<iScalar<iScalar<iMatrix<vComplex_t, N> > > > &Umu) {
|
||||
return ProjectOnGeneralGroup(Umu, group_name());
|
||||
}
|
||||
|
||||
template <int N,class vComplex_t> // Projects on SU(N), Sp(2N), with unit determinant, by first projecting on general group and then enforcing unit determinant
|
||||
static void ProjectOnSpecialGroup(Lattice<iScalar<iScalar<iMatrix<vComplex_t, N> > > > &Umu) {
|
||||
Umu = ProjectOnGeneralGroup(Umu);
|
||||
auto det = Determinant(Umu);
|
||||
|
||||
det = conjugate(det);
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
auto element = PeekIndex<ColourIndex>(Umu, N - 1, i);
|
||||
element = element * det;
|
||||
PokeIndex<ColourIndex>(Umu, element, Nc - 1, i);
|
||||
}
|
||||
}
|
||||
|
||||
template <int N,class vComplex_t> // reunitarise, resimplectify... previously ProjectSUn
|
||||
static void ProjectOnSpecialGroup(Lattice<iVector<iScalar<iMatrix<vComplex_t, N> >, Nd> > &U) {
|
||||
// Reunitarise
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
auto Umu = PeekIndex<LorentzIndex>(U, mu);
|
||||
ProjectOnSpecialGroup(Umu);
|
||||
PokeIndex<LorentzIndex>(U, Umu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename GaugeField>
|
||||
static void HotConfiguration(GridParallelRNG &pRNG, GaugeField &out) {
|
||||
typedef typename GaugeField::vector_type vector_type;
|
||||
typedef iGroupMatrix<vector_type> vMatrixType;
|
||||
typedef Lattice<vMatrixType> LatticeMatrixType;
|
||||
|
||||
LatticeMatrixType Umu(out.Grid());
|
||||
LatticeMatrixType tmp(out.Grid());
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
// LieRandomize(pRNG, Umu, 1.0);
|
||||
// PokeIndex<LorentzIndex>(out, Umu, mu);
|
||||
gaussian(pRNG,Umu);
|
||||
tmp = Ta(Umu);
|
||||
taExp(tmp,Umu);
|
||||
ProjectOnSpecialGroup(Umu);
|
||||
// ProjectSUn(Umu);
|
||||
PokeIndex<LorentzIndex>(out, Umu, mu);
|
||||
}
|
||||
}
|
||||
template <typename GaugeField>
|
||||
static void TepidConfiguration(GridParallelRNG &pRNG, GaugeField &out) {
|
||||
typedef typename GaugeField::vector_type vector_type;
|
||||
typedef iGroupMatrix<vector_type> vMatrixType;
|
||||
typedef Lattice<vMatrixType> LatticeMatrixType;
|
||||
|
||||
LatticeMatrixType Umu(out.Grid());
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
LieRandomize(pRNG, Umu, 0.01);
|
||||
PokeIndex<LorentzIndex>(out, Umu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename GaugeField>
|
||||
static void ColdConfiguration(GaugeField &out) {
|
||||
typedef typename GaugeField::vector_type vector_type;
|
||||
typedef iGroupMatrix<vector_type> vMatrixType;
|
||||
typedef Lattice<vMatrixType> LatticeMatrixType;
|
||||
|
||||
LatticeMatrixType Umu(out.Grid());
|
||||
Umu = 1.0;
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
PokeIndex<LorentzIndex>(out, Umu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename GaugeField>
|
||||
static void ColdConfiguration(GridParallelRNG &pRNG, GaugeField &out) {
|
||||
ColdConfiguration(out);
|
||||
}
|
||||
|
||||
template <typename LatticeMatrixType>
|
||||
static void taProj(const LatticeMatrixType &in, LatticeMatrixType &out) {
|
||||
taProj(in, out, group_name());
|
||||
}
|
||||
|
||||
template <typename LatticeMatrixType>
|
||||
static void taExp(const LatticeMatrixType &x, LatticeMatrixType &ex) {
|
||||
typedef typename LatticeMatrixType::scalar_type ComplexType;
|
||||
|
||||
LatticeMatrixType xn(x.Grid());
|
||||
RealD nfac = 1.0;
|
||||
|
||||
xn = x;
|
||||
ex = xn + ComplexType(1.0); // 1+x
|
||||
|
||||
// Do a 12th order exponentiation
|
||||
for (int i = 2; i <= 12; ++i) {
|
||||
nfac = nfac / RealD(i); // 1/2, 1/2.3 ...
|
||||
xn = xn * x; // x2, x3,x4....
|
||||
ex = ex + xn * nfac; // x2/2!, x3/3!....
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <int ncolour>
|
||||
using SU = GaugeGroup<ncolour, GroupName::SU>;
|
||||
|
||||
template <int ncolour>
|
||||
using Sp = GaugeGroup<ncolour, GroupName::Sp>;
|
||||
|
||||
typedef SU<2> SU2;
|
||||
typedef SU<3> SU3;
|
||||
typedef SU<4> SU4;
|
||||
typedef SU<5> SU5;
|
||||
|
||||
typedef SU<Nc> FundamentalMatrices;
|
||||
|
||||
typedef Sp<2> Sp2;
|
||||
typedef Sp<4> Sp4;
|
||||
typedef Sp<6> Sp6;
|
||||
typedef Sp<8> Sp8;
|
||||
|
||||
template <int N,class vComplex_t>
|
||||
static void ProjectSUn(Lattice<iScalar<iScalar<iMatrix<vComplex_t, N> > > > &Umu)
|
||||
{
|
||||
GaugeGroup<N,GroupName::SU>::ProjectOnSpecialGroup(Umu);
|
||||
}
|
||||
|
||||
template <int N,class vComplex_t>
|
||||
static void ProjectSUn(Lattice<iVector<iScalar<iMatrix<vComplex_t, N> >,Nd> > &U)
|
||||
{
|
||||
GaugeGroup<N,GroupName::SU>::ProjectOnSpecialGroup(U);
|
||||
}
|
||||
|
||||
template <int N,class vComplex_t>
|
||||
static void ProjectSpn(Lattice<iScalar<iScalar<iMatrix<vComplex_t, N> > > > &Umu)
|
||||
{
|
||||
GaugeGroup<N,GroupName::Sp>::ProjectOnSpecialGroup(Umu);
|
||||
}
|
||||
|
||||
template <int N,class vComplex_t>
|
||||
static void ProjectSpn(Lattice<iVector<iScalar<iMatrix<vComplex_t, N> >,Nd> > &U)
|
||||
{
|
||||
GaugeGroup<N,GroupName::Sp>::ProjectOnSpecialGroup(U);
|
||||
}
|
||||
|
||||
// Explicit specialisation for SU(3).
|
||||
static void ProjectSU3(Lattice<iScalar<iScalar<iMatrix<vComplexD, 3> > > > &Umu)
|
||||
{
|
||||
GridBase *grid = Umu.Grid();
|
||||
const int x = 0;
|
||||
const int y = 1;
|
||||
const int z = 2;
|
||||
// Reunitarise
|
||||
Umu = ProjectOnGroup(Umu);
|
||||
autoView(Umu_v, Umu, CpuWrite);
|
||||
thread_for(ss, grid->oSites(), {
|
||||
auto cm = Umu_v[ss];
|
||||
cm()()(2, x) = adj(cm()()(0, y) * cm()()(1, z) -
|
||||
cm()()(0, z) * cm()()(1, y)); // x= yz-zy
|
||||
cm()()(2, y) = adj(cm()()(0, z) * cm()()(1, x) -
|
||||
cm()()(0, x) * cm()()(1, z)); // y= zx-xz
|
||||
cm()()(2, z) = adj(cm()()(0, x) * cm()()(1, y) -
|
||||
cm()()(0, y) * cm()()(1, x)); // z= xy-yx
|
||||
Umu_v[ss] = cm;
|
||||
});
|
||||
}
|
||||
static void ProjectSU3(Lattice<iVector<iScalar<iMatrix<vComplexD, 3> >, Nd> > &U)
|
||||
{
|
||||
GridBase *grid = U.Grid();
|
||||
// Reunitarise
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
auto Umu = PeekIndex<LorentzIndex>(U, mu);
|
||||
Umu = ProjectOnGroup(Umu);
|
||||
ProjectSU3(Umu);
|
||||
PokeIndex<LorentzIndex>(U, Umu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
#endif
|
371
Grid/qcd/utils/GaugeGroupTwoIndex.h
Normal file
371
Grid/qcd/utils/GaugeGroupTwoIndex.h
Normal file
@ -0,0 +1,371 @@
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// * Two index representation generators
|
||||
//
|
||||
// * Normalisation for the fundamental generators:
|
||||
// trace ta tb = 1/2 delta_ab = T_F delta_ab
|
||||
// T_F = 1/2 for SU(N) groups
|
||||
//
|
||||
//
|
||||
// base for NxN two index (anti-symmetric) matrices
|
||||
// normalized to 1 (d_ij is the kroenecker delta)
|
||||
//
|
||||
// (e^(ij)_{kl} = 1 / sqrt(2) (d_ik d_jl +/- d_jk d_il)
|
||||
//
|
||||
// Then the generators are written as
|
||||
//
|
||||
// (iT_a)^(ij)(lk) = i * ( tr[e^(ij)^dag e^(lk) T^trasp_a] +
|
||||
// tr[e^(lk)e^(ij)^dag T_a] ) //
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Authors: David Preti, Guido Cossu
|
||||
|
||||
#ifndef QCD_UTIL_GAUGEGROUPTWOINDEX_H
|
||||
#define QCD_UTIL_GAUGEGROUPTWOINDEX_H
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
enum TwoIndexSymmetry { Symmetric = 1, AntiSymmetric = -1 };
|
||||
|
||||
constexpr inline Real delta(int a, int b) { return (a == b) ? 1.0 : 0.0; }
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class cplx, int nc, TwoIndexSymmetry S>
|
||||
struct baseOffDiagonalSpHelper;
|
||||
|
||||
template <class cplx, int nc>
|
||||
struct baseOffDiagonalSpHelper<cplx, nc, AntiSymmetric> {
|
||||
static const int ngroup = nc / 2;
|
||||
static void baseOffDiagonalSp(int i, int j, iScalar<iScalar<iMatrix<cplx, nc> > > &eij) {
|
||||
eij = Zero();
|
||||
RealD tmp;
|
||||
|
||||
if ((i == ngroup + j) && (1 <= j) && (j < ngroup)) {
|
||||
for (int k = 0; k < j+1; k++) {
|
||||
if (k < j) {
|
||||
tmp = 1 / sqrt(j * (j + 1));
|
||||
eij()()(k, k + ngroup) = tmp;
|
||||
eij()()(k + ngroup, k) = -tmp;
|
||||
}
|
||||
if (k == j) {
|
||||
tmp = -j / sqrt(j * (j + 1));
|
||||
eij()()(k, k + ngroup) = tmp;
|
||||
eij()()(k + ngroup, k) = -tmp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if (i != ngroup + j) {
|
||||
for (int k = 0; k < nc; k++)
|
||||
for (int l = 0; l < nc; l++) {
|
||||
eij()()(l, k) =
|
||||
delta(i, k) * delta(j, l) - delta(j, k) * delta(i, l);
|
||||
}
|
||||
}
|
||||
RealD nrm = 1. / std::sqrt(2.0);
|
||||
eij = eij * nrm;
|
||||
}
|
||||
};
|
||||
|
||||
template <class cplx, int nc>
|
||||
struct baseOffDiagonalSpHelper<cplx, nc, Symmetric> {
|
||||
static void baseOffDiagonalSp(int i, int j, iScalar<iScalar<iMatrix<cplx, nc> > > &eij) {
|
||||
eij = Zero();
|
||||
for (int k = 0; k < nc; k++)
|
||||
for (int l = 0; l < nc; l++)
|
||||
eij()()(l, k) =
|
||||
delta(i, k) * delta(j, l) + delta(j, k) * delta(i, l);
|
||||
|
||||
RealD nrm = 1. / std::sqrt(2.0);
|
||||
eij = eij * nrm;
|
||||
}
|
||||
};
|
||||
|
||||
} // closing detail namespace
|
||||
|
||||
template <int ncolour, TwoIndexSymmetry S, class group_name>
|
||||
class GaugeGroupTwoIndex : public GaugeGroup<ncolour, group_name> {
|
||||
public:
|
||||
// The chosen convention is that we are taking ncolour to be N in SU<N> but 2N
|
||||
// in Sp(2N). ngroup is equal to N for SU but 2N/2 = N for Sp(2N).
|
||||
static_assert(std::is_same<group_name, GroupName::SU>::value or
|
||||
std::is_same<group_name, GroupName::Sp>::value,
|
||||
"ngroup is only implemented for SU and Sp currently.");
|
||||
static const int ngroup =
|
||||
std::is_same<group_name, GroupName::SU>::value ? ncolour : ncolour / 2;
|
||||
static const int Dimension =
|
||||
(ncolour * (ncolour + S) / 2) + (std::is_same<group_name, GroupName::Sp>::value ? (S - 1) / 2 : 0);
|
||||
static const int DimensionAS =
|
||||
(ncolour * (ncolour - 1) / 2) + (std::is_same<group_name, GroupName::Sp>::value ? (- 1) : 0);
|
||||
static const int DimensionS =
|
||||
ncolour * (ncolour + 1) / 2;
|
||||
static const int NumGenerators =
|
||||
GaugeGroup<ncolour, group_name>::AlgebraDimension;
|
||||
|
||||
template <typename vtype>
|
||||
using iGroupTwoIndexMatrix = iScalar<iScalar<iMatrix<vtype, Dimension> > >;
|
||||
|
||||
typedef iGroupTwoIndexMatrix<Complex> TIMatrix;
|
||||
typedef iGroupTwoIndexMatrix<ComplexF> TIMatrixF;
|
||||
typedef iGroupTwoIndexMatrix<ComplexD> TIMatrixD;
|
||||
|
||||
typedef iGroupTwoIndexMatrix<vComplex> vTIMatrix;
|
||||
typedef iGroupTwoIndexMatrix<vComplexF> vTIMatrixF;
|
||||
typedef iGroupTwoIndexMatrix<vComplexD> vTIMatrixD;
|
||||
|
||||
typedef Lattice<vTIMatrix> LatticeTwoIndexMatrix;
|
||||
typedef Lattice<vTIMatrixF> LatticeTwoIndexMatrixF;
|
||||
typedef Lattice<vTIMatrixD> LatticeTwoIndexMatrixD;
|
||||
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplex, Dimension> >, Nd> >
|
||||
LatticeTwoIndexField;
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplexF, Dimension> >, Nd> >
|
||||
LatticeTwoIndexFieldF;
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplexD, Dimension> >, Nd> >
|
||||
LatticeTwoIndexFieldD;
|
||||
|
||||
template <typename vtype>
|
||||
using iGroupMatrix = iScalar<iScalar<iMatrix<vtype, ncolour> > >;
|
||||
|
||||
typedef iGroupMatrix<Complex> Matrix;
|
||||
typedef iGroupMatrix<ComplexF> MatrixF;
|
||||
typedef iGroupMatrix<ComplexD> MatrixD;
|
||||
|
||||
private:
|
||||
template <class cplx>
|
||||
static void baseDiagonal(int Index, iGroupMatrix<cplx> &eij) {
|
||||
eij = Zero();
|
||||
eij()()(Index - ncolour * (ncolour - 1) / 2,
|
||||
Index - ncolour * (ncolour - 1) / 2) = 1.0;
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void baseOffDiagonal(int i, int j, iGroupMatrix<cplx> &eij, GroupName::SU) {
|
||||
eij = Zero();
|
||||
for (int k = 0; k < ncolour; k++)
|
||||
for (int l = 0; l < ncolour; l++)
|
||||
eij()()(l, k) =
|
||||
delta(i, k) * delta(j, l) + S * delta(j, k) * delta(i, l);
|
||||
|
||||
RealD nrm = 1. / std::sqrt(2.0);
|
||||
eij = eij * nrm;
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void baseOffDiagonal(int i, int j, iGroupMatrix<cplx> &eij, GroupName::Sp) {
|
||||
detail::baseOffDiagonalSpHelper<cplx, ncolour, S>::baseOffDiagonalSp(i, j, eij);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <class cplx>
|
||||
static void base(int Index, iGroupMatrix<cplx> &eij) {
|
||||
// returns (e)^(ij)_{kl} necessary for change of base U_F -> U_R
|
||||
assert(Index < Dimension);
|
||||
eij = Zero();
|
||||
// for the linearisation of the 2 indexes
|
||||
static int a[ncolour * (ncolour - 1) / 2][2]; // store the a <-> i,j
|
||||
static bool filled = false;
|
||||
if (!filled) {
|
||||
int counter = 0;
|
||||
for (int i = 1; i < ncolour; i++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (std::is_same<group_name, GroupName::Sp>::value)
|
||||
{
|
||||
if (j==0 && i==ngroup+j && S==-1) {
|
||||
//std::cout << "skipping" << std::endl; // for Sp2n this vanishes identically.
|
||||
j = j+1;
|
||||
}
|
||||
}
|
||||
a[counter][0] = i;
|
||||
a[counter][1] = j;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
filled = true;
|
||||
}
|
||||
if (Index < ncolour*ncolour - DimensionS)
|
||||
{
|
||||
baseOffDiagonal(a[Index][0], a[Index][1], eij, group_name());
|
||||
} else {
|
||||
baseDiagonal(Index, eij);
|
||||
}
|
||||
}
|
||||
|
||||
static void printBase(void) {
|
||||
for (int gen = 0; gen < Dimension; gen++) {
|
||||
Matrix tmp;
|
||||
base(gen, tmp);
|
||||
std::cout << GridLogMessage << "Nc = " << ncolour << " t_" << gen
|
||||
<< std::endl;
|
||||
std::cout << GridLogMessage << tmp << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void generator(int Index, iGroupTwoIndexMatrix<cplx> &i2indTa) {
|
||||
Vector<iGroupMatrix<cplx> > ta(NumGenerators);
|
||||
Vector<iGroupMatrix<cplx> > eij(Dimension);
|
||||
iGroupMatrix<cplx> tmp;
|
||||
|
||||
for (int a = 0; a < NumGenerators; a++)
|
||||
GaugeGroup<ncolour, group_name>::generator(a, ta[a]);
|
||||
|
||||
for (int a = 0; a < Dimension; a++) base(a, eij[a]);
|
||||
|
||||
for (int a = 0; a < Dimension; a++) {
|
||||
tmp = transpose(eij[a]*ta[Index]) + transpose(eij[a]) * ta[Index];
|
||||
for (int b = 0; b < Dimension; b++) {
|
||||
Complex iTr = TensorRemove(timesI(trace(tmp * eij[b])));
|
||||
i2indTa()()(a, b) = iTr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void printGenerators(void) {
|
||||
for (int gen = 0; gen < NumGenerators; gen++) {
|
||||
TIMatrix i2indTa;
|
||||
generator(gen, i2indTa);
|
||||
std::cout << GridLogMessage << "Nc = " << ncolour << " t_" << gen
|
||||
<< std::endl;
|
||||
std::cout << GridLogMessage << i2indTa << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void testGenerators(void) {
|
||||
TIMatrix i2indTa, i2indTb;
|
||||
std::cout << GridLogMessage << "2IndexRep - Checking if traceless"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < NumGenerators; a++) {
|
||||
generator(a, i2indTa);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(trace(i2indTa)) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
|
||||
std::cout << GridLogMessage << "2IndexRep - Checking if antihermitean"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < NumGenerators; a++) {
|
||||
generator(a, i2indTa);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(adj(i2indTa) + i2indTa) < 1.0e-6);
|
||||
}
|
||||
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
std::cout << GridLogMessage
|
||||
<< "2IndexRep - Checking Tr[Ta*Tb]=delta(a,b)*(N +- 2)/2"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < NumGenerators; a++) {
|
||||
for (int b = 0; b < NumGenerators; b++) {
|
||||
generator(a, i2indTa);
|
||||
generator(b, i2indTb);
|
||||
|
||||
// generator returns iTa, so we need a minus sign here
|
||||
Complex Tr = -TensorRemove(trace(i2indTa * i2indTb));
|
||||
std::cout << GridLogMessage << "a=" << a << "b=" << b << "Tr=" << Tr
|
||||
<< std::endl;
|
||||
if (a == b) {
|
||||
assert(real(Tr) - ((ncolour + S * 2) * 0.5) < 1e-8);
|
||||
} else {
|
||||
assert(real(Tr) < 1e-8);
|
||||
}
|
||||
assert(imag(Tr) < 1e-8);
|
||||
}
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
}
|
||||
|
||||
static void TwoIndexLieAlgebraMatrix(
|
||||
const typename GaugeGroup<ncolour, group_name>::LatticeAlgebraVector &h,
|
||||
LatticeTwoIndexMatrix &out, Real scale = 1.0) {
|
||||
conformable(h, out);
|
||||
GridBase *grid = out.Grid();
|
||||
LatticeTwoIndexMatrix la(grid);
|
||||
TIMatrix i2indTa;
|
||||
|
||||
out = Zero();
|
||||
for (int a = 0; a < NumGenerators; a++) {
|
||||
generator(a, i2indTa);
|
||||
la = peekColour(h, a) * i2indTa;
|
||||
out += la;
|
||||
}
|
||||
out *= scale;
|
||||
}
|
||||
|
||||
// Projects the algebra components
|
||||
// of a lattice matrix ( of dimension ncol*ncol -1 )
|
||||
static void projectOnAlgebra(
|
||||
typename GaugeGroup<ncolour, group_name>::LatticeAlgebraVector &h_out,
|
||||
const LatticeTwoIndexMatrix &in, Real scale = 1.0) {
|
||||
conformable(h_out, in);
|
||||
h_out = Zero();
|
||||
TIMatrix i2indTa;
|
||||
Real coefficient = -2.0 / (ncolour + 2 * S) * scale;
|
||||
// 2/(Nc +/- 2) for the normalization of the trace in the two index rep
|
||||
for (int a = 0; a < NumGenerators; a++) {
|
||||
generator(a, i2indTa);
|
||||
pokeColour(h_out, real(trace(i2indTa * in)) * coefficient, a);
|
||||
}
|
||||
}
|
||||
|
||||
// a projector that keeps the generators stored to avoid the overhead of
|
||||
// recomputing them
|
||||
static void projector(
|
||||
typename GaugeGroup<ncolour, group_name>::LatticeAlgebraVector &h_out,
|
||||
const LatticeTwoIndexMatrix &in, Real scale = 1.0) {
|
||||
conformable(h_out, in);
|
||||
// to store the generators
|
||||
static std::vector<TIMatrix> i2indTa(NumGenerators);
|
||||
h_out = Zero();
|
||||
static bool precalculated = false;
|
||||
if (!precalculated) {
|
||||
precalculated = true;
|
||||
for (int a = 0; a < NumGenerators; a++) generator(a, i2indTa[a]);
|
||||
}
|
||||
|
||||
Real coefficient =
|
||||
-2.0 / (ncolour + 2 * S) * scale; // 2/(Nc +/- 2) for the normalization
|
||||
// of the trace in the two index rep
|
||||
|
||||
for (int a = 0; a < NumGenerators; a++) {
|
||||
auto tmp = real(trace(i2indTa[a] * in)) * coefficient;
|
||||
pokeColour(h_out, tmp, a);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <int ncolour, TwoIndexSymmetry S>
|
||||
using SU_TwoIndex = GaugeGroupTwoIndex<ncolour, S, GroupName::SU>;
|
||||
|
||||
// Some useful type names
|
||||
typedef SU_TwoIndex<Nc, Symmetric> TwoIndexSymmMatrices;
|
||||
typedef SU_TwoIndex<Nc, AntiSymmetric> TwoIndexAntiSymmMatrices;
|
||||
|
||||
typedef SU_TwoIndex<2, Symmetric> SU2TwoIndexSymm;
|
||||
typedef SU_TwoIndex<3, Symmetric> SU3TwoIndexSymm;
|
||||
typedef SU_TwoIndex<4, Symmetric> SU4TwoIndexSymm;
|
||||
typedef SU_TwoIndex<5, Symmetric> SU5TwoIndexSymm;
|
||||
|
||||
typedef SU_TwoIndex<2, AntiSymmetric> SU2TwoIndexAntiSymm;
|
||||
typedef SU_TwoIndex<3, AntiSymmetric> SU3TwoIndexAntiSymm;
|
||||
typedef SU_TwoIndex<4, AntiSymmetric> SU4TwoIndexAntiSymm;
|
||||
typedef SU_TwoIndex<5, AntiSymmetric> SU5TwoIndexAntiSymm;
|
||||
|
||||
template <int ncolour, TwoIndexSymmetry S>
|
||||
using Sp_TwoIndex = GaugeGroupTwoIndex<ncolour, S, GroupName::Sp>;
|
||||
|
||||
typedef Sp_TwoIndex<Nc, Symmetric> SpTwoIndexSymmMatrices;
|
||||
typedef Sp_TwoIndex<Nc, AntiSymmetric> SpTwoIndexAntiSymmMatrices;
|
||||
|
||||
typedef Sp_TwoIndex<2, Symmetric> Sp2TwoIndexSymm;
|
||||
typedef Sp_TwoIndex<4, Symmetric> Sp4TwoIndexSymm;
|
||||
|
||||
typedef Sp_TwoIndex<4, AntiSymmetric> Sp4TwoIndexAntiSymm;
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif
|
@ -7,6 +7,7 @@ Source file: ./lib/qcd/hmc/integrators/Integrator.h
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
Author: Chulwoo Jung <chulwoo@bnl.gov>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -33,7 +34,12 @@ NAMESPACE_BEGIN(Grid);
|
||||
|
||||
template <typename Field>
|
||||
class Metric{
|
||||
protected:
|
||||
int triv;
|
||||
public:
|
||||
Metric(){this->triv=1;}
|
||||
int Trivial(){ return triv;}
|
||||
//printf("Metric::Trivial=%d\n",triv); ;
|
||||
virtual void ImportGauge(const Field&) = 0;
|
||||
virtual void M(const Field&, Field&) = 0;
|
||||
virtual void Minv(const Field&, Field&) = 0;
|
||||
@ -41,6 +47,8 @@ public:
|
||||
virtual void MInvSquareRoot(Field&) = 0;
|
||||
virtual void MDeriv(const Field&, Field&) = 0;
|
||||
virtual void MDeriv(const Field&, const Field&, Field&) = 0;
|
||||
virtual void MinvDeriv(const Field&, Field&) = 0;
|
||||
// virtual void MinvDeriv(const Field&, const Field&, Field&) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -48,23 +56,36 @@ public:
|
||||
template <typename Field>
|
||||
class TrivialMetric : public Metric<Field>{
|
||||
public:
|
||||
// TrivialMetric(){this->triv=1;printf("TrivialMetric::triv=%d\n",this->Trivial());}
|
||||
virtual void ImportGauge(const Field&){};
|
||||
virtual void M(const Field& in, Field& out){
|
||||
// printf("M:norm=%0.15e\n",norm2(in));
|
||||
std::cout << GridLogIntegrator << " M:norm(in)= " << std::sqrt(norm2(in)) << std::endl;
|
||||
out = in;
|
||||
}
|
||||
virtual void Minv(const Field& in, Field& out){
|
||||
std::cout << GridLogIntegrator << " Minv:norm(in)= " << std::sqrt(norm2(in)) << std::endl;
|
||||
out = in;
|
||||
}
|
||||
virtual void MSquareRoot(Field& P){
|
||||
std::cout << GridLogIntegrator << " MSquareRoot:norm(P)= " << std::sqrt(norm2(P)) << std::endl;
|
||||
// do nothing
|
||||
}
|
||||
virtual void MInvSquareRoot(Field& P){
|
||||
std::cout << GridLogIntegrator << " MInvSquareRoot:norm(P)= " << std::sqrt(norm2(P)) << std::endl;
|
||||
// do nothing
|
||||
}
|
||||
virtual void MDeriv(const Field& in, Field& out){
|
||||
std::cout << GridLogIntegrator << " MDeriv:norm(in)= " << std::sqrt(norm2(in)) << std::endl;
|
||||
out = Zero();
|
||||
}
|
||||
virtual void MinvDeriv(const Field& in, Field& out){
|
||||
std::cout << GridLogIntegrator << " MinvDeriv:norm(in)= " << std::sqrt(norm2(in)) << std::endl;
|
||||
out = Zero();
|
||||
}
|
||||
virtual void MDeriv(const Field& left, const Field& right, Field& out){
|
||||
std::cout << GridLogIntegrator << " MDeriv:norm(left)= " << std::sqrt(norm2(left)) << std::endl;
|
||||
std::cout << GridLogIntegrator << " MDeriv:norm(right)= " << std::sqrt(norm2(right)) << std::endl;
|
||||
out = Zero();
|
||||
}
|
||||
|
||||
@ -101,14 +122,15 @@ public:
|
||||
// Generate gaussian momenta
|
||||
Implementation::generate_momenta(Mom, sRNG, pRNG);
|
||||
// Modify the distribution with the metric
|
||||
// if(M.Trivial()) return;
|
||||
M.MSquareRoot(Mom);
|
||||
|
||||
if (1) {
|
||||
// Auxiliary momenta
|
||||
// do nothing if trivial, so hide in the metric
|
||||
MomentaField AuxMomTemp(Mom.Grid());
|
||||
Implementation::generate_momenta(AuxMom, sRNG, pRNG);
|
||||
Implementation::generate_momenta(AuxField, sRNG, pRNG);
|
||||
Implementation::generate_momenta(AuxMom, sRNG,pRNG);
|
||||
Implementation::generate_momenta(AuxField, sRNG,pRNG);
|
||||
// Modify the distribution with the metric
|
||||
// Aux^dag M Aux
|
||||
M.MInvSquareRoot(AuxMom); // AuxMom = M^{-1/2} AuxMomTemp
|
||||
@ -117,11 +139,12 @@ public:
|
||||
|
||||
// Correct
|
||||
RealD MomentaAction(){
|
||||
static RealD Saux=0.,Smom=0.;
|
||||
MomentaField inv(Mom.Grid());
|
||||
inv = Zero();
|
||||
M.Minv(Mom, inv);
|
||||
LatticeComplex Hloc(Mom.Grid());
|
||||
Hloc = Zero();
|
||||
LatticeComplex Hloc(Mom.Grid()); Hloc = Zero();
|
||||
LatticeComplex Hloc2(Mom.Grid()); Hloc2 = Zero();
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
// This is not very general
|
||||
// hide in the metric
|
||||
@ -129,8 +152,15 @@ public:
|
||||
auto inv_mu = PeekIndex<LorentzIndex>(inv, mu);
|
||||
Hloc += trace(Mom_mu * inv_mu);
|
||||
}
|
||||
auto Htmp1 = TensorRemove(sum(Hloc));
|
||||
std::cout << GridLogMessage << "S:dSmom = " << Htmp1.real()-Smom << "\n";
|
||||
Smom=Htmp1.real()/HMC_MOMENTUM_DENOMINATOR;
|
||||
|
||||
|
||||
if (1) {
|
||||
|
||||
|
||||
// if(!M.Trivial())
|
||||
{
|
||||
// Auxiliary Fields
|
||||
// hide in the metric
|
||||
M.M(AuxMom, inv);
|
||||
@ -140,13 +170,18 @@ public:
|
||||
auto inv_mu = PeekIndex<LorentzIndex>(inv, mu);
|
||||
auto am_mu = PeekIndex<LorentzIndex>(AuxMom, mu);
|
||||
auto af_mu = PeekIndex<LorentzIndex>(AuxField, mu);
|
||||
Hloc += trace(am_mu * inv_mu);// p M p
|
||||
Hloc += trace(af_mu * af_mu);
|
||||
Hloc += trace(am_mu * inv_mu);
|
||||
Hloc2 += trace(af_mu * af_mu);
|
||||
}
|
||||
}
|
||||
auto Htmp2 = TensorRemove(sum(Hloc))-Htmp1;
|
||||
std::cout << GridLogMessage << "S:dSaux = " << Htmp2.real()-Saux << "\n";
|
||||
Saux=Htmp2.real();
|
||||
|
||||
auto Hsum = TensorRemove(sum(Hloc));
|
||||
return Hsum.real();
|
||||
auto Hsum = TensorRemove(sum(Hloc))/HMC_MOMENTUM_DENOMINATOR;
|
||||
auto Hsum2 = TensorRemove(sum(Hloc2));
|
||||
std::cout << GridLogIntegrator << "MomentaAction: " << Hsum.real()+Hsum2.real() << std::endl;
|
||||
return Hsum.real()+Hsum2.real();
|
||||
}
|
||||
|
||||
// Correct
|
||||
@ -157,15 +192,17 @@ public:
|
||||
MomentaField MDer(in.Grid());
|
||||
MomentaField X(in.Grid());
|
||||
X = Zero();
|
||||
M.Minv(in, X); // X = G in
|
||||
M.MDeriv(X, MDer); // MDer = U * dS/dU
|
||||
der = Implementation::projectForce(MDer); // Ta if gauge fields
|
||||
M.MinvDeriv(in, MDer); // MDer = U * dS/dU
|
||||
der = -1.0* Implementation::projectForce(MDer); // Ta if gauge fields
|
||||
// std::cout << GridLogIntegrator << " DerivativeU: norm(in)= " << std::sqrt(norm2(in)) << std::endl;
|
||||
// std::cout << GridLogIntegrator << " DerivativeU: norm(der)= " << std::sqrt(norm2(der)) << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void AuxiliaryFieldsDerivative(MomentaField& der){
|
||||
der = Zero();
|
||||
if (1){
|
||||
// if(!M.Trivial())
|
||||
{
|
||||
// Auxiliary fields
|
||||
MomentaField der_temp(der.Grid());
|
||||
MomentaField X(der.Grid());
|
||||
@ -173,6 +210,7 @@ public:
|
||||
//M.M(AuxMom, X); // X = M Aux
|
||||
// Two derivative terms
|
||||
// the Mderiv need separation of left and right terms
|
||||
std::cout << GridLogIntegrator << " AuxiliaryFieldsDerivative:norm(AuxMom)= " << std::sqrt(norm2(AuxMom)) << std::endl;
|
||||
M.MDeriv(AuxMom, der);
|
||||
|
||||
|
||||
@ -180,6 +218,7 @@ public:
|
||||
//M.MDeriv(X, AuxMom, der_temp); der += der_temp;
|
||||
|
||||
der = -1.0*Implementation::projectForce(der);
|
||||
std::cout << GridLogIntegrator << " AuxiliaryFieldsDerivative:norm(der)= " << std::sqrt(norm2(der)) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,22 +228,28 @@ public:
|
||||
// is the projection necessary here?
|
||||
// no for fields in the algebra
|
||||
der = Implementation::projectForce(der);
|
||||
std::cout << GridLogIntegrator << " DerivativeP:norm(der)= " << std::sqrt(norm2(der)) << std::endl;
|
||||
}
|
||||
|
||||
void update_auxiliary_momenta(RealD ep){
|
||||
if(1){
|
||||
AuxMom -= ep * AuxField;
|
||||
std::cout << GridLogIntegrator << "AuxMom update_auxiliary_fields: " << std::sqrt(norm2(AuxMom)) << std::endl;
|
||||
std::cout << GridLogIntegrator << "AuxField update_auxiliary_fields: " << std::sqrt(norm2(AuxField)) << std::endl;
|
||||
{
|
||||
AuxMom -= ep * AuxField * HMC_MOMENTUM_DENOMINATOR;
|
||||
std::cout << GridLogIntegrator << "AuxMom update_auxiliary_fields: " << std::sqrt(norm2(AuxMom)) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void update_auxiliary_fields(RealD ep){
|
||||
if (1) {
|
||||
// if(!M.Trivial())
|
||||
{
|
||||
MomentaField tmp(AuxMom.Grid());
|
||||
MomentaField tmp2(AuxMom.Grid());
|
||||
M.M(AuxMom, tmp);
|
||||
// M.M(tmp, tmp2);
|
||||
AuxField += ep * tmp; // M^2 AuxMom
|
||||
// factor of 2?
|
||||
std::cout << GridLogIntegrator << "AuxField update_auxiliary_fields: " << std::sqrt(norm2(AuxField)) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,892 +0,0 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/utils/SUn.h
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: neo <cossu@post.kek.jp>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
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
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef QCD_UTIL_SUN_H
|
||||
#define QCD_UTIL_SUN_H
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
template <int ncolour>
|
||||
class SU {
|
||||
public:
|
||||
static const int Dimension = ncolour;
|
||||
static const int AdjointDimension = ncolour * ncolour - 1;
|
||||
static int su2subgroups(void) { return (ncolour * (ncolour - 1)) / 2; }
|
||||
|
||||
template <typename vtype>
|
||||
using iSUnMatrix = iScalar<iScalar<iMatrix<vtype, ncolour> > >;
|
||||
template <typename vtype>
|
||||
using iSU2Matrix = iScalar<iScalar<iMatrix<vtype, 2> > >;
|
||||
template <typename vtype>
|
||||
using iSUnAlgebraVector =
|
||||
iScalar<iScalar<iVector<vtype, AdjointDimension> > >;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Types can be accessed as SU<2>::Matrix , SU<2>::vSUnMatrix,
|
||||
// SU<2>::LatticeMatrix etc...
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
typedef iSUnMatrix<Complex> Matrix;
|
||||
typedef iSUnMatrix<ComplexF> MatrixF;
|
||||
typedef iSUnMatrix<ComplexD> MatrixD;
|
||||
|
||||
typedef iSUnMatrix<vComplex> vMatrix;
|
||||
typedef iSUnMatrix<vComplexF> vMatrixF;
|
||||
typedef iSUnMatrix<vComplexD> vMatrixD;
|
||||
|
||||
// For the projectors to the algebra
|
||||
// these should be real...
|
||||
// keeping complex for consistency with the SIMD vector types
|
||||
typedef iSUnAlgebraVector<Complex> AlgebraVector;
|
||||
typedef iSUnAlgebraVector<ComplexF> AlgebraVectorF;
|
||||
typedef iSUnAlgebraVector<ComplexD> AlgebraVectorD;
|
||||
|
||||
typedef iSUnAlgebraVector<vComplex> vAlgebraVector;
|
||||
typedef iSUnAlgebraVector<vComplexF> vAlgebraVectorF;
|
||||
typedef iSUnAlgebraVector<vComplexD> vAlgebraVectorD;
|
||||
|
||||
typedef Lattice<vMatrix> LatticeMatrix;
|
||||
typedef Lattice<vMatrixF> LatticeMatrixF;
|
||||
typedef Lattice<vMatrixD> LatticeMatrixD;
|
||||
|
||||
typedef Lattice<vAlgebraVector> LatticeAlgebraVector;
|
||||
typedef Lattice<vAlgebraVectorF> LatticeAlgebraVectorF;
|
||||
typedef Lattice<vAlgebraVectorD> LatticeAlgebraVectorD;
|
||||
|
||||
typedef iSU2Matrix<Complex> SU2Matrix;
|
||||
typedef iSU2Matrix<ComplexF> SU2MatrixF;
|
||||
typedef iSU2Matrix<ComplexD> SU2MatrixD;
|
||||
|
||||
typedef iSU2Matrix<vComplex> vSU2Matrix;
|
||||
typedef iSU2Matrix<vComplexF> vSU2MatrixF;
|
||||
typedef iSU2Matrix<vComplexD> vSU2MatrixD;
|
||||
|
||||
typedef Lattice<vSU2Matrix> LatticeSU2Matrix;
|
||||
typedef Lattice<vSU2MatrixF> LatticeSU2MatrixF;
|
||||
typedef Lattice<vSU2MatrixD> LatticeSU2MatrixD;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// There are N^2-1 generators for SU(N).
|
||||
//
|
||||
// We take a traceless hermitian generator basis as follows
|
||||
//
|
||||
// * Normalisation: trace ta tb = 1/2 delta_ab = T_F delta_ab
|
||||
// T_F = 1/2 for SU(N) groups
|
||||
//
|
||||
// * Off diagonal
|
||||
// - pairs of rows i1,i2 behaving like pauli matrices signma_x, sigma_y
|
||||
//
|
||||
// - there are (Nc-1-i1) slots for i2 on each row [ x 0 x ]
|
||||
// direct count off each row
|
||||
//
|
||||
// - Sum of all pairs is Nc(Nc-1)/2: proof arithmetic series
|
||||
//
|
||||
// (Nc-1) + (Nc-2)+... 1 ==> Nc*(Nc-1)/2
|
||||
// 1+ 2+ + + Nc-1
|
||||
//
|
||||
// - There are 2 x Nc (Nc-1)/ 2 of these = Nc^2 - Nc
|
||||
//
|
||||
// - We enumerate the row-col pairs.
|
||||
// - for each row col pair there is a (sigma_x) and a (sigma_y) like
|
||||
// generator
|
||||
//
|
||||
//
|
||||
// t^a_ij = { in 0.. Nc(Nc-1)/2 -1} => 1/2(delta_{i,i1} delta_{j,i2} +
|
||||
// delta_{i,i1} delta_{j,i2})
|
||||
// t^a_ij = { in Nc(Nc-1)/2 ... Nc(Nc-1) - 1} => i/2( delta_{i,i1}
|
||||
// delta_{j,i2} - i delta_{i,i1} delta_{j,i2})
|
||||
//
|
||||
// * Diagonal; must be traceless and normalised
|
||||
// - Sequence is
|
||||
// N (1,-1,0,0...)
|
||||
// N (1, 1,-2,0...)
|
||||
// N (1, 1, 1,-3,0...)
|
||||
// N (1, 1, 1, 1,-4,0...)
|
||||
//
|
||||
// where 1/2 = N^2 (1+.. m^2)etc.... for the m-th diagonal generator
|
||||
// NB this gives the famous SU3 result for su2 index 8
|
||||
//
|
||||
// N= sqrt(1/2 . 1/6 ) = 1/2 . 1/sqrt(3)
|
||||
//
|
||||
// ( 1 )
|
||||
// ( 1 ) / sqrt(3) /2 = 1/2 lambda_8
|
||||
// ( -2)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
template <class cplx>
|
||||
static void generator(int lieIndex, iSUnMatrix<cplx> &ta) {
|
||||
// map lie index to which type of generator
|
||||
int diagIndex;
|
||||
int su2Index;
|
||||
int sigxy;
|
||||
int NNm1 = ncolour * (ncolour - 1);
|
||||
if (lieIndex >= NNm1) {
|
||||
diagIndex = lieIndex - NNm1;
|
||||
generatorDiagonal(diagIndex, ta);
|
||||
return;
|
||||
}
|
||||
sigxy = lieIndex & 0x1; // even or odd
|
||||
su2Index = lieIndex >> 1;
|
||||
if (sigxy)
|
||||
generatorSigmaY(su2Index, ta);
|
||||
else
|
||||
generatorSigmaX(su2Index, ta);
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void generatorSigmaY(int su2Index, iSUnMatrix<cplx> &ta) {
|
||||
ta = Zero();
|
||||
int i1, i2;
|
||||
su2SubGroupIndex(i1, i2, su2Index);
|
||||
ta()()(i1, i2) = 1.0;
|
||||
ta()()(i2, i1) = 1.0;
|
||||
ta = ta * 0.5;
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void generatorSigmaX(int su2Index, iSUnMatrix<cplx> &ta) {
|
||||
ta = Zero();
|
||||
cplx i(0.0, 1.0);
|
||||
int i1, i2;
|
||||
su2SubGroupIndex(i1, i2, su2Index);
|
||||
ta()()(i1, i2) = i;
|
||||
ta()()(i2, i1) = -i;
|
||||
ta = ta * 0.5;
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void generatorDiagonal(int diagIndex, iSUnMatrix<cplx> &ta) {
|
||||
// diag ({1, 1, ..., 1}(k-times), -k, 0, 0, ...)
|
||||
ta = Zero();
|
||||
int k = diagIndex + 1; // diagIndex starts from 0
|
||||
for (int i = 0; i <= diagIndex; i++) { // k iterations
|
||||
ta()()(i, i) = 1.0;
|
||||
}
|
||||
ta()()(k, k) = -k; // indexing starts from 0
|
||||
RealD nrm = 1.0 / std::sqrt(2.0 * k * (k + 1));
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Map a su2 subgroup number to the pair of rows that are non zero
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
static void su2SubGroupIndex(int &i1, int &i2, int su2_index) {
|
||||
assert((su2_index >= 0) && (su2_index < (ncolour * (ncolour - 1)) / 2));
|
||||
|
||||
int spare = su2_index;
|
||||
for (i1 = 0; spare >= (ncolour - 1 - i1); i1++) {
|
||||
spare = spare - (ncolour - 1 - i1); // remove the Nc-1-i1 terms
|
||||
}
|
||||
i2 = i1 + 1 + spare;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pull out a subgroup and project on to real coeffs x pauli basis
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class vcplx>
|
||||
static void su2Extract(Lattice<iSinglet<vcplx> > &Determinant,
|
||||
Lattice<iSU2Matrix<vcplx> > &subgroup,
|
||||
const Lattice<iSUnMatrix<vcplx> > &source,
|
||||
int su2_index) {
|
||||
GridBase *grid(source.Grid());
|
||||
conformable(subgroup, source);
|
||||
conformable(subgroup, Determinant);
|
||||
int i0, i1;
|
||||
su2SubGroupIndex(i0, i1, su2_index);
|
||||
|
||||
autoView( subgroup_v , subgroup,AcceleratorWrite);
|
||||
autoView( source_v , source,AcceleratorRead);
|
||||
autoView( Determinant_v , Determinant,AcceleratorWrite);
|
||||
accelerator_for(ss, grid->oSites(), 1, {
|
||||
|
||||
subgroup_v[ss]()()(0, 0) = source_v[ss]()()(i0, i0);
|
||||
subgroup_v[ss]()()(0, 1) = source_v[ss]()()(i0, i1);
|
||||
subgroup_v[ss]()()(1, 0) = source_v[ss]()()(i1, i0);
|
||||
subgroup_v[ss]()()(1, 1) = source_v[ss]()()(i1, i1);
|
||||
|
||||
iSU2Matrix<vcplx> Sigma = subgroup_v[ss];
|
||||
|
||||
Sigma = Sigma - adj(Sigma) + trace(adj(Sigma));
|
||||
|
||||
subgroup_v[ss] = Sigma;
|
||||
|
||||
// this should be purely real
|
||||
Determinant_v[ss] =
|
||||
Sigma()()(0, 0) * Sigma()()(1, 1) - Sigma()()(0, 1) * Sigma()()(1, 0);
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set matrix to one and insert a pauli subgroup
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class vcplx>
|
||||
static void su2Insert(const Lattice<iSU2Matrix<vcplx> > &subgroup,
|
||||
Lattice<iSUnMatrix<vcplx> > &dest, int su2_index) {
|
||||
GridBase *grid(dest.Grid());
|
||||
conformable(subgroup, dest);
|
||||
int i0, i1;
|
||||
su2SubGroupIndex(i0, i1, su2_index);
|
||||
|
||||
dest = 1.0; // start out with identity
|
||||
autoView( dest_v , dest, AcceleratorWrite);
|
||||
autoView( subgroup_v, subgroup, AcceleratorRead);
|
||||
accelerator_for(ss, grid->oSites(),1,
|
||||
{
|
||||
dest_v[ss]()()(i0, i0) = subgroup_v[ss]()()(0, 0);
|
||||
dest_v[ss]()()(i0, i1) = subgroup_v[ss]()()(0, 1);
|
||||
dest_v[ss]()()(i1, i0) = subgroup_v[ss]()()(1, 0);
|
||||
dest_v[ss]()()(i1, i1) = subgroup_v[ss]()()(1, 1);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Generate e^{ Re Tr Staple Link} dlink
|
||||
//
|
||||
// *** Note Staple should be appropriate linear compbination between all
|
||||
// staples.
|
||||
// *** If already by beta pass coefficient 1.0.
|
||||
// *** This routine applies the additional 1/Nc factor that comes after trace
|
||||
// in action.
|
||||
//
|
||||
///////////////////////////////////////////////
|
||||
static void SubGroupHeatBath(GridSerialRNG &sRNG, GridParallelRNG &pRNG,
|
||||
RealD beta, // coeff multiplying staple in action (with no 1/Nc)
|
||||
LatticeMatrix &link,
|
||||
const LatticeMatrix &barestaple, // multiplied by action coeffs so th
|
||||
int su2_subgroup, int nheatbath, LatticeInteger &wheremask)
|
||||
{
|
||||
GridBase *grid = link.Grid();
|
||||
|
||||
const RealD twopi = 2.0 * M_PI;
|
||||
|
||||
LatticeMatrix staple(grid);
|
||||
|
||||
staple = barestaple * (beta / ncolour);
|
||||
|
||||
LatticeMatrix V(grid);
|
||||
V = link * staple;
|
||||
|
||||
// Subgroup manipulation in the lie algebra space
|
||||
LatticeSU2Matrix u(grid); // Kennedy pendleton "u" real projected normalised Sigma
|
||||
LatticeSU2Matrix uinv(grid);
|
||||
LatticeSU2Matrix ua(grid); // a in pauli form
|
||||
LatticeSU2Matrix b(grid); // rotated matrix after hb
|
||||
|
||||
// Some handy constant fields
|
||||
LatticeComplex ones(grid);
|
||||
ones = 1.0;
|
||||
LatticeComplex zeros(grid);
|
||||
zeros = Zero();
|
||||
LatticeReal rones(grid);
|
||||
rones = 1.0;
|
||||
LatticeReal rzeros(grid);
|
||||
rzeros = Zero();
|
||||
LatticeComplex udet(grid); // determinant of real(staple)
|
||||
LatticeInteger mask_true(grid);
|
||||
mask_true = 1;
|
||||
LatticeInteger mask_false(grid);
|
||||
mask_false = 0;
|
||||
|
||||
/*
|
||||
PLB 156 P393 (1985) (Kennedy and Pendleton)
|
||||
|
||||
Note: absorb "beta" into the def of sigma compared to KP paper; staple
|
||||
passed to this routine has "beta" already multiplied in
|
||||
|
||||
Action linear in links h and of form:
|
||||
|
||||
beta S = beta Sum_p (1 - 1/Nc Re Tr Plaq )
|
||||
|
||||
Writing Sigma = 1/Nc (beta Sigma') where sum over staples is "Sigma' "
|
||||
|
||||
beta S = const - beta/Nc Re Tr h Sigma'
|
||||
= const - Re Tr h Sigma
|
||||
|
||||
Decompose h and Sigma into (1, sigma_j) ; h_i real, h^2=1, Sigma_i complex
|
||||
arbitrary.
|
||||
|
||||
Tr h Sigma = h_i Sigma_j Tr (sigma_i sigma_j) = h_i Sigma_j 2 delta_ij
|
||||
Re Tr h Sigma = 2 h_j Re Sigma_j
|
||||
|
||||
Normalised re Sigma_j = xi u_j
|
||||
|
||||
With u_j a unit vector and U can be in SU(2);
|
||||
|
||||
Re Tr h Sigma = 2 h_j Re Sigma_j = 2 xi (h.u)
|
||||
|
||||
4xi^2 = Det [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
u = 1/2xi [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
|
||||
xi = sqrt(Det)/2;
|
||||
|
||||
Write a= u h in SU(2); a has pauli decomp a_j;
|
||||
|
||||
Note: Product b' xi is unvariant because scaling Sigma leaves
|
||||
normalised vector "u" fixed; Can rescale Sigma so b' = 1.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Real part of Pauli decomposition
|
||||
// Note a subgroup can project to zero in cold start
|
||||
////////////////////////////////////////////////////////
|
||||
su2Extract(udet, u, V, su2_subgroup);
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Normalising this vector if possible; else identity
|
||||
//////////////////////////////////////////////////////
|
||||
LatticeComplex xi(grid);
|
||||
|
||||
LatticeSU2Matrix lident(grid);
|
||||
|
||||
SU2Matrix ident = Complex(1.0);
|
||||
SU2Matrix pauli1;
|
||||
SU<2>::generator(0, pauli1);
|
||||
SU2Matrix pauli2;
|
||||
SU<2>::generator(1, pauli2);
|
||||
SU2Matrix pauli3;
|
||||
SU<2>::generator(2, pauli3);
|
||||
pauli1 = timesI(pauli1) * 2.0;
|
||||
pauli2 = timesI(pauli2) * 2.0;
|
||||
pauli3 = timesI(pauli3) * 2.0;
|
||||
|
||||
LatticeComplex cone(grid);
|
||||
LatticeReal adet(grid);
|
||||
adet = abs(toReal(udet));
|
||||
lident = Complex(1.0);
|
||||
cone = Complex(1.0);
|
||||
Real machine_epsilon = 1.0e-7;
|
||||
u = where(adet > machine_epsilon, u, lident);
|
||||
udet = where(adet > machine_epsilon, udet, cone);
|
||||
|
||||
xi = 0.5 * sqrt(udet); // 4xi^2 = Det [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
u = 0.5 * u *
|
||||
pow(xi, -1.0); // u = 1/2xi [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
|
||||
// Debug test for sanity
|
||||
uinv = adj(u);
|
||||
b = u * uinv - 1.0;
|
||||
assert(norm2(b) < 1.0e-4);
|
||||
|
||||
/*
|
||||
Measure: Haar measure dh has d^4a delta(1-|a^2|)
|
||||
In polars:
|
||||
da = da0 r^2 sin theta dr dtheta dphi delta( 1 - r^2 -a0^2)
|
||||
= da0 r^2 sin theta dr dtheta dphi delta( (sqrt(1-a0^) - r)(sqrt(1-a0^) +
|
||||
r) )
|
||||
= da0 r/2 sin theta dr dtheta dphi delta( (sqrt(1-a0^) - r) )
|
||||
|
||||
Action factor Q(h) dh = e^-S[h] dh = e^{ xi Tr uh} dh // beta enters
|
||||
through xi
|
||||
= e^{2 xi (h.u)} dh
|
||||
= e^{2 xi h0u0}.e^{2 xi h1u1}.e^{2 xi
|
||||
h2u2}.e^{2 xi h3u3} dh
|
||||
|
||||
Therefore for each site, take xi for that site
|
||||
i) generate |a0|<1 with dist
|
||||
(1-a0^2)^0.5 e^{2 xi a0 } da0
|
||||
|
||||
Take alpha = 2 xi = 2 xi [ recall 2 beta/Nc unmod staple norm]; hence 2.0/Nc
|
||||
factor in Chroma ]
|
||||
A. Generate two uniformly distributed pseudo-random numbers R and R', R'',
|
||||
R''' in the unit interval;
|
||||
B. Set X = -(ln R)/alpha, X' =-(ln R')/alpha;
|
||||
C. Set C = cos^2(2pi R"), with R" another uniform random number in [0,1] ;
|
||||
D. Set A = XC;
|
||||
E. Let d = X'+A;
|
||||
F. If R'''^2 :> 1 - 0.5 d, go back to A;
|
||||
G. Set a0 = 1 - d;
|
||||
|
||||
Note that in step D setting B ~ X - A and using B in place of A in step E will
|
||||
generate a second independent a 0 value.
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// count the number of sites by picking "1"'s out of hat
|
||||
/////////////////////////////////////////////////////////
|
||||
Integer hit = 0;
|
||||
LatticeReal rtmp(grid);
|
||||
rtmp = where(wheremask, rones, rzeros);
|
||||
RealD numSites = sum(rtmp);
|
||||
RealD numAccepted;
|
||||
LatticeInteger Accepted(grid);
|
||||
Accepted = Zero();
|
||||
LatticeInteger newlyAccepted(grid);
|
||||
|
||||
std::vector<LatticeReal> xr(4, grid);
|
||||
std::vector<LatticeReal> a(4, grid);
|
||||
LatticeReal d(grid);
|
||||
d = Zero();
|
||||
LatticeReal alpha(grid);
|
||||
|
||||
// std::cout<<GridLogMessage<<"xi "<<xi <<std::endl;
|
||||
xi = 2.0 *xi;
|
||||
alpha = toReal(xi);
|
||||
|
||||
do {
|
||||
// A. Generate two uniformly distributed pseudo-random numbers R and R',
|
||||
// R'', R''' in the unit interval;
|
||||
random(pRNG, xr[0]);
|
||||
random(pRNG, xr[1]);
|
||||
random(pRNG, xr[2]);
|
||||
random(pRNG, xr[3]);
|
||||
|
||||
// B. Set X = - ln R/alpha, X' = -ln R'/alpha
|
||||
xr[1] = -log(xr[1]) / alpha;
|
||||
xr[2] = -log(xr[2]) / alpha;
|
||||
|
||||
// C. Set C = cos^2(2piR'')
|
||||
xr[3] = cos(xr[3] * twopi);
|
||||
xr[3] = xr[3] * xr[3];
|
||||
|
||||
LatticeReal xrsq(grid);
|
||||
|
||||
// D. Set A = XC;
|
||||
// E. Let d = X'+A;
|
||||
xrsq = xr[2] + xr[1] * xr[3];
|
||||
|
||||
d = where(Accepted, d, xr[2] + xr[1] * xr[3]);
|
||||
|
||||
// F. If R'''^2 :> 1 - 0.5 d, go back to A;
|
||||
LatticeReal thresh(grid);
|
||||
thresh = 1.0 - d * 0.5;
|
||||
xrsq = xr[0] * xr[0];
|
||||
LatticeInteger ione(grid);
|
||||
ione = 1;
|
||||
LatticeInteger izero(grid);
|
||||
izero = Zero();
|
||||
|
||||
newlyAccepted = where(xrsq < thresh, ione, izero);
|
||||
Accepted = where(newlyAccepted, newlyAccepted, Accepted);
|
||||
Accepted = where(wheremask, Accepted, izero);
|
||||
|
||||
// FIXME need an iSum for integer to avoid overload on return type??
|
||||
rtmp = where(Accepted, rones, rzeros);
|
||||
numAccepted = sum(rtmp);
|
||||
|
||||
hit++;
|
||||
|
||||
} while ((numAccepted < numSites) && (hit < nheatbath));
|
||||
|
||||
// G. Set a0 = 1 - d;
|
||||
a[0] = Zero();
|
||||
a[0] = where(wheremask, 1.0 - d, a[0]);
|
||||
|
||||
//////////////////////////////////////////
|
||||
// ii) generate a_i uniform on two sphere radius (1-a0^2)^0.5
|
||||
//////////////////////////////////////////
|
||||
|
||||
LatticeReal a123mag(grid);
|
||||
a123mag = sqrt(abs(1.0 - a[0] * a[0]));
|
||||
|
||||
LatticeReal cos_theta(grid);
|
||||
LatticeReal sin_theta(grid);
|
||||
LatticeReal phi(grid);
|
||||
|
||||
random(pRNG, phi);
|
||||
phi = phi * twopi; // uniform in [0,2pi]
|
||||
random(pRNG, cos_theta);
|
||||
cos_theta = (cos_theta * 2.0) - 1.0; // uniform in [-1,1]
|
||||
sin_theta = sqrt(abs(1.0 - cos_theta * cos_theta));
|
||||
|
||||
a[1] = a123mag * sin_theta * cos(phi);
|
||||
a[2] = a123mag * sin_theta * sin(phi);
|
||||
a[3] = a123mag * cos_theta;
|
||||
|
||||
ua = toComplex(a[0]) * ident + toComplex(a[1]) * pauli1 +
|
||||
toComplex(a[2]) * pauli2 + toComplex(a[3]) * pauli3;
|
||||
|
||||
b = 1.0;
|
||||
b = where(wheremask, uinv * ua, b);
|
||||
su2Insert(b, V, su2_subgroup);
|
||||
|
||||
// mask the assignment back based on Accptance
|
||||
link = where(Accepted, V * link, link);
|
||||
|
||||
//////////////////////////////
|
||||
// Debug Checks
|
||||
// SU2 check
|
||||
LatticeSU2Matrix check(grid); // rotated matrix after hb
|
||||
u = Zero();
|
||||
check = ua * adj(ua) - 1.0;
|
||||
check = where(Accepted, check, u);
|
||||
assert(norm2(check) < 1.0e-4);
|
||||
|
||||
check = b * adj(b) - 1.0;
|
||||
check = where(Accepted, check, u);
|
||||
assert(norm2(check) < 1.0e-4);
|
||||
|
||||
LatticeMatrix Vcheck(grid);
|
||||
Vcheck = Zero();
|
||||
Vcheck = where(Accepted, V * adj(V) - 1.0, Vcheck);
|
||||
// std::cout<<GridLogMessage << "SU3 check " <<norm2(Vcheck)<<std::endl;
|
||||
assert(norm2(Vcheck) < 1.0e-4);
|
||||
|
||||
// Verify the link stays in SU(3)
|
||||
// std::cout<<GridLogMessage <<"Checking the modified link"<<std::endl;
|
||||
Vcheck = link * adj(link) - 1.0;
|
||||
assert(norm2(Vcheck) < 1.0e-4);
|
||||
/////////////////////////////////
|
||||
}
|
||||
|
||||
static void printGenerators(void) {
|
||||
for (int gen = 0; gen < AdjointDimension; gen++) {
|
||||
Matrix ta;
|
||||
generator(gen, ta);
|
||||
std::cout << GridLogMessage << "Nc = " << ncolour << " t_" << gen
|
||||
<< std::endl;
|
||||
std::cout << GridLogMessage << ta << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void testGenerators(void) {
|
||||
Matrix ta;
|
||||
Matrix tb;
|
||||
std::cout << GridLogMessage
|
||||
<< "Fundamental - Checking trace ta tb is 0.5 delta_ab"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
for (int b = 0; b < AdjointDimension; b++) {
|
||||
generator(a, ta);
|
||||
generator(b, tb);
|
||||
Complex tr = TensorRemove(trace(ta * tb));
|
||||
std::cout << GridLogMessage << "(" << a << "," << b << ") = " << tr
|
||||
<< std::endl;
|
||||
if (a == b) assert(abs(tr - Complex(0.5)) < 1.0e-6);
|
||||
if (a != b) assert(abs(tr) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
}
|
||||
std::cout << GridLogMessage << "Fundamental - Checking if hermitian"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
generator(a, ta);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(ta - adj(ta)) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
|
||||
std::cout << GridLogMessage << "Fundamental - Checking if traceless"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
generator(a, ta);
|
||||
Complex tr = TensorRemove(trace(ta));
|
||||
std::cout << GridLogMessage << a << " " << std::endl;
|
||||
assert(abs(tr) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
}
|
||||
|
||||
// reunitarise??
|
||||
template <typename LatticeMatrixType>
|
||||
static void LieRandomize(GridParallelRNG &pRNG, LatticeMatrixType &out, double scale = 1.0)
|
||||
{
|
||||
GridBase *grid = out.Grid();
|
||||
|
||||
typedef typename LatticeMatrixType::vector_type vector_type;
|
||||
|
||||
typedef iSinglet<vector_type> vTComplexType;
|
||||
|
||||
typedef Lattice<vTComplexType> LatticeComplexType;
|
||||
typedef typename GridTypeMapper<typename LatticeMatrixType::vector_object>::scalar_object MatrixType;
|
||||
|
||||
LatticeComplexType ca(grid);
|
||||
LatticeMatrixType lie(grid);
|
||||
LatticeMatrixType la(grid);
|
||||
ComplexD ci(0.0, scale);
|
||||
// ComplexD cone(1.0, 0.0);
|
||||
MatrixType ta;
|
||||
|
||||
lie = Zero();
|
||||
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
random(pRNG, ca);
|
||||
|
||||
ca = (ca + conjugate(ca)) * 0.5;
|
||||
ca = ca - 0.5;
|
||||
|
||||
generator(a, ta);
|
||||
|
||||
la = ci * ca * ta;
|
||||
|
||||
lie = lie + la; // e^{i la ta}
|
||||
|
||||
}
|
||||
taExp(lie, out);
|
||||
}
|
||||
|
||||
static void GaussianFundamentalLieAlgebraMatrix(GridParallelRNG &pRNG,
|
||||
LatticeMatrix &out,
|
||||
Real scale = 1.0) {
|
||||
GridBase *grid = out.Grid();
|
||||
LatticeReal ca(grid);
|
||||
LatticeMatrix la(grid);
|
||||
Complex ci(0.0, scale);
|
||||
Matrix ta;
|
||||
|
||||
out = Zero();
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
gaussian(pRNG, ca);
|
||||
generator(a, ta);
|
||||
la = toComplex(ca) * ta;
|
||||
out += la;
|
||||
}
|
||||
out *= ci;
|
||||
}
|
||||
|
||||
static void FundamentalLieAlgebraMatrix(const LatticeAlgebraVector &h,
|
||||
LatticeMatrix &out,
|
||||
Real scale = 1.0) {
|
||||
conformable(h, out);
|
||||
GridBase *grid = out.Grid();
|
||||
LatticeMatrix la(grid);
|
||||
Matrix ta;
|
||||
|
||||
out = Zero();
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
generator(a, ta);
|
||||
la = peekColour(h, a) * timesI(ta) * scale;
|
||||
out += la;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Fundamental rep gauge xform
|
||||
*/
|
||||
template<typename Fundamental,typename GaugeMat>
|
||||
static void GaugeTransformFundamental( Fundamental &ferm, GaugeMat &g){
|
||||
GridBase *grid = ferm._grid;
|
||||
conformable(grid,g._grid);
|
||||
ferm = g*ferm;
|
||||
}
|
||||
/*
|
||||
* Adjoint rep gauge xform
|
||||
*/
|
||||
|
||||
template<typename Gimpl>
|
||||
static void GaugeTransform(typename Gimpl::GaugeField &Umu, typename Gimpl::GaugeLinkField &g){
|
||||
GridBase *grid = Umu.Grid();
|
||||
conformable(grid,g.Grid());
|
||||
|
||||
typename Gimpl::GaugeLinkField U(grid);
|
||||
typename Gimpl::GaugeLinkField ag(grid); ag = adj(g);
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U= PeekIndex<LorentzIndex>(Umu,mu);
|
||||
U = g*U*Gimpl::CshiftLink(ag, mu, 1); //BC-aware
|
||||
PokeIndex<LorentzIndex>(Umu,U,mu);
|
||||
}
|
||||
}
|
||||
template<typename Gimpl>
|
||||
static void GaugeTransform( std::vector<typename Gimpl::GaugeLinkField> &U, typename Gimpl::GaugeLinkField &g){
|
||||
GridBase *grid = g.Grid();
|
||||
typename Gimpl::GaugeLinkField ag(grid); ag = adj(g);
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U[mu] = g*U[mu]*Gimpl::CshiftLink(ag, mu, 1); //BC-aware
|
||||
}
|
||||
}
|
||||
template<typename Gimpl>
|
||||
static void RandomGaugeTransform(GridParallelRNG &pRNG, typename Gimpl::GaugeField &Umu, typename Gimpl::GaugeLinkField &g){
|
||||
LieRandomize(pRNG,g,1.0);
|
||||
GaugeTransform<Gimpl>(Umu,g);
|
||||
}
|
||||
|
||||
// Projects the algebra components a lattice matrix (of dimension ncol*ncol -1 )
|
||||
// inverse operation: FundamentalLieAlgebraMatrix
|
||||
static void projectOnAlgebra(LatticeAlgebraVector &h_out, const LatticeMatrix &in, Real scale = 1.0) {
|
||||
conformable(h_out, in);
|
||||
h_out = Zero();
|
||||
Matrix Ta;
|
||||
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
generator(a, Ta);
|
||||
pokeColour(h_out, - 2.0 * (trace(timesI(Ta) * in)) * scale, a);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename GaugeField>
|
||||
static void HotConfiguration(GridParallelRNG &pRNG, GaugeField &out) {
|
||||
typedef typename GaugeField::vector_type vector_type;
|
||||
typedef iSUnMatrix<vector_type> vMatrixType;
|
||||
typedef Lattice<vMatrixType> LatticeMatrixType;
|
||||
|
||||
LatticeMatrixType Umu(out.Grid());
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
LieRandomize(pRNG, Umu, 1.0);
|
||||
PokeIndex<LorentzIndex>(out, Umu, mu);
|
||||
}
|
||||
}
|
||||
template<typename GaugeField>
|
||||
static void TepidConfiguration(GridParallelRNG &pRNG,GaugeField &out){
|
||||
typedef typename GaugeField::vector_type vector_type;
|
||||
typedef iSUnMatrix<vector_type> vMatrixType;
|
||||
typedef Lattice<vMatrixType> LatticeMatrixType;
|
||||
|
||||
LatticeMatrixType Umu(out.Grid());
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
LieRandomize(pRNG,Umu,0.01);
|
||||
PokeIndex<LorentzIndex>(out,Umu,mu);
|
||||
}
|
||||
}
|
||||
template<typename GaugeField>
|
||||
static void ColdConfiguration(GaugeField &out){
|
||||
typedef typename GaugeField::vector_type vector_type;
|
||||
typedef iSUnMatrix<vector_type> vMatrixType;
|
||||
typedef Lattice<vMatrixType> LatticeMatrixType;
|
||||
|
||||
LatticeMatrixType Umu(out.Grid());
|
||||
Umu=1.0;
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
PokeIndex<LorentzIndex>(out,Umu,mu);
|
||||
}
|
||||
}
|
||||
template<typename GaugeField>
|
||||
static void ColdConfiguration(GridParallelRNG &pRNG,GaugeField &out){
|
||||
ColdConfiguration(out);
|
||||
}
|
||||
|
||||
template<typename LatticeMatrixType>
|
||||
static void taProj( const LatticeMatrixType &in, LatticeMatrixType &out){
|
||||
out = Ta(in);
|
||||
}
|
||||
template <typename LatticeMatrixType>
|
||||
static void taExp(const LatticeMatrixType &x, LatticeMatrixType &ex) {
|
||||
typedef typename LatticeMatrixType::scalar_type ComplexType;
|
||||
|
||||
LatticeMatrixType xn(x.Grid());
|
||||
RealD nfac = 1.0;
|
||||
|
||||
xn = x;
|
||||
ex = xn + ComplexType(1.0); // 1+x
|
||||
|
||||
// Do a 12th order exponentiation
|
||||
for (int i = 2; i <= 12; ++i) {
|
||||
nfac = nfac / RealD(i); // 1/2, 1/2.3 ...
|
||||
xn = xn * x; // x2, x3,x4....
|
||||
ex = ex + xn * nfac; // x2/2!, x3/3!....
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<int N>
|
||||
LatticeComplexD Determinant(const Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > &Umu)
|
||||
{
|
||||
GridBase *grid=Umu.Grid();
|
||||
auto lvol = grid->lSites();
|
||||
LatticeComplexD ret(grid);
|
||||
|
||||
autoView(Umu_v,Umu,CpuRead);
|
||||
autoView(ret_v,ret,CpuWrite);
|
||||
thread_for(site,lvol,{
|
||||
Eigen::MatrixXcd EigenU = Eigen::MatrixXcd::Zero(N,N);
|
||||
Coordinate lcoor;
|
||||
grid->LocalIndexToLocalCoor(site, lcoor);
|
||||
iScalar<iScalar<iMatrix<ComplexD, N> > > Us;
|
||||
peekLocalSite(Us, Umu_v, lcoor);
|
||||
for(int i=0;i<N;i++){
|
||||
for(int j=0;j<N;j++){
|
||||
EigenU(i,j) = Us()()(i,j);
|
||||
}}
|
||||
ComplexD det = EigenU.determinant();
|
||||
pokeLocalSite(det,ret_v,lcoor);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
template<int N>
|
||||
static void ProjectSUn(Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > &Umu)
|
||||
{
|
||||
Umu = ProjectOnGroup(Umu);
|
||||
auto det = Determinant(Umu);
|
||||
|
||||
det = conjugate(det);
|
||||
|
||||
for(int i=0;i<N;i++){
|
||||
auto element = PeekIndex<ColourIndex>(Umu,N-1,i);
|
||||
element = element * det;
|
||||
PokeIndex<ColourIndex>(Umu,element,Nc-1,i);
|
||||
}
|
||||
}
|
||||
template<int N>
|
||||
static void ProjectSUn(Lattice<iVector<iScalar<iMatrix<vComplexD, N> >,Nd> > &U)
|
||||
{
|
||||
GridBase *grid=U.Grid();
|
||||
// Reunitarise
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
auto Umu = PeekIndex<LorentzIndex>(U,mu);
|
||||
Umu = ProjectOnGroup(Umu);
|
||||
ProjectSUn(Umu);
|
||||
PokeIndex<LorentzIndex>(U,Umu,mu);
|
||||
}
|
||||
}
|
||||
// Explicit specialisation for SU(3).
|
||||
// Explicit specialisation for SU(3).
|
||||
static void
|
||||
ProjectSU3 (Lattice<iScalar<iScalar<iMatrix<vComplexD, 3> > > > &Umu)
|
||||
{
|
||||
GridBase *grid=Umu.Grid();
|
||||
const int x=0;
|
||||
const int y=1;
|
||||
const int z=2;
|
||||
// Reunitarise
|
||||
Umu = ProjectOnGroup(Umu);
|
||||
autoView(Umu_v,Umu,CpuWrite);
|
||||
thread_for(ss,grid->oSites(),{
|
||||
auto cm = Umu_v[ss];
|
||||
cm()()(2,x) = adj(cm()()(0,y)*cm()()(1,z)-cm()()(0,z)*cm()()(1,y)); //x= yz-zy
|
||||
cm()()(2,y) = adj(cm()()(0,z)*cm()()(1,x)-cm()()(0,x)*cm()()(1,z)); //y= zx-xz
|
||||
cm()()(2,z) = adj(cm()()(0,x)*cm()()(1,y)-cm()()(0,y)*cm()()(1,x)); //z= xy-yx
|
||||
Umu_v[ss]=cm;
|
||||
});
|
||||
}
|
||||
static void ProjectSU3(Lattice<iVector<iScalar<iMatrix<vComplexD, 3> >,Nd> > &U)
|
||||
{
|
||||
GridBase *grid=U.Grid();
|
||||
// Reunitarise
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
auto Umu = PeekIndex<LorentzIndex>(U,mu);
|
||||
Umu = ProjectOnGroup(Umu);
|
||||
ProjectSU3(Umu);
|
||||
PokeIndex<LorentzIndex>(U,Umu,mu);
|
||||
}
|
||||
}
|
||||
|
||||
typedef SU<2> SU2;
|
||||
typedef SU<3> SU3;
|
||||
typedef SU<4> SU4;
|
||||
typedef SU<5> SU5;
|
||||
|
||||
|
||||
typedef SU<Nc> FundamentalMatrices;
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
#endif
|
578
Grid/qcd/utils/SUn.impl.h
Normal file
578
Grid/qcd/utils/SUn.impl.h
Normal file
@ -0,0 +1,578 @@
|
||||
// This file is #included into the body of the class template definition of
|
||||
// GaugeGroup. So, image there to be
|
||||
//
|
||||
// template <int ncolour, class group_name>
|
||||
// class GaugeGroup {
|
||||
//
|
||||
// around it.
|
||||
//
|
||||
// Please note that the unconventional file extension makes sure that it
|
||||
// doesn't get found by the scripts/filelist during bootstrapping.
|
||||
|
||||
private:
|
||||
template <ONLY_IF_SU>
|
||||
static int su2subgroups(GroupName::SU) { return (ncolour * (ncolour - 1)) / 2; }
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// There are N^2-1 generators for SU(N).
|
||||
//
|
||||
// We take a traceless hermitian generator basis as follows
|
||||
//
|
||||
// * Normalisation: trace ta tb = 1/2 delta_ab = T_F delta_ab
|
||||
// T_F = 1/2 for SU(N) groups
|
||||
//
|
||||
// * Off diagonal
|
||||
// - pairs of rows i1,i2 behaving like pauli matrices signma_x, sigma_y
|
||||
//
|
||||
// - there are (Nc-1-i1) slots for i2 on each row [ x 0 x ]
|
||||
// direct count off each row
|
||||
//
|
||||
// - Sum of all pairs is Nc(Nc-1)/2: proof arithmetic series
|
||||
//
|
||||
// (Nc-1) + (Nc-2)+... 1 ==> Nc*(Nc-1)/2
|
||||
// 1+ 2+ + + Nc-1
|
||||
//
|
||||
// - There are 2 x Nc (Nc-1)/ 2 of these = Nc^2 - Nc
|
||||
//
|
||||
// - We enumerate the row-col pairs.
|
||||
// - for each row col pair there is a (sigma_x) and a (sigma_y) like
|
||||
// generator
|
||||
//
|
||||
//
|
||||
// t^a_ij = { in 0.. Nc(Nc-1)/2 -1} => 1/2(delta_{i,i1} delta_{j,i2} +
|
||||
// delta_{i,i1} delta_{j,i2})
|
||||
// t^a_ij = { in Nc(Nc-1)/2 ... Nc(Nc-1) - 1} => i/2( delta_{i,i1}
|
||||
// delta_{j,i2} - i delta_{i,i1} delta_{j,i2})
|
||||
//
|
||||
// * Diagonal; must be traceless and normalised
|
||||
// - Sequence is
|
||||
// N (1,-1,0,0...)
|
||||
// N (1, 1,-2,0...)
|
||||
// N (1, 1, 1,-3,0...)
|
||||
// N (1, 1, 1, 1,-4,0...)
|
||||
//
|
||||
// where 1/2 = N^2 (1+.. m^2)etc.... for the m-th diagonal generator
|
||||
// NB this gives the famous SU3 result for su2 index 8
|
||||
//
|
||||
// N= sqrt(1/2 . 1/6 ) = 1/2 . 1/sqrt(3)
|
||||
//
|
||||
// ( 1 )
|
||||
// ( 1 ) / sqrt(3) /2 = 1/2 lambda_8
|
||||
// ( -2)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
template <class cplx, ONLY_IF_SU>
|
||||
static void generator(int lieIndex, iGroupMatrix<cplx> &ta, GroupName::SU) {
|
||||
// map lie index to which type of generator
|
||||
int diagIndex;
|
||||
int su2Index;
|
||||
int sigxy;
|
||||
int NNm1 = ncolour * (ncolour - 1);
|
||||
if (lieIndex >= NNm1) {
|
||||
diagIndex = lieIndex - NNm1;
|
||||
generatorDiagonal(diagIndex, ta);
|
||||
return;
|
||||
}
|
||||
sigxy = lieIndex & 0x1; // even or odd
|
||||
su2Index = lieIndex >> 1;
|
||||
if (sigxy)
|
||||
generatorSigmaY(su2Index, ta);
|
||||
else
|
||||
generatorSigmaX(su2Index, ta);
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_SU>
|
||||
static void generatorSigmaY(int su2Index, iGroupMatrix<cplx> &ta) {
|
||||
ta = Zero();
|
||||
int i1, i2;
|
||||
su2SubGroupIndex(i1, i2, su2Index);
|
||||
ta()()(i1, i2) = 1.0;
|
||||
ta()()(i2, i1) = 1.0;
|
||||
ta = ta * 0.5;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_SU>
|
||||
static void generatorSigmaX(int su2Index, iGroupMatrix<cplx> &ta) {
|
||||
ta = Zero();
|
||||
cplx i(0.0, 1.0);
|
||||
int i1, i2;
|
||||
su2SubGroupIndex(i1, i2, su2Index);
|
||||
ta()()(i1, i2) = i;
|
||||
ta()()(i2, i1) = -i;
|
||||
ta = ta * 0.5;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_SU>
|
||||
static void generatorDiagonal(int diagIndex, iGroupMatrix<cplx> &ta) {
|
||||
// diag ({1, 1, ..., 1}(k-times), -k, 0, 0, ...)
|
||||
ta = Zero();
|
||||
int k = diagIndex + 1; // diagIndex starts from 0
|
||||
for (int i = 0; i <= diagIndex; i++) { // k iterations
|
||||
ta()()(i, i) = 1.0;
|
||||
}
|
||||
ta()()(k, k) = -k; // indexing starts from 0
|
||||
RealD nrm = 1.0 / std::sqrt(2.0 * k * (k + 1));
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Map a su2 subgroup number to the pair of rows that are non zero
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
static void su2SubGroupIndex(int &i1, int &i2, int su2_index, GroupName::SU) {
|
||||
assert((su2_index >= 0) && (su2_index < (ncolour * (ncolour - 1)) / 2));
|
||||
|
||||
int spare = su2_index;
|
||||
for (i1 = 0; spare >= (ncolour - 1 - i1); i1++) {
|
||||
spare = spare - (ncolour - 1 - i1); // remove the Nc-1-i1 terms
|
||||
}
|
||||
i2 = i1 + 1 + spare;
|
||||
}
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pull out a subgroup and project on to real coeffs x pauli basis
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class vcplx, ONLY_IF_SU>
|
||||
static void su2Extract(Lattice<iSinglet<vcplx> > &Determinant,
|
||||
Lattice<iSU2Matrix<vcplx> > &subgroup,
|
||||
const Lattice<iGroupMatrix<vcplx> > &source,
|
||||
int su2_index) {
|
||||
GridBase *grid(source.Grid());
|
||||
conformable(subgroup, source);
|
||||
conformable(subgroup, Determinant);
|
||||
int i0, i1;
|
||||
su2SubGroupIndex(i0, i1, su2_index);
|
||||
|
||||
autoView(subgroup_v, subgroup, AcceleratorWrite);
|
||||
autoView(source_v, source, AcceleratorRead);
|
||||
autoView(Determinant_v, Determinant, AcceleratorWrite);
|
||||
accelerator_for(ss, grid->oSites(), 1, {
|
||||
subgroup_v[ss]()()(0, 0) = source_v[ss]()()(i0, i0);
|
||||
subgroup_v[ss]()()(0, 1) = source_v[ss]()()(i0, i1);
|
||||
subgroup_v[ss]()()(1, 0) = source_v[ss]()()(i1, i0);
|
||||
subgroup_v[ss]()()(1, 1) = source_v[ss]()()(i1, i1);
|
||||
|
||||
iSU2Matrix<vcplx> Sigma = subgroup_v[ss];
|
||||
|
||||
Sigma = Sigma - adj(Sigma) + trace(adj(Sigma));
|
||||
|
||||
subgroup_v[ss] = Sigma;
|
||||
|
||||
// this should be purely real
|
||||
Determinant_v[ss] =
|
||||
Sigma()()(0, 0) * Sigma()()(1, 1) - Sigma()()(0, 1) * Sigma()()(1, 0);
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set matrix to one and insert a pauli subgroup
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class vcplx, ONLY_IF_SU>
|
||||
static void su2Insert(const Lattice<iSU2Matrix<vcplx> > &subgroup,
|
||||
Lattice<iGroupMatrix<vcplx> > &dest, int su2_index) {
|
||||
GridBase *grid(dest.Grid());
|
||||
conformable(subgroup, dest);
|
||||
int i0, i1;
|
||||
su2SubGroupIndex(i0, i1, su2_index);
|
||||
|
||||
dest = 1.0; // start out with identity
|
||||
autoView(dest_v, dest, AcceleratorWrite);
|
||||
autoView(subgroup_v, subgroup, AcceleratorRead);
|
||||
accelerator_for(ss, grid->oSites(), 1, {
|
||||
dest_v[ss]()()(i0, i0) = subgroup_v[ss]()()(0, 0);
|
||||
dest_v[ss]()()(i0, i1) = subgroup_v[ss]()()(0, 1);
|
||||
dest_v[ss]()()(i1, i0) = subgroup_v[ss]()()(1, 0);
|
||||
dest_v[ss]()()(i1, i1) = subgroup_v[ss]()()(1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Generate e^{ Re Tr Staple Link} dlink
|
||||
//
|
||||
// *** Note Staple should be appropriate linear compbination between all
|
||||
// staples.
|
||||
// *** If already by beta pass coefficient 1.0.
|
||||
// *** This routine applies the additional 1/Nc factor that comes after trace
|
||||
// in action.
|
||||
//
|
||||
///////////////////////////////////////////////
|
||||
template <ONLY_IF_SU>
|
||||
static void SubGroupHeatBath(
|
||||
GridSerialRNG &sRNG, GridParallelRNG &pRNG,
|
||||
RealD beta, // coeff multiplying staple in action (with no 1/Nc)
|
||||
LatticeMatrix &link,
|
||||
const LatticeMatrix &barestaple, // multiplied by action coeffs so th
|
||||
int su2_subgroup, int nheatbath, LatticeInteger &wheremask) {
|
||||
GridBase *grid = link.Grid();
|
||||
|
||||
const RealD twopi = 2.0 * M_PI;
|
||||
|
||||
LatticeMatrix staple(grid);
|
||||
|
||||
staple = barestaple * (beta / ncolour);
|
||||
|
||||
LatticeMatrix V(grid);
|
||||
V = link * staple;
|
||||
|
||||
// Subgroup manipulation in the lie algebra space
|
||||
LatticeSU2Matrix u(
|
||||
grid); // Kennedy pendleton "u" real projected normalised Sigma
|
||||
LatticeSU2Matrix uinv(grid);
|
||||
LatticeSU2Matrix ua(grid); // a in pauli form
|
||||
LatticeSU2Matrix b(grid); // rotated matrix after hb
|
||||
|
||||
// Some handy constant fields
|
||||
LatticeComplex ones(grid);
|
||||
ones = 1.0;
|
||||
LatticeComplex zeros(grid);
|
||||
zeros = Zero();
|
||||
LatticeReal rones(grid);
|
||||
rones = 1.0;
|
||||
LatticeReal rzeros(grid);
|
||||
rzeros = Zero();
|
||||
LatticeComplex udet(grid); // determinant of real(staple)
|
||||
LatticeInteger mask_true(grid);
|
||||
mask_true = 1;
|
||||
LatticeInteger mask_false(grid);
|
||||
mask_false = 0;
|
||||
|
||||
/*
|
||||
PLB 156 P393 (1985) (Kennedy and Pendleton)
|
||||
|
||||
Note: absorb "beta" into the def of sigma compared to KP paper; staple
|
||||
passed to this routine has "beta" already multiplied in
|
||||
|
||||
Action linear in links h and of form:
|
||||
|
||||
beta S = beta Sum_p (1 - 1/Nc Re Tr Plaq )
|
||||
|
||||
Writing Sigma = 1/Nc (beta Sigma') where sum over staples is "Sigma' "
|
||||
|
||||
beta S = const - beta/Nc Re Tr h Sigma'
|
||||
= const - Re Tr h Sigma
|
||||
|
||||
Decompose h and Sigma into (1, sigma_j) ; h_i real, h^2=1, Sigma_i complex
|
||||
arbitrary.
|
||||
|
||||
Tr h Sigma = h_i Sigma_j Tr (sigma_i sigma_j) = h_i Sigma_j 2 delta_ij
|
||||
Re Tr h Sigma = 2 h_j Re Sigma_j
|
||||
|
||||
Normalised re Sigma_j = xi u_j
|
||||
|
||||
With u_j a unit vector and U can be in SU(2);
|
||||
|
||||
Re Tr h Sigma = 2 h_j Re Sigma_j = 2 xi (h.u)
|
||||
|
||||
4xi^2 = Det [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
u = 1/2xi [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
|
||||
xi = sqrt(Det)/2;
|
||||
|
||||
Write a= u h in SU(2); a has pauli decomp a_j;
|
||||
|
||||
Note: Product b' xi is unvariant because scaling Sigma leaves
|
||||
normalised vector "u" fixed; Can rescale Sigma so b' = 1.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Real part of Pauli decomposition
|
||||
// Note a subgroup can project to zero in cold start
|
||||
////////////////////////////////////////////////////////
|
||||
su2Extract(udet, u, V, su2_subgroup);
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Normalising this vector if possible; else identity
|
||||
//////////////////////////////////////////////////////
|
||||
LatticeComplex xi(grid);
|
||||
|
||||
LatticeSU2Matrix lident(grid);
|
||||
|
||||
SU2Matrix ident = Complex(1.0);
|
||||
SU2Matrix pauli1;
|
||||
GaugeGroup<2, GroupName::SU>::generator(0, pauli1);
|
||||
SU2Matrix pauli2;
|
||||
GaugeGroup<2, GroupName::SU>::generator(1, pauli2);
|
||||
SU2Matrix pauli3;
|
||||
GaugeGroup<2, GroupName::SU>::generator(2, pauli3);
|
||||
pauli1 = timesI(pauli1) * 2.0;
|
||||
pauli2 = timesI(pauli2) * 2.0;
|
||||
pauli3 = timesI(pauli3) * 2.0;
|
||||
|
||||
LatticeComplex cone(grid);
|
||||
LatticeReal adet(grid);
|
||||
adet = abs(toReal(udet));
|
||||
lident = Complex(1.0);
|
||||
cone = Complex(1.0);
|
||||
Real machine_epsilon = 1.0e-7;
|
||||
u = where(adet > machine_epsilon, u, lident);
|
||||
udet = where(adet > machine_epsilon, udet, cone);
|
||||
|
||||
xi = 0.5 * sqrt(udet); // 4xi^2 = Det [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
u = 0.5 * u * pow(xi, -1.0); // u = 1/2xi [ Sig - Sig^dag + 1 Tr Sigdag]
|
||||
|
||||
// Debug test for sanity
|
||||
uinv = adj(u);
|
||||
b = u * uinv - 1.0;
|
||||
assert(norm2(b) < 1.0e-4);
|
||||
|
||||
/*
|
||||
Measure: Haar measure dh has d^4a delta(1-|a^2|)
|
||||
In polars:
|
||||
da = da0 r^2 sin theta dr dtheta dphi delta( 1 - r^2 -a0^2)
|
||||
= da0 r^2 sin theta dr dtheta dphi delta( (sqrt(1-a0^) - r)(sqrt(1-a0^) +
|
||||
r) )
|
||||
= da0 r/2 sin theta dr dtheta dphi delta( (sqrt(1-a0^) - r) )
|
||||
|
||||
Action factor Q(h) dh = e^-S[h] dh = e^{ xi Tr uh} dh // beta
|
||||
enters through xi = e^{2 xi (h.u)} dh = e^{2 xi h0u0}.e^{2 xi h1u1}.e^{2
|
||||
xi h2u2}.e^{2 xi h3u3} dh
|
||||
|
||||
Therefore for each site, take xi for that site
|
||||
i) generate |a0|<1 with dist
|
||||
(1-a0^2)^0.5 e^{2 xi a0 } da0
|
||||
|
||||
Take alpha = 2 xi = 2 xi [ recall 2 beta/Nc unmod staple norm];
|
||||
hence 2.0/Nc factor in Chroma ] A. Generate two uniformly distributed
|
||||
pseudo-random numbers R and R', R'', R''' in the unit interval; B. Set X =
|
||||
-(ln R)/alpha, X' =-(ln R')/alpha; C. Set C = cos^2(2pi R"), with R"
|
||||
another uniform random number in [0,1] ; D. Set A = XC; E. Let d = X'+A;
|
||||
F. If R'''^2 :> 1 - 0.5 d, go back to A;
|
||||
G. Set a0 = 1 - d;
|
||||
|
||||
Note that in step D setting B ~ X - A and using B in place of A in step E
|
||||
will generate a second independent a 0 value.
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// count the number of sites by picking "1"'s out of hat
|
||||
/////////////////////////////////////////////////////////
|
||||
Integer hit = 0;
|
||||
LatticeReal rtmp(grid);
|
||||
rtmp = where(wheremask, rones, rzeros);
|
||||
RealD numSites = sum(rtmp);
|
||||
RealD numAccepted;
|
||||
LatticeInteger Accepted(grid);
|
||||
Accepted = Zero();
|
||||
LatticeInteger newlyAccepted(grid);
|
||||
|
||||
std::vector<LatticeReal> xr(4, grid);
|
||||
std::vector<LatticeReal> a(4, grid);
|
||||
LatticeReal d(grid);
|
||||
d = Zero();
|
||||
LatticeReal alpha(grid);
|
||||
|
||||
// std::cout<<GridLogMessage<<"xi "<<xi <<std::endl;
|
||||
xi = 2.0 * xi;
|
||||
alpha = toReal(xi);
|
||||
|
||||
do {
|
||||
// A. Generate two uniformly distributed pseudo-random numbers R and R',
|
||||
// R'', R''' in the unit interval;
|
||||
random(pRNG, xr[0]);
|
||||
random(pRNG, xr[1]);
|
||||
random(pRNG, xr[2]);
|
||||
random(pRNG, xr[3]);
|
||||
|
||||
// B. Set X = - ln R/alpha, X' = -ln R'/alpha
|
||||
xr[1] = -log(xr[1]) / alpha;
|
||||
xr[2] = -log(xr[2]) / alpha;
|
||||
|
||||
// C. Set C = cos^2(2piR'')
|
||||
xr[3] = cos(xr[3] * twopi);
|
||||
xr[3] = xr[3] * xr[3];
|
||||
|
||||
LatticeReal xrsq(grid);
|
||||
|
||||
// D. Set A = XC;
|
||||
// E. Let d = X'+A;
|
||||
xrsq = xr[2] + xr[1] * xr[3];
|
||||
|
||||
d = where(Accepted, d, xr[2] + xr[1] * xr[3]);
|
||||
|
||||
// F. If R'''^2 :> 1 - 0.5 d, go back to A;
|
||||
LatticeReal thresh(grid);
|
||||
thresh = 1.0 - d * 0.5;
|
||||
xrsq = xr[0] * xr[0];
|
||||
LatticeInteger ione(grid);
|
||||
ione = 1;
|
||||
LatticeInteger izero(grid);
|
||||
izero = Zero();
|
||||
|
||||
newlyAccepted = where(xrsq < thresh, ione, izero);
|
||||
Accepted = where(newlyAccepted, newlyAccepted, Accepted);
|
||||
Accepted = where(wheremask, Accepted, izero);
|
||||
|
||||
// FIXME need an iSum for integer to avoid overload on return type??
|
||||
rtmp = where(Accepted, rones, rzeros);
|
||||
numAccepted = sum(rtmp);
|
||||
|
||||
hit++;
|
||||
|
||||
} while ((numAccepted < numSites) && (hit < nheatbath));
|
||||
|
||||
// G. Set a0 = 1 - d;
|
||||
a[0] = Zero();
|
||||
a[0] = where(wheremask, 1.0 - d, a[0]);
|
||||
|
||||
//////////////////////////////////////////
|
||||
// ii) generate a_i uniform on two sphere radius (1-a0^2)^0.5
|
||||
//////////////////////////////////////////
|
||||
|
||||
LatticeReal a123mag(grid);
|
||||
a123mag = sqrt(abs(1.0 - a[0] * a[0]));
|
||||
|
||||
LatticeReal cos_theta(grid);
|
||||
LatticeReal sin_theta(grid);
|
||||
LatticeReal phi(grid);
|
||||
|
||||
random(pRNG, phi);
|
||||
phi = phi * twopi; // uniform in [0,2pi]
|
||||
random(pRNG, cos_theta);
|
||||
cos_theta = (cos_theta * 2.0) - 1.0; // uniform in [-1,1]
|
||||
sin_theta = sqrt(abs(1.0 - cos_theta * cos_theta));
|
||||
|
||||
a[1] = a123mag * sin_theta * cos(phi);
|
||||
a[2] = a123mag * sin_theta * sin(phi);
|
||||
a[3] = a123mag * cos_theta;
|
||||
|
||||
ua = toComplex(a[0]) * ident + toComplex(a[1]) * pauli1 +
|
||||
toComplex(a[2]) * pauli2 + toComplex(a[3]) * pauli3;
|
||||
|
||||
b = 1.0;
|
||||
b = where(wheremask, uinv * ua, b);
|
||||
su2Insert(b, V, su2_subgroup);
|
||||
|
||||
// mask the assignment back based on Accptance
|
||||
link = where(Accepted, V * link, link);
|
||||
|
||||
//////////////////////////////
|
||||
// Debug Checks
|
||||
// SU2 check
|
||||
LatticeSU2Matrix check(grid); // rotated matrix after hb
|
||||
u = Zero();
|
||||
check = ua * adj(ua) - 1.0;
|
||||
check = where(Accepted, check, u);
|
||||
assert(norm2(check) < 1.0e-4);
|
||||
|
||||
check = b * adj(b) - 1.0;
|
||||
check = where(Accepted, check, u);
|
||||
assert(norm2(check) < 1.0e-4);
|
||||
|
||||
LatticeMatrix Vcheck(grid);
|
||||
Vcheck = Zero();
|
||||
Vcheck = where(Accepted, V * adj(V) - 1.0, Vcheck);
|
||||
// std::cout<<GridLogMessage << "SU3 check " <<norm2(Vcheck)<<std::endl;
|
||||
assert(norm2(Vcheck) < 1.0e-4);
|
||||
|
||||
// Verify the link stays in SU(3)
|
||||
// std::cout<<GridLogMessage <<"Checking the modified link"<<std::endl;
|
||||
Vcheck = link * adj(link) - 1.0;
|
||||
assert(norm2(Vcheck) < 1.0e-4);
|
||||
/////////////////////////////////
|
||||
}
|
||||
|
||||
template <ONLY_IF_SU>
|
||||
static void testGenerators(GroupName::SU) {
|
||||
Matrix ta;
|
||||
Matrix tb;
|
||||
std::cout << GridLogMessage
|
||||
<< "Fundamental - Checking trace ta tb is 0.5 delta_ab"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
for (int b = 0; b < AdjointDimension; b++) {
|
||||
generator(a, ta);
|
||||
generator(b, tb);
|
||||
Complex tr = TensorRemove(trace(ta * tb));
|
||||
std::cout << GridLogMessage << "(" << a << "," << b << ") = " << tr
|
||||
<< std::endl;
|
||||
if (a == b) assert(abs(tr - Complex(0.5)) < 1.0e-6);
|
||||
if (a != b) assert(abs(tr) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
}
|
||||
std::cout << GridLogMessage << "Fundamental - Checking if hermitian"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
generator(a, ta);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(ta - adj(ta)) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
|
||||
std::cout << GridLogMessage << "Fundamental - Checking if traceless"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AdjointDimension; a++) {
|
||||
generator(a, ta);
|
||||
Complex tr = TensorRemove(trace(ta));
|
||||
std::cout << GridLogMessage << a << " " << std::endl;
|
||||
assert(abs(tr) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
}
|
||||
|
||||
|
||||
template <int N, class vtype>
|
||||
static Lattice<iScalar<iScalar<iMatrix<vtype, N> > > >
|
||||
ProjectOnGeneralGroup(const Lattice<iScalar<iScalar<iMatrix<vtype, N> > > > &Umu, GroupName::SU) {
|
||||
return ProjectOnGroup(Umu);
|
||||
}
|
||||
|
||||
template <class vtype>
|
||||
accelerator_inline static iScalar<vtype> ProjectOnGeneralGroup(const iScalar<vtype> &r, GroupName::SU) {
|
||||
return ProjectOnGroup(r);
|
||||
}
|
||||
|
||||
template <class vtype, int N>
|
||||
accelerator_inline static iVector<vtype,N> ProjectOnGeneralGroup(const iVector<vtype,N> &r, GroupName::SU) {
|
||||
return ProjectOnGroup(r);
|
||||
}
|
||||
|
||||
template <class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
accelerator_inline static iMatrix<vtype,N> ProjectOnGeneralGroup(const iMatrix<vtype,N> &arg, GroupName::SU) {
|
||||
return ProjectOnGroup(arg);
|
||||
}
|
||||
|
||||
template <typename LatticeMatrixType>
|
||||
static void taProj(const LatticeMatrixType &in, LatticeMatrixType &out, GroupName::SU) {
|
||||
out = Ta(in);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fundamental rep gauge xform
|
||||
*/
|
||||
template<typename Fundamental,typename GaugeMat>
|
||||
static void GaugeTransformFundamental( Fundamental &ferm, GaugeMat &g){
|
||||
GridBase *grid = ferm._grid;
|
||||
conformable(grid,g._grid);
|
||||
ferm = g*ferm;
|
||||
}
|
||||
/*
|
||||
* Adjoint rep gauge xform
|
||||
*/
|
||||
|
||||
template<typename Gimpl>
|
||||
static void GaugeTransform(typename Gimpl::GaugeField &Umu, typename Gimpl::GaugeLinkField &g){
|
||||
GridBase *grid = Umu.Grid();
|
||||
conformable(grid,g.Grid());
|
||||
|
||||
typename Gimpl::GaugeLinkField U(grid);
|
||||
typename Gimpl::GaugeLinkField ag(grid); ag = adj(g);
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U= PeekIndex<LorentzIndex>(Umu,mu);
|
||||
U = g*U*Gimpl::CshiftLink(ag, mu, 1); //BC-aware
|
||||
PokeIndex<LorentzIndex>(Umu,U,mu);
|
||||
}
|
||||
}
|
||||
template<typename Gimpl>
|
||||
static void GaugeTransform( std::vector<typename Gimpl::GaugeLinkField> &U, typename Gimpl::GaugeLinkField &g){
|
||||
GridBase *grid = g.Grid();
|
||||
typename Gimpl::GaugeLinkField ag(grid); ag = adj(g);
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U[mu] = g*U[mu]*Gimpl::CshiftLink(ag, mu, 1); //BC-aware
|
||||
}
|
||||
}
|
||||
template<typename Gimpl>
|
||||
static void RandomGaugeTransform(GridParallelRNG &pRNG, typename Gimpl::GaugeField &Umu, typename Gimpl::GaugeLinkField &g){
|
||||
LieRandomize(pRNG,g,1.0);
|
||||
GaugeTransform<Gimpl>(Umu,g);
|
||||
}
|
@ -52,13 +52,18 @@ public:
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplexD, Dimension> >, Nd> > LatticeAdjFieldD;
|
||||
|
||||
|
||||
template <typename vtype>
|
||||
using iSUnMatrix = iScalar<iScalar<iMatrix<vtype, ncolour> > >;
|
||||
|
||||
typedef Lattice<iScalar<iScalar<iVector<vComplex, Dimension> > > > LatticeAdjVector;
|
||||
|
||||
template <class cplx>
|
||||
static void generator(int Index, iSUnAdjointMatrix<cplx> &iAdjTa) {
|
||||
// returns i(T_Adj)^index necessary for the projectors
|
||||
// see definitions above
|
||||
iAdjTa = Zero();
|
||||
Vector<typename SU<ncolour>::template iSUnMatrix<cplx> > ta(ncolour * ncolour - 1);
|
||||
typename SU<ncolour>::template iSUnMatrix<cplx> tmp;
|
||||
Vector<iSUnMatrix<cplx> > ta(ncolour * ncolour - 1);
|
||||
iSUnMatrix<cplx> tmp;
|
||||
|
||||
// FIXME not very efficient to get all the generators everytime
|
||||
for (int a = 0; a < Dimension; a++) SU<ncolour>::generator(a, ta[a]);
|
||||
@ -66,8 +71,7 @@ public:
|
||||
for (int a = 0; a < Dimension; a++) {
|
||||
tmp = ta[a] * ta[Index] - ta[Index] * ta[a];
|
||||
for (int b = 0; b < (ncolour * ncolour - 1); b++) {
|
||||
typename SU<ncolour>::template iSUnMatrix<cplx> tmp1 =
|
||||
2.0 * tmp * ta[b]; // 2.0 from the normalization
|
||||
iSUnMatrix<cplx> tmp1 = 2.0 * tmp * ta[b]; // 2.0 from the normalization
|
||||
Complex iTr = TensorRemove(timesI(trace(tmp1)));
|
||||
//iAdjTa()()(b, a) = iTr;
|
||||
iAdjTa()()(a, b) = iTr;
|
||||
@ -133,8 +137,7 @@ public:
|
||||
|
||||
for (int a = 0; a < Dimension; a++) {
|
||||
generator(a, iTa);
|
||||
LatticeComplex tmp = real(trace(iTa * in)) * coefficient;
|
||||
pokeColour(h_out, tmp, a);
|
||||
pokeColour(h_out, real(trace(iTa * in)) * coefficient, a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,273 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// * Two index representation generators
|
||||
//
|
||||
// * Normalisation for the fundamental generators:
|
||||
// trace ta tb = 1/2 delta_ab = T_F delta_ab
|
||||
// T_F = 1/2 for SU(N) groups
|
||||
//
|
||||
//
|
||||
// base for NxN two index (anti-symmetric) matrices
|
||||
// normalized to 1 (d_ij is the kroenecker delta)
|
||||
//
|
||||
// (e^(ij)_{kl} = 1 / sqrt(2) (d_ik d_jl +/- d_jk d_il)
|
||||
//
|
||||
// Then the generators are written as
|
||||
//
|
||||
// (iT_a)^(ij)(lk) = i * ( tr[e^(ij)^dag e^(lk) T^trasp_a] +
|
||||
// tr[e^(lk)e^(ij)^dag T_a] ) //
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Authors: David Preti, Guido Cossu
|
||||
|
||||
#ifndef QCD_UTIL_SUN2INDEX_H
|
||||
#define QCD_UTIL_SUN2INDEX_H
|
||||
|
||||
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
enum TwoIndexSymmetry { Symmetric = 1, AntiSymmetric = -1 };
|
||||
|
||||
inline Real delta(int a, int b) { return (a == b) ? 1.0 : 0.0; }
|
||||
|
||||
template <int ncolour, TwoIndexSymmetry S>
|
||||
class SU_TwoIndex : public SU<ncolour> {
|
||||
public:
|
||||
static const int Dimension = ncolour * (ncolour + S) / 2;
|
||||
static const int NumGenerators = SU<ncolour>::AdjointDimension;
|
||||
|
||||
template <typename vtype>
|
||||
using iSUnTwoIndexMatrix = iScalar<iScalar<iMatrix<vtype, Dimension> > >;
|
||||
|
||||
typedef iSUnTwoIndexMatrix<Complex> TIMatrix;
|
||||
typedef iSUnTwoIndexMatrix<ComplexF> TIMatrixF;
|
||||
typedef iSUnTwoIndexMatrix<ComplexD> TIMatrixD;
|
||||
|
||||
typedef iSUnTwoIndexMatrix<vComplex> vTIMatrix;
|
||||
typedef iSUnTwoIndexMatrix<vComplexF> vTIMatrixF;
|
||||
typedef iSUnTwoIndexMatrix<vComplexD> vTIMatrixD;
|
||||
|
||||
typedef Lattice<vTIMatrix> LatticeTwoIndexMatrix;
|
||||
typedef Lattice<vTIMatrixF> LatticeTwoIndexMatrixF;
|
||||
typedef Lattice<vTIMatrixD> LatticeTwoIndexMatrixD;
|
||||
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplex, Dimension> >, Nd> >
|
||||
LatticeTwoIndexField;
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplexF, Dimension> >, Nd> >
|
||||
LatticeTwoIndexFieldF;
|
||||
typedef Lattice<iVector<iScalar<iMatrix<vComplexD, Dimension> >, Nd> >
|
||||
LatticeTwoIndexFieldD;
|
||||
|
||||
template <typename vtype>
|
||||
using iSUnMatrix = iScalar<iScalar<iMatrix<vtype, ncolour> > >;
|
||||
|
||||
typedef iSUnMatrix<Complex> Matrix;
|
||||
typedef iSUnMatrix<ComplexF> MatrixF;
|
||||
typedef iSUnMatrix<ComplexD> MatrixD;
|
||||
|
||||
template <class cplx>
|
||||
static void base(int Index, iSUnMatrix<cplx> &eij) {
|
||||
// returns (e)^(ij)_{kl} necessary for change of base U_F -> U_R
|
||||
assert(Index < NumGenerators);
|
||||
eij = Zero();
|
||||
|
||||
// for the linearisation of the 2 indexes
|
||||
static int a[ncolour * (ncolour - 1) / 2][2]; // store the a <-> i,j
|
||||
static bool filled = false;
|
||||
if (!filled) {
|
||||
int counter = 0;
|
||||
for (int i = 1; i < ncolour; i++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
a[counter][0] = i;
|
||||
a[counter][1] = j;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
filled = true;
|
||||
}
|
||||
|
||||
if (Index < ncolour * (ncolour - 1) / 2) {
|
||||
baseOffDiagonal(a[Index][0], a[Index][1], eij);
|
||||
} else {
|
||||
baseDiagonal(Index, eij);
|
||||
}
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void baseDiagonal(int Index, iSUnMatrix<cplx> &eij) {
|
||||
eij = Zero();
|
||||
eij()()(Index - ncolour * (ncolour - 1) / 2,
|
||||
Index - ncolour * (ncolour - 1) / 2) = 1.0;
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void baseOffDiagonal(int i, int j, iSUnMatrix<cplx> &eij) {
|
||||
eij = Zero();
|
||||
for (int k = 0; k < ncolour; k++)
|
||||
for (int l = 0; l < ncolour; l++)
|
||||
eij()()(l, k) = delta(i, k) * delta(j, l) +
|
||||
S * delta(j, k) * delta(i, l);
|
||||
|
||||
RealD nrm = 1. / std::sqrt(2.0);
|
||||
eij = eij * nrm;
|
||||
}
|
||||
|
||||
static void printBase(void) {
|
||||
for (int gen = 0; gen < Dimension; gen++) {
|
||||
Matrix tmp;
|
||||
base(gen, tmp);
|
||||
std::cout << GridLogMessage << "Nc = " << ncolour << " t_" << gen
|
||||
<< std::endl;
|
||||
std::cout << GridLogMessage << tmp << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <class cplx>
|
||||
static void generator(int Index, iSUnTwoIndexMatrix<cplx> &i2indTa) {
|
||||
Vector<typename SU<ncolour>::template iSUnMatrix<cplx> > ta(
|
||||
ncolour * ncolour - 1);
|
||||
Vector<typename SU<ncolour>::template iSUnMatrix<cplx> > eij(Dimension);
|
||||
typename SU<ncolour>::template iSUnMatrix<cplx> tmp;
|
||||
i2indTa = Zero();
|
||||
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++)
|
||||
SU<ncolour>::generator(a, ta[a]);
|
||||
|
||||
for (int a = 0; a < Dimension; a++) base(a, eij[a]);
|
||||
|
||||
for (int a = 0; a < Dimension; a++) {
|
||||
tmp = transpose(ta[Index]) * adj(eij[a]) + adj(eij[a]) * ta[Index];
|
||||
for (int b = 0; b < Dimension; b++) {
|
||||
typename SU<ncolour>::template iSUnMatrix<cplx> tmp1 =
|
||||
tmp * eij[b];
|
||||
Complex iTr = TensorRemove(timesI(trace(tmp1)));
|
||||
i2indTa()()(a, b) = iTr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void printGenerators(void) {
|
||||
for (int gen = 0; gen < ncolour * ncolour - 1; gen++) {
|
||||
TIMatrix i2indTa;
|
||||
generator(gen, i2indTa);
|
||||
std::cout << GridLogMessage << "Nc = " << ncolour << " t_" << gen
|
||||
<< std::endl;
|
||||
std::cout << GridLogMessage << i2indTa << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void testGenerators(void) {
|
||||
TIMatrix i2indTa, i2indTb;
|
||||
std::cout << GridLogMessage << "2IndexRep - Checking if traceless"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) {
|
||||
generator(a, i2indTa);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(trace(i2indTa)) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
|
||||
std::cout << GridLogMessage << "2IndexRep - Checking if antihermitean"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) {
|
||||
generator(a, i2indTa);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(adj(i2indTa) + i2indTa) < 1.0e-6);
|
||||
}
|
||||
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
std::cout << GridLogMessage
|
||||
<< "2IndexRep - Checking Tr[Ta*Tb]=delta(a,b)*(N +- 2)/2"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) {
|
||||
for (int b = 0; b < ncolour * ncolour - 1; b++) {
|
||||
generator(a, i2indTa);
|
||||
generator(b, i2indTb);
|
||||
|
||||
// generator returns iTa, so we need a minus sign here
|
||||
Complex Tr = -TensorRemove(trace(i2indTa * i2indTb));
|
||||
std::cout << GridLogMessage << "a=" << a << "b=" << b << "Tr=" << Tr
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
}
|
||||
|
||||
static void TwoIndexLieAlgebraMatrix(
|
||||
const typename SU<ncolour>::LatticeAlgebraVector &h,
|
||||
LatticeTwoIndexMatrix &out, Real scale = 1.0) {
|
||||
conformable(h, out);
|
||||
GridBase *grid = out.Grid();
|
||||
LatticeTwoIndexMatrix la(grid);
|
||||
TIMatrix i2indTa;
|
||||
|
||||
out = Zero();
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) {
|
||||
generator(a, i2indTa);
|
||||
la = peekColour(h, a) * i2indTa;
|
||||
out += la;
|
||||
}
|
||||
out *= scale;
|
||||
}
|
||||
|
||||
// Projects the algebra components
|
||||
// of a lattice matrix ( of dimension ncol*ncol -1 )
|
||||
static void projectOnAlgebra(
|
||||
typename SU<ncolour>::LatticeAlgebraVector &h_out,
|
||||
const LatticeTwoIndexMatrix &in, Real scale = 1.0) {
|
||||
conformable(h_out, in);
|
||||
h_out = Zero();
|
||||
TIMatrix i2indTa;
|
||||
Real coefficient = -2.0 / (ncolour + 2 * S) * scale;
|
||||
// 2/(Nc +/- 2) for the normalization of the trace in the two index rep
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) {
|
||||
generator(a, i2indTa);
|
||||
auto tmp = real(trace(i2indTa * in)) * coefficient;
|
||||
pokeColour(h_out, tmp, a);
|
||||
}
|
||||
}
|
||||
|
||||
// a projector that keeps the generators stored to avoid the overhead of
|
||||
// recomputing them
|
||||
static void projector(typename SU<ncolour>::LatticeAlgebraVector &h_out,
|
||||
const LatticeTwoIndexMatrix &in, Real scale = 1.0) {
|
||||
conformable(h_out, in);
|
||||
// to store the generators
|
||||
static std::vector<TIMatrix> i2indTa(ncolour * ncolour -1);
|
||||
h_out = Zero();
|
||||
static bool precalculated = false;
|
||||
if (!precalculated) {
|
||||
precalculated = true;
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) generator(a, i2indTa[a]);
|
||||
}
|
||||
|
||||
Real coefficient =
|
||||
-2.0 / (ncolour + 2 * S) * scale; // 2/(Nc +/- 2) for the normalization
|
||||
// of the trace in the two index rep
|
||||
|
||||
for (int a = 0; a < ncolour * ncolour - 1; a++) {
|
||||
auto tmp = real(trace(i2indTa[a] * in)) * coefficient;
|
||||
pokeColour(h_out, tmp, a);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Some useful type names
|
||||
typedef SU_TwoIndex<Nc, Symmetric> TwoIndexSymmMatrices;
|
||||
typedef SU_TwoIndex<Nc, AntiSymmetric> TwoIndexAntiSymmMatrices;
|
||||
|
||||
typedef SU_TwoIndex<2, Symmetric> SU2TwoIndexSymm;
|
||||
typedef SU_TwoIndex<3, Symmetric> SU3TwoIndexSymm;
|
||||
typedef SU_TwoIndex<4, Symmetric> SU4TwoIndexSymm;
|
||||
typedef SU_TwoIndex<5, Symmetric> SU5TwoIndexSymm;
|
||||
|
||||
typedef SU_TwoIndex<2, AntiSymmetric> SU2TwoIndexAntiSymm;
|
||||
typedef SU_TwoIndex<3, AntiSymmetric> SU3TwoIndexAntiSymm;
|
||||
typedef SU_TwoIndex<4, AntiSymmetric> SU4TwoIndexAntiSymm;
|
||||
typedef SU_TwoIndex<5, AntiSymmetric> SU5TwoIndexAntiSymm;
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif
|
317
Grid/qcd/utils/Sp2n.impl.h
Normal file
317
Grid/qcd/utils/Sp2n.impl.h
Normal file
@ -0,0 +1,317 @@
|
||||
// This file is #included into the body of the class template definition of
|
||||
// GaugeGroup. So, image there to be
|
||||
//
|
||||
// template <int ncolour, class group_name>
|
||||
// class GaugeGroup {
|
||||
//
|
||||
// around it.
|
||||
//
|
||||
// Please note that the unconventional file extension makes sure that it
|
||||
// doesn't get found by the scripts/filelist during bootstrapping.
|
||||
|
||||
private:
|
||||
template <ONLY_IF_Sp>
|
||||
static int su2subgroups(GroupName::Sp) { return (ncolour/2 * (ncolour/2 - 1)) / 2; }
|
||||
|
||||
// Sp(2N) has N(2N+1) = 2N^2+N generators
|
||||
//
|
||||
// normalise the generators such that
|
||||
// Trace ( Ta Tb) = 1/2 delta_ab
|
||||
//
|
||||
// N generators in the cartan, 2N^2 off
|
||||
// off diagonal:
|
||||
// there are 6 types named a,b,c,d and w,z
|
||||
// abcd are N(N-1)/2 each while wz are N each
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generator(int lieIndex, iGroupMatrix<cplx> &ta, GroupName::Sp) {
|
||||
// map lie index into type of generators: diagonal, abcd type, wz type
|
||||
|
||||
const int nsp = ncolour/2;
|
||||
int diagIndex;
|
||||
int aIndex, bIndex, cIndex, dIndex;
|
||||
int wIndex, zIndex; // a,b,c,d are N(N-1)/2 and w,z are N
|
||||
const int mod = nsp * (nsp - 1) * 0.5;
|
||||
const int offdiag =
|
||||
2 * nsp * nsp; // number of generators not in the cartan subalgebra
|
||||
const int wmod = 4 * mod;
|
||||
const int zmod = wmod + nsp;
|
||||
if (lieIndex >= offdiag) {
|
||||
diagIndex = lieIndex - offdiag; // 0, ... ,N-1
|
||||
// std::cout << GridLogMessage << "diag type " << std::endl;
|
||||
generatorDiagtype(diagIndex, ta);
|
||||
return;
|
||||
}
|
||||
if ((lieIndex >= wmod) && (lieIndex < zmod)) {
|
||||
// std::cout << GridLogMessage << "w type " << std::endl;
|
||||
wIndex = lieIndex - wmod; // 0, ... ,N-1
|
||||
generatorWtype(wIndex, ta);
|
||||
return;
|
||||
}
|
||||
if ((lieIndex >= zmod) && (lieIndex < offdiag)) {
|
||||
// std::cout << GridLogMessage << "z type " << std::endl;
|
||||
// std::cout << GridLogMessage << "lie index " << lieIndex << std::endl;
|
||||
// std::cout << GridLogMessage << "z mod " << zmod << std::endl;
|
||||
zIndex = lieIndex - zmod; // 0, ... ,N-1
|
||||
generatorZtype(zIndex, ta);
|
||||
return;
|
||||
}
|
||||
if (lieIndex < mod) { // atype 0, ... , N(N-1)/2=mod
|
||||
// std::cout << GridLogMessage << "a type " << std::endl;
|
||||
aIndex = lieIndex;
|
||||
// std::cout << GridLogMessage << "a indx " << aIndex << std::endl;
|
||||
generatorAtype(aIndex, ta);
|
||||
return;
|
||||
}
|
||||
if ((lieIndex >= mod) && lieIndex < 2 * mod) { // btype mod, ... , 2mod-1
|
||||
// std::cout << GridLogMessage << "b type " << std::endl;
|
||||
bIndex = lieIndex - mod;
|
||||
generatorBtype(bIndex, ta);
|
||||
return;
|
||||
}
|
||||
if ((lieIndex >= 2 * mod) &&
|
||||
lieIndex < 3 * mod) { // ctype 2mod, ... , 3mod-1
|
||||
// std::cout << GridLogMessage << "c type " << std::endl;
|
||||
cIndex = lieIndex - 2 * mod;
|
||||
generatorCtype(cIndex, ta);
|
||||
return;
|
||||
}
|
||||
if ((lieIndex >= 3 * mod) &&
|
||||
lieIndex < wmod) { // ctype 3mod, ... , 4mod-1 = wmod-1
|
||||
// std::cout << GridLogMessage << "d type " << std::endl;
|
||||
dIndex = lieIndex - 3 * mod;
|
||||
generatorDtype(dIndex, ta);
|
||||
return;
|
||||
}
|
||||
|
||||
} // end of generator
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorDiagtype(int diagIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,i) = - ta(i+N,i+N) = 1/2 for each i index of the cartan subalgebra
|
||||
|
||||
const int nsp=ncolour/2;
|
||||
ta = Zero();
|
||||
RealD nrm = 1.0 / 2;
|
||||
|
||||
ta()()(diagIndex, diagIndex) = nrm;
|
||||
ta()()(diagIndex + nsp, diagIndex + nsp) = -nrm;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorAtype(int aIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,j) = ta(j,i) = -ta(i+N,j+N) = -ta(j+N,i+N) = 1 / 2 sqrt(2)
|
||||
// with i<j and i=0,...,N-2
|
||||
// follows that j=i+1, ... , N
|
||||
int i1, i2;
|
||||
const int nsp=ncolour/2;
|
||||
ta = Zero();
|
||||
RealD nrm = 1 / (2 * std::sqrt(2));
|
||||
|
||||
su2SubGroupIndex(i1, i2, aIndex);
|
||||
ta()()(i1, i2) = 1;
|
||||
ta()()(i2, i1) = 1;
|
||||
ta()()(i1 + nsp, i2 + nsp) = -1;
|
||||
ta()()(i2 + nsp, i1 + nsp) = -1;
|
||||
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorBtype(int bIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,j) = -ta(j,i) = ta(i+N,j+N) = -ta(j+N,i+N) = i / 1/ 2 sqrt(2)
|
||||
// with i<j and i=0,...,N-2
|
||||
// follows that j=i+1, ... , N-1
|
||||
|
||||
const int nsp=ncolour/2;
|
||||
int i1, i2;
|
||||
ta = Zero();
|
||||
cplx i(0.0, 1.0);
|
||||
RealD nrm = 1 / (2 * std::sqrt(2));
|
||||
su2SubGroupIndex(i1, i2, bIndex);
|
||||
|
||||
ta()()(i1, i2) = i;
|
||||
ta()()(i2, i1) = -i;
|
||||
ta()()(i1 + nsp, i2 + nsp) = i;
|
||||
ta()()(i2 + nsp, i1 + nsp) = -i;
|
||||
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorCtype(int cIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,j+N) = ta(j,i+N) = ta(i+N,j) = ta(j+N,i) = 1 / 2 sqrt(2)
|
||||
|
||||
const int nsp=ncolour/2;
|
||||
int i1, i2;
|
||||
ta = Zero();
|
||||
RealD nrm = 1 / (2 * std::sqrt(2));
|
||||
su2SubGroupIndex(i1, i2, cIndex);
|
||||
|
||||
ta()()(i1, i2 + nsp) = 1;
|
||||
ta()()(i2, i1 + nsp) = 1;
|
||||
ta()()(i1 + nsp, i2) = 1;
|
||||
ta()()(i2 + nsp, i1) = 1;
|
||||
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorDtype(int dIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,j+N) = ta(j,i+N) = -ta(i+N,j) = -ta(j+N,i) = i / 2 sqrt(2)
|
||||
|
||||
const int nsp=ncolour/2;
|
||||
int i1, i2;
|
||||
ta = Zero();
|
||||
cplx i(0.0, 1.0);
|
||||
RealD nrm = 1 / (2 * std::sqrt(2));
|
||||
su2SubGroupIndex(i1, i2, dIndex);
|
||||
|
||||
ta()()(i1, i2 + nsp) = i;
|
||||
ta()()(i2, i1 + nsp) = i;
|
||||
ta()()(i1 + nsp, i2) = -i;
|
||||
ta()()(i2 + nsp, i1) = -i;
|
||||
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorWtype(int wIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,i+N) = ta(i+N,i) = 1/2
|
||||
|
||||
const int nsp=ncolour/2;
|
||||
ta = Zero();
|
||||
RealD nrm = 1.0 / 2; // check
|
||||
|
||||
ta()()(wIndex, wIndex + nsp) = 1;
|
||||
ta()()(wIndex + nsp, wIndex) = 1;
|
||||
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
template <class cplx, ONLY_IF_Sp>
|
||||
static void generatorZtype(int zIndex, iGroupMatrix<cplx> &ta) {
|
||||
// ta(i,i+N) = - ta(i+N,i) = i/2
|
||||
|
||||
const int nsp=ncolour/2;
|
||||
ta = Zero();
|
||||
RealD nrm = 1.0 / 2; // check
|
||||
cplx i(0.0, 1.0);
|
||||
ta()()(zIndex, zIndex + nsp) = i;
|
||||
ta()()(zIndex + nsp, zIndex) = -i;
|
||||
|
||||
ta = ta * nrm;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Map a su2 subgroup number to the pair of rows that are non zero
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
template <ONLY_IF_Sp>
|
||||
static void su2SubGroupIndex(int &i1, int &i2, int su2_index, GroupName::Sp) {
|
||||
const int nsp=ncolour/2;
|
||||
assert((su2_index >= 0) && (su2_index < (nsp * (nsp - 1)) / 2));
|
||||
|
||||
int spare = su2_index;
|
||||
for (i1 = 0; spare >= (nsp - 1 - i1); i1++) {
|
||||
spare = spare - (nsp - 1 - i1); // remove the Nc-1-i1 terms
|
||||
}
|
||||
i2 = i1 + 1 + spare;
|
||||
}
|
||||
|
||||
static void testGenerators(GroupName::Sp) {
|
||||
Matrix ta;
|
||||
Matrix tb;
|
||||
std::cout << GridLogMessage
|
||||
<< "Fundamental - Checking trace ta tb is 0.5 delta_ab "
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
for (int b = 0; b < AlgebraDimension; b++) {
|
||||
generator(a, ta);
|
||||
generator(b, tb);
|
||||
Complex tr = TensorRemove(trace(ta * tb));
|
||||
std::cout << GridLogMessage << "(" << a << "," << b << ") = " << tr
|
||||
<< std::endl;
|
||||
if (a == b) assert(abs(tr - Complex(0.5)) < 1.0e-6);
|
||||
if (a != b) assert(abs(tr) < 1.0e-6);
|
||||
}
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
std::cout << GridLogMessage << "Fundamental - Checking if hermitian"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
generator(a, ta);
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(norm2(ta - adj(ta)) < 1.0e-6);
|
||||
}
|
||||
std::cout << GridLogMessage << std::endl;
|
||||
std::cout << GridLogMessage << "Fundamental - Checking if traceless"
|
||||
<< std::endl;
|
||||
for (int a = 0; a < AlgebraDimension; a++) {
|
||||
generator(a, ta);
|
||||
Complex tr = TensorRemove(trace(ta));
|
||||
std::cout << GridLogMessage << a << std::endl;
|
||||
assert(abs(tr) < 1.0e-6);
|
||||
}
|
||||
}
|
||||
|
||||
template <int N>
|
||||
static Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > >
|
||||
ProjectOnGeneralGroup(const Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > &Umu, GroupName::Sp) {
|
||||
return ProjectOnSpGroup(Umu);
|
||||
}
|
||||
|
||||
template <class vtype>
|
||||
accelerator_inline static iScalar<vtype> ProjectOnGeneralGroup(const iScalar<vtype> &r, GroupName::Sp) {
|
||||
return ProjectOnSpGroup(r);
|
||||
}
|
||||
|
||||
template <class vtype, int N>
|
||||
accelerator_inline static iVector<vtype,N> ProjectOnGeneralGroup(const iVector<vtype,N> &r, GroupName::Sp) {
|
||||
return ProjectOnSpGroup(r);
|
||||
}
|
||||
|
||||
template <class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
accelerator_inline static iMatrix<vtype,N> ProjectOnGeneralGroup(const iMatrix<vtype,N> &arg, GroupName::Sp) {
|
||||
return ProjectOnSpGroup(arg);
|
||||
}
|
||||
|
||||
template <typename LatticeMatrixType>
|
||||
static void taProj(const LatticeMatrixType &in, LatticeMatrixType &out, GroupName::Sp) {
|
||||
out = SpTa(in);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <ONLY_IF_Sp>
|
||||
static void Omega(LatticeColourMatrixD &in) {
|
||||
const int nsp=ncolour/2;
|
||||
LatticeColourMatrixD OmegaLatt(in.Grid());
|
||||
LatticeColourMatrixD identity(in.Grid());
|
||||
ColourMatrix Omega;
|
||||
|
||||
OmegaLatt = Zero();
|
||||
Omega = Zero();
|
||||
identity = 1.;
|
||||
|
||||
for (int i = 0; i < nsp; i++) {
|
||||
Omega()()(i, nsp + i) = 1.;
|
||||
Omega()()(nsp + i, i) = -1;
|
||||
}
|
||||
OmegaLatt = OmegaLatt + (identity * Omega);
|
||||
in = OmegaLatt;
|
||||
}
|
||||
|
||||
template <ONLY_IF_Sp, class vtype, int N>
|
||||
static void Omega(iScalar<iScalar<iMatrix<vtype, N> > > &in) {
|
||||
const int nsp=ncolour/2;
|
||||
|
||||
iScalar<iScalar<iMatrix<vtype, N> > > Omega;
|
||||
Omega = Zero();
|
||||
|
||||
for (int i = 0; i < nsp; i++) {
|
||||
Omega()()(i, nsp + i) = 1.;
|
||||
Omega()()(nsp + i, i) = -1;
|
||||
}
|
||||
|
||||
in = Omega;
|
||||
}
|
@ -8,9 +8,9 @@
|
||||
#include <Grid/qcd/utils/ScalarObjs.h>
|
||||
|
||||
// Include representations
|
||||
#include <Grid/qcd/utils/SUn.h>
|
||||
#include <Grid/qcd/utils/GaugeGroup.h>
|
||||
#include <Grid/qcd/utils/SUnAdjoint.h>
|
||||
#include <Grid/qcd/utils/SUnTwoIndex.h>
|
||||
#include <Grid/qcd/utils/GaugeGroupTwoIndex.h>
|
||||
|
||||
// All-to-all contraction kernels that touch the
|
||||
// internal lattice structure
|
||||
|
@ -290,7 +290,7 @@ public:
|
||||
}
|
||||
*/
|
||||
//////////////////////////////////////////////////
|
||||
// the sum over all staples on each site
|
||||
// the sum over all nu-oriented staples for nu != mu on each site
|
||||
//////////////////////////////////////////////////
|
||||
static void Staple(GaugeMat &staple, const GaugeLorentz &Umu, int mu) {
|
||||
|
||||
@ -300,6 +300,10 @@ public:
|
||||
for (int d = 0; d < Nd; d++) {
|
||||
U[d] = PeekIndex<LorentzIndex>(Umu, d);
|
||||
}
|
||||
Staple(staple, U, mu);
|
||||
}
|
||||
|
||||
static void Staple(GaugeMat &staple, const std::vector<GaugeMat> &U, int mu) {
|
||||
staple = Zero();
|
||||
|
||||
for (int nu = 0; nu < Nd; nu++) {
|
||||
@ -335,6 +339,203 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/////////////
|
||||
//Staples for each direction mu, summed over nu != mu
|
||||
//staple: output staples for each mu (Nd)
|
||||
//U: link array (Nd)
|
||||
/////////////
|
||||
static void StapleAll(std::vector<GaugeMat> &staple, const std::vector<GaugeMat> &U) {
|
||||
assert(staple.size() == Nd); assert(U.size() == Nd);
|
||||
for(int mu=0;mu<Nd;mu++) Staple(staple[mu], U, mu);
|
||||
}
|
||||
|
||||
|
||||
//A workspace class allowing reuse of the stencil
|
||||
class WilsonLoopPaddedStencilWorkspace{
|
||||
std::unique_ptr<GeneralLocalStencil> stencil;
|
||||
size_t nshift;
|
||||
|
||||
void generateStencil(GridBase* padded_grid){
|
||||
double t0 = usecond();
|
||||
|
||||
//Generate shift arrays
|
||||
std::vector<Coordinate> shifts = this->getShifts();
|
||||
nshift = shifts.size();
|
||||
|
||||
double t1 = usecond();
|
||||
//Generate local stencil
|
||||
stencil.reset(new GeneralLocalStencil(padded_grid,shifts));
|
||||
double t2 = usecond();
|
||||
std::cout << GridLogPerformance << " WilsonLoopPaddedWorkspace timings: coord:" << (t1-t0)/1000 << "ms, stencil:" << (t2-t1)/1000 << "ms" << std::endl;
|
||||
}
|
||||
public:
|
||||
//Get the stencil. If not already generated, or if generated using a different Grid than in PaddedCell, it will be created on-the-fly
|
||||
const GeneralLocalStencil & getStencil(const PaddedCell &pcell){
|
||||
assert(pcell.depth >= this->paddingDepth());
|
||||
if(!stencil || stencil->Grid() != (GridBase*)pcell.grids.back() ) generateStencil((GridBase*)pcell.grids.back());
|
||||
return *stencil;
|
||||
}
|
||||
size_t Nshift() const{ return nshift; }
|
||||
|
||||
virtual std::vector<Coordinate> getShifts() const = 0;
|
||||
virtual int paddingDepth() const = 0; //padding depth required
|
||||
|
||||
virtual ~WilsonLoopPaddedStencilWorkspace(){}
|
||||
};
|
||||
|
||||
//This workspace allows the sharing of a common PaddedCell object between multiple stencil workspaces
|
||||
class WilsonLoopPaddedWorkspace{
|
||||
std::vector<WilsonLoopPaddedStencilWorkspace*> stencil_wk;
|
||||
std::unique_ptr<PaddedCell> pcell;
|
||||
|
||||
void generatePcell(GridBase* unpadded_grid){
|
||||
assert(stencil_wk.size());
|
||||
int max_depth = 0;
|
||||
for(auto const &s : stencil_wk) max_depth=std::max(max_depth, s->paddingDepth());
|
||||
|
||||
pcell.reset(new PaddedCell(max_depth, dynamic_cast<GridCartesian*>(unpadded_grid)));
|
||||
}
|
||||
|
||||
public:
|
||||
//Add a stencil definition. This should be done before the first call to retrieve a stencil object.
|
||||
//Takes ownership of the pointer
|
||||
void addStencil(WilsonLoopPaddedStencilWorkspace *stencil){
|
||||
assert(!pcell);
|
||||
stencil_wk.push_back(stencil);
|
||||
}
|
||||
|
||||
const GeneralLocalStencil & getStencil(const size_t stencil_idx, GridBase* unpadded_grid){
|
||||
if(!pcell || pcell->unpadded_grid != unpadded_grid) generatePcell(unpadded_grid);
|
||||
return stencil_wk[stencil_idx]->getStencil(*pcell);
|
||||
}
|
||||
const PaddedCell & getPaddedCell(GridBase* unpadded_grid){
|
||||
if(!pcell || pcell->unpadded_grid != unpadded_grid) generatePcell(unpadded_grid);
|
||||
return *pcell;
|
||||
}
|
||||
|
||||
~WilsonLoopPaddedWorkspace(){
|
||||
for(auto &s : stencil_wk) delete s;
|
||||
}
|
||||
};
|
||||
|
||||
//A workspace class allowing reuse of the stencil
|
||||
class StaplePaddedAllWorkspace: public WilsonLoopPaddedStencilWorkspace{
|
||||
public:
|
||||
std::vector<Coordinate> getShifts() const override{
|
||||
std::vector<Coordinate> shifts;
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
for(int nu=0;nu<Nd;nu++){
|
||||
if(nu != mu){
|
||||
Coordinate shift_0(Nd,0);
|
||||
Coordinate shift_mu(Nd,0); shift_mu[mu]=1;
|
||||
Coordinate shift_nu(Nd,0); shift_nu[nu]=1;
|
||||
Coordinate shift_mnu(Nd,0); shift_mnu[nu]=-1;
|
||||
Coordinate shift_mnu_pmu(Nd,0); shift_mnu_pmu[nu]=-1; shift_mnu_pmu[mu]=1;
|
||||
|
||||
//U_nu(x+mu)U^dag_mu(x+nu) U^dag_nu(x)
|
||||
shifts.push_back(shift_0);
|
||||
shifts.push_back(shift_nu);
|
||||
shifts.push_back(shift_mu);
|
||||
|
||||
//U_nu^dag(x-nu+mu) U_mu^dag(x-nu) U_nu(x-nu)
|
||||
shifts.push_back(shift_mnu);
|
||||
shifts.push_back(shift_mnu);
|
||||
shifts.push_back(shift_mnu_pmu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return shifts;
|
||||
}
|
||||
|
||||
int paddingDepth() const override{ return 1; }
|
||||
};
|
||||
|
||||
//Padded cell implementation of the staple method for all mu, summed over nu != mu
|
||||
//staple: output staple for each mu, summed over nu != mu (Nd)
|
||||
//U_padded: the gauge link fields padded out using the PaddedCell class
|
||||
//Cell: the padded cell class
|
||||
static void StaplePaddedAll(std::vector<GaugeMat> &staple, const std::vector<GaugeMat> &U_padded, const PaddedCell &Cell) {
|
||||
StaplePaddedAllWorkspace wk;
|
||||
StaplePaddedAll(staple,U_padded,Cell,wk.getStencil(Cell));
|
||||
}
|
||||
|
||||
//Padded cell implementation of the staple method for all mu, summed over nu != mu
|
||||
//staple: output staple for each mu, summed over nu != mu (Nd)
|
||||
//U_padded: the gauge link fields padded out using the PaddedCell class
|
||||
//Cell: the padded cell class
|
||||
//gStencil: the precomputed generalized local stencil for the staple
|
||||
static void StaplePaddedAll(std::vector<GaugeMat> &staple, const std::vector<GaugeMat> &U_padded, const PaddedCell &Cell, const GeneralLocalStencil &gStencil)
|
||||
{
|
||||
double t0 = usecond();
|
||||
assert(U_padded.size() == Nd); assert(staple.size() == Nd);
|
||||
assert(U_padded[0].Grid() == (GridBase*)Cell.grids.back());
|
||||
assert(Cell.depth >= 1);
|
||||
GridBase *ggrid = U_padded[0].Grid(); //padded cell grid
|
||||
|
||||
int shift_mu_off = gStencil._npoints/Nd;
|
||||
|
||||
//Open views to padded gauge links and keep open over mu loop
|
||||
typedef LatticeView<typename GaugeMat::vector_object> GaugeViewType;
|
||||
size_t vsize = Nd*sizeof(GaugeViewType);
|
||||
GaugeViewType* Ug_dirs_v_host = (GaugeViewType*)malloc(vsize);
|
||||
for(int i=0;i<Nd;i++) Ug_dirs_v_host[i] = U_padded[i].View(AcceleratorRead);
|
||||
GaugeViewType* Ug_dirs_v = (GaugeViewType*)acceleratorAllocDevice(vsize);
|
||||
acceleratorCopyToDevice(Ug_dirs_v_host,Ug_dirs_v,vsize);
|
||||
|
||||
GaugeMat gStaple(ggrid);
|
||||
|
||||
int outer_off = 0;
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
{ //view scope
|
||||
autoView( gStaple_v , gStaple, AcceleratorWrite);
|
||||
auto gStencil_v = gStencil.View();
|
||||
|
||||
accelerator_for(ss, ggrid->oSites(), (size_t)ggrid->Nsimd(), {
|
||||
decltype(coalescedRead(Ug_dirs_v[0][0])) stencil_ss;
|
||||
stencil_ss = Zero();
|
||||
int off = outer_off;
|
||||
|
||||
for(int nu=0;nu<Nd;nu++){
|
||||
if(nu != mu){
|
||||
GeneralStencilEntry const* e = gStencil_v.GetEntry(off++,ss);
|
||||
auto U0 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(off++,ss);
|
||||
auto U1 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(off++,ss);
|
||||
auto U2 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
|
||||
stencil_ss = stencil_ss + U2 * U1 * U0;
|
||||
|
||||
e = gStencil_v.GetEntry(off++,ss);
|
||||
U0 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(off++,ss);
|
||||
U1 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(off++,ss);
|
||||
U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
|
||||
stencil_ss = stencil_ss + U2 * U1 * U0;
|
||||
}
|
||||
}
|
||||
|
||||
coalescedWrite(gStaple_v[ss],stencil_ss);
|
||||
}
|
||||
);
|
||||
} //ensure views are all closed!
|
||||
|
||||
staple[mu] = Cell.Extract(gStaple);
|
||||
outer_off += shift_mu_off;
|
||||
}//mu loop
|
||||
|
||||
for(int i=0;i<Nd;i++) Ug_dirs_v_host[i].ViewClose();
|
||||
free(Ug_dirs_v_host);
|
||||
acceleratorFreeDevice(Ug_dirs_v);
|
||||
|
||||
double t1=usecond();
|
||||
|
||||
std::cout << GridLogPerformance << "StaplePaddedAll timing:" << (t1-t0)/1000 << "ms" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// the sum over all staples on each site in direction mu,nu, upper part
|
||||
//////////////////////////////////////////////////
|
||||
@ -707,18 +908,14 @@ public:
|
||||
// the sum over all staples on each site
|
||||
//////////////////////////////////////////////////
|
||||
static void RectStapleDouble(GaugeMat &U2, const GaugeMat &U, int mu) {
|
||||
U2 = U * Cshift(U, mu, 1);
|
||||
U2 = U * Gimpl::CshiftLink(U, mu, 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Hop by two optimisation strategy does not work nicely with Gparity. (could
|
||||
// do,
|
||||
// but need to track two deep where cross boundary and apply a conjugation).
|
||||
// Must differentiate this in Gimpl, and use Gimpl::isPeriodicGaugeField to do
|
||||
// so .
|
||||
// Hop by two optimisation strategy. Use RectStapleDouble to obtain 'U2'
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
static void RectStapleOptimised(GaugeMat &Stap, std::vector<GaugeMat> &U2,
|
||||
std::vector<GaugeMat> &U, int mu) {
|
||||
static void RectStapleOptimised(GaugeMat &Stap, const std::vector<GaugeMat> &U2,
|
||||
const std::vector<GaugeMat> &U, int mu) {
|
||||
|
||||
Stap = Zero();
|
||||
|
||||
@ -732,9 +929,9 @@ public:
|
||||
|
||||
// Up staple ___ ___
|
||||
// | |
|
||||
tmp = Cshift(adj(U[nu]), nu, -1);
|
||||
tmp = Gimpl::CshiftLink(adj(U[nu]), nu, -1);
|
||||
tmp = adj(U2[mu]) * tmp;
|
||||
tmp = Cshift(tmp, mu, -2);
|
||||
tmp = Gimpl::CshiftLink(tmp, mu, -2);
|
||||
|
||||
Staple2x1 = Gimpl::CovShiftForward(U[nu], nu, tmp);
|
||||
|
||||
@ -742,14 +939,14 @@ public:
|
||||
// |___ ___|
|
||||
//
|
||||
tmp = adj(U2[mu]) * U[nu];
|
||||
Staple2x1 += Gimpl::CovShiftBackward(U[nu], nu, Cshift(tmp, mu, -2));
|
||||
Staple2x1 += Gimpl::CovShiftBackward(U[nu], nu, Gimpl::CshiftLink(tmp, mu, -2));
|
||||
|
||||
// ___ ___
|
||||
// | ___|
|
||||
// |___ ___|
|
||||
//
|
||||
|
||||
Stap += Cshift(Gimpl::CovShiftForward(U[mu], mu, Staple2x1), mu, 1);
|
||||
Stap += Gimpl::CshiftLink(Gimpl::CovShiftForward(U[mu], mu, Staple2x1), mu, 1);
|
||||
|
||||
// ___ ___
|
||||
// |___ |
|
||||
@ -758,7 +955,7 @@ public:
|
||||
|
||||
// tmp= Staple2x1* Cshift(U[mu],mu,-2);
|
||||
// Stap+= Cshift(tmp,mu,1) ;
|
||||
Stap += Cshift(Staple2x1, mu, 1) * Cshift(U[mu], mu, -1);
|
||||
Stap += Gimpl::CshiftLink(Staple2x1, mu, 1) * Gimpl::CshiftLink(U[mu], mu, -1);
|
||||
;
|
||||
|
||||
// --
|
||||
@ -766,10 +963,10 @@ public:
|
||||
//
|
||||
// | |
|
||||
|
||||
tmp = Cshift(adj(U2[nu]), nu, -2);
|
||||
tmp = Gimpl::CshiftLink(adj(U2[nu]), nu, -2);
|
||||
tmp = Gimpl::CovShiftBackward(U[mu], mu, tmp);
|
||||
tmp = U2[nu] * Cshift(tmp, nu, 2);
|
||||
Stap += Cshift(tmp, mu, 1);
|
||||
tmp = U2[nu] * Gimpl::CshiftLink(tmp, nu, 2);
|
||||
Stap += Gimpl::CshiftLink(tmp, mu, 1);
|
||||
|
||||
// | |
|
||||
//
|
||||
@ -778,25 +975,12 @@ public:
|
||||
|
||||
tmp = Gimpl::CovShiftBackward(U[mu], mu, U2[nu]);
|
||||
tmp = adj(U2[nu]) * tmp;
|
||||
tmp = Cshift(tmp, nu, -2);
|
||||
Stap += Cshift(tmp, mu, 1);
|
||||
tmp = Gimpl::CshiftLink(tmp, nu, -2);
|
||||
Stap += Gimpl::CshiftLink(tmp, mu, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void RectStaple(GaugeMat &Stap, const GaugeLorentz &Umu, int mu) {
|
||||
RectStapleUnoptimised(Stap, Umu, mu);
|
||||
}
|
||||
static void RectStaple(const GaugeLorentz &Umu, GaugeMat &Stap,
|
||||
std::vector<GaugeMat> &U2, std::vector<GaugeMat> &U,
|
||||
int mu) {
|
||||
if (Gimpl::isPeriodicGaugeField()) {
|
||||
RectStapleOptimised(Stap, U2, U, mu);
|
||||
} else {
|
||||
RectStapleUnoptimised(Stap, Umu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
static void RectStapleUnoptimised(GaugeMat &Stap, const GaugeLorentz &Umu,
|
||||
int mu) {
|
||||
GridBase *grid = Umu.Grid();
|
||||
@ -895,6 +1079,288 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void RectStaple(GaugeMat &Stap, const GaugeLorentz &Umu, int mu) {
|
||||
RectStapleUnoptimised(Stap, Umu, mu);
|
||||
}
|
||||
static void RectStaple(const GaugeLorentz &Umu, GaugeMat &Stap,
|
||||
std::vector<GaugeMat> &U2, std::vector<GaugeMat> &U,
|
||||
int mu) {
|
||||
RectStapleOptimised(Stap, U2, U, mu);
|
||||
}
|
||||
//////////////////////////////////////////////////////
|
||||
//Compute the rectangular staples for all orientations
|
||||
//Stap : Array of staples (Nd)
|
||||
//U: Gauge links in each direction (Nd)
|
||||
/////////////////////////////////////////////////////
|
||||
static void RectStapleAll(std::vector<GaugeMat> &Stap, const std::vector<GaugeMat> &U){
|
||||
assert(Stap.size() == Nd); assert(U.size() == Nd);
|
||||
std::vector<GaugeMat> U2(Nd,U[0].Grid());
|
||||
for(int mu=0;mu<Nd;mu++) RectStapleDouble(U2[mu], U[mu], mu);
|
||||
for(int mu=0;mu<Nd;mu++) RectStapleOptimised(Stap[mu], U2, U, mu);
|
||||
}
|
||||
|
||||
//A workspace class allowing reuse of the stencil
|
||||
class RectStaplePaddedAllWorkspace: public WilsonLoopPaddedStencilWorkspace{
|
||||
public:
|
||||
std::vector<Coordinate> getShifts() const override{
|
||||
std::vector<Coordinate> shifts;
|
||||
for (int mu = 0; mu < Nd; mu++){
|
||||
for (int nu = 0; nu < Nd; nu++) {
|
||||
if (nu != mu) {
|
||||
auto genShift = [&](int mushift,int nushift){
|
||||
Coordinate out(Nd,0); out[mu]=mushift; out[nu]=nushift; return out;
|
||||
};
|
||||
|
||||
//tmp6 = tmp5(x+mu) = U_mu(x+mu)U_nu(x+2mu)U_mu^dag(x+nu+mu) U_mu^dag(x+nu) U_nu^dag(x)
|
||||
shifts.push_back(genShift(0,0));
|
||||
shifts.push_back(genShift(0,+1));
|
||||
shifts.push_back(genShift(+1,+1));
|
||||
shifts.push_back(genShift(+2,0));
|
||||
shifts.push_back(genShift(+1,0));
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U_mu(x+mu)U^dag_nu(x-nu+2mu)U^dag_mu(x-nu+mu)U^dag_mu(x-nu)U_nu(x-nu)
|
||||
shifts.push_back(genShift(0,-1));
|
||||
shifts.push_back(genShift(0,-1));
|
||||
shifts.push_back(genShift(+1,-1));
|
||||
shifts.push_back(genShift(+2,-1));
|
||||
shifts.push_back(genShift(+1,0));
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U^dag_nu(x-nu+mu)U^dag_mu(x-nu)U^dag_mu(x-mu-nu)U_nu(x-mu-nu)U_mu(x-mu)
|
||||
shifts.push_back(genShift(-1,0));
|
||||
shifts.push_back(genShift(-1,-1));
|
||||
shifts.push_back(genShift(-1,-1));
|
||||
shifts.push_back(genShift(0,-1));
|
||||
shifts.push_back(genShift(+1,-1));
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U_nu(x+mu)U_mu^dag(x+nu)U_mu^dag(x-mu+nu)U_nu^dag(x-mu)U_mu(x-mu)
|
||||
shifts.push_back(genShift(-1,0));
|
||||
shifts.push_back(genShift(-1,0));
|
||||
shifts.push_back(genShift(-1,+1));
|
||||
shifts.push_back(genShift(0,+1));
|
||||
shifts.push_back(genShift(+1,0));
|
||||
|
||||
//tmp6 = tmp5(x+mu) = U_nu(x+mu)U_nu(x+mu+nu)U_mu^dag(x+2nu)U_nu^dag(x+nu)U_nu^dag(x)
|
||||
shifts.push_back(genShift(0,0));
|
||||
shifts.push_back(genShift(0,+1));
|
||||
shifts.push_back(genShift(0,+2));
|
||||
shifts.push_back(genShift(+1,+1));
|
||||
shifts.push_back(genShift(+1,0));
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U_nu^dag(x+mu-nu)U_nu^dag(x+mu-2nu)U_mu^dag(x-2nu)U_nu(x-2nu)U_nu(x-nu)
|
||||
shifts.push_back(genShift(0,-1));
|
||||
shifts.push_back(genShift(0,-2));
|
||||
shifts.push_back(genShift(0,-2));
|
||||
shifts.push_back(genShift(+1,-2));
|
||||
shifts.push_back(genShift(+1,-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return shifts;
|
||||
}
|
||||
|
||||
int paddingDepth() const override{ return 2; }
|
||||
};
|
||||
|
||||
//Padded cell implementation of the rectangular staple method for all mu, summed over nu != mu
|
||||
//staple: output staple for each mu, summed over nu != mu (Nd)
|
||||
//U_padded: the gauge link fields padded out using the PaddedCell class
|
||||
//Cell: the padded cell class
|
||||
static void RectStaplePaddedAll(std::vector<GaugeMat> &staple, const std::vector<GaugeMat> &U_padded, const PaddedCell &Cell) {
|
||||
RectStaplePaddedAllWorkspace wk;
|
||||
RectStaplePaddedAll(staple,U_padded,Cell,wk.getStencil(Cell));
|
||||
}
|
||||
|
||||
//Padded cell implementation of the rectangular staple method for all mu, summed over nu != mu
|
||||
//staple: output staple for each mu, summed over nu != mu (Nd)
|
||||
//U_padded: the gauge link fields padded out using the PaddedCell class
|
||||
//Cell: the padded cell class
|
||||
//gStencil: the stencil
|
||||
static void RectStaplePaddedAll(std::vector<GaugeMat> &staple, const std::vector<GaugeMat> &U_padded, const PaddedCell &Cell, const GeneralLocalStencil &gStencil) {
|
||||
double t0 = usecond();
|
||||
assert(U_padded.size() == Nd); assert(staple.size() == Nd);
|
||||
assert(U_padded[0].Grid() == (GridBase*)Cell.grids.back());
|
||||
assert(Cell.depth >= 2);
|
||||
GridBase *ggrid = U_padded[0].Grid(); //padded cell grid
|
||||
|
||||
size_t nshift = gStencil._npoints;
|
||||
int mu_off_delta = nshift / Nd;
|
||||
|
||||
//Open views to padded gauge links and keep open over mu loop
|
||||
typedef LatticeView<typename GaugeMat::vector_object> GaugeViewType;
|
||||
size_t vsize = Nd*sizeof(GaugeViewType);
|
||||
GaugeViewType* Ug_dirs_v_host = (GaugeViewType*)malloc(vsize);
|
||||
for(int i=0;i<Nd;i++) Ug_dirs_v_host[i] = U_padded[i].View(AcceleratorRead);
|
||||
GaugeViewType* Ug_dirs_v = (GaugeViewType*)acceleratorAllocDevice(vsize);
|
||||
acceleratorCopyToDevice(Ug_dirs_v_host,Ug_dirs_v,vsize);
|
||||
|
||||
GaugeMat gStaple(ggrid); //temp staple object on padded grid
|
||||
|
||||
int offset = 0;
|
||||
for(int mu=0; mu<Nd; mu++){
|
||||
|
||||
{ //view scope
|
||||
autoView( gStaple_v , gStaple, AcceleratorWrite);
|
||||
auto gStencil_v = gStencil.View();
|
||||
|
||||
accelerator_for(ss, ggrid->oSites(), (size_t)ggrid->Nsimd(), {
|
||||
decltype(coalescedRead(Ug_dirs_v[0][0])) stencil_ss;
|
||||
stencil_ss = Zero();
|
||||
int s=offset;
|
||||
for(int nu=0;nu<Nd;nu++){
|
||||
if(nu != mu){
|
||||
//tmp6 = tmp5(x+mu) = U_mu(x+mu)U_nu(x+2mu)U_mu^dag(x+nu+mu) U_mu^dag(x+nu) U_nu^dag(x)
|
||||
GeneralStencilEntry const* e = gStencil_v.GetEntry(s++,ss);
|
||||
auto U0 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
auto U1 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
auto U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
auto U3 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
auto U4 = coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd);
|
||||
|
||||
stencil_ss = stencil_ss + U4*U3*U2*U1*U0;
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U_mu(x+mu)U^dag_nu(x-nu+2mu)U^dag_mu(x-nu+mu)U^dag_mu(x-nu)U_nu(x-nu)
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U0 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U1 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U3 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U4 = coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd);
|
||||
|
||||
stencil_ss = stencil_ss + U4*U3*U2*U1*U0;
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U^dag_nu(x-nu+mu)U^dag_mu(x-nu)U^dag_mu(x-mu-nu)U_nu(x-mu-nu)U_mu(x-mu)
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U0 = coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U1 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U3 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U4 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
|
||||
stencil_ss = stencil_ss + U4*U3*U2*U1*U0;
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U_nu(x+mu)U_mu^dag(x+nu)U_mu^dag(x-mu+nu)U_nu^dag(x-mu)U_mu(x-mu)
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U0 = coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U1 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U3 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U4 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
|
||||
stencil_ss = stencil_ss + U4*U3*U2*U1*U0;
|
||||
|
||||
//tmp6 = tmp5(x+mu) = U_nu(x+mu)U_nu(x+mu+nu)U_mu^dag(x+2nu)U_nu^dag(x+nu)U_nu^dag(x)
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U0 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U1 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U3 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U4 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
|
||||
stencil_ss = stencil_ss + U4*U3*U2*U1*U0;
|
||||
|
||||
//tmp5 = tmp4(x+mu) = U_nu^dag(x+mu-nu)U_nu^dag(x+mu-2nu)U_mu^dag(x-2nu)U_nu(x-2nu)U_nu(x-nu)
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U0 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U1 = coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd);
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U2 = adj(coalescedReadGeneralPermute(Ug_dirs_v[mu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U3 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
e = gStencil_v.GetEntry(s++,ss);
|
||||
U4 = adj(coalescedReadGeneralPermute(Ug_dirs_v[nu][e->_offset], e->_permute, Nd));
|
||||
|
||||
stencil_ss = stencil_ss + U4*U3*U2*U1*U0;
|
||||
|
||||
}
|
||||
}
|
||||
coalescedWrite(gStaple_v[ss],stencil_ss);
|
||||
}
|
||||
);
|
||||
offset += mu_off_delta;
|
||||
}//kernel/view scope
|
||||
|
||||
staple[mu] = Cell.Extract(gStaple);
|
||||
}//mu loop
|
||||
|
||||
for(int i=0;i<Nd;i++) Ug_dirs_v_host[i].ViewClose();
|
||||
free(Ug_dirs_v_host);
|
||||
acceleratorFreeDevice(Ug_dirs_v);
|
||||
|
||||
double t1 = usecond();
|
||||
|
||||
std::cout << GridLogPerformance << "RectStaplePaddedAll timings:" << (t1-t0)/1000 << "ms" << std::endl;
|
||||
}
|
||||
|
||||
//A workspace for reusing the PaddedCell and GeneralLocalStencil objects
|
||||
class StapleAndRectStapleAllWorkspace: public WilsonLoopPaddedWorkspace{
|
||||
public:
|
||||
StapleAndRectStapleAllWorkspace(){
|
||||
this->addStencil(new StaplePaddedAllWorkspace);
|
||||
this->addStencil(new RectStaplePaddedAllWorkspace);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Compute the 1x1 and 1x2 staples for all orientations
|
||||
//Stap : Array of staples (Nd)
|
||||
//RectStap: Array of rectangular staples (Nd)
|
||||
//U: Gauge links in each direction (Nd)
|
||||
/////////////////////////////////////////////////////
|
||||
static void StapleAndRectStapleAll(std::vector<GaugeMat> &Stap, std::vector<GaugeMat> &RectStap, const std::vector<GaugeMat> &U){
|
||||
StapleAndRectStapleAllWorkspace wk;
|
||||
StapleAndRectStapleAll(Stap,RectStap,U,wk);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Compute the 1x1 and 1x2 staples for all orientations
|
||||
//Stap : Array of staples (Nd)
|
||||
//RectStap: Array of rectangular staples (Nd)
|
||||
//U: Gauge links in each direction (Nd)
|
||||
//wk: a workspace containing stored PaddedCell and GeneralLocalStencil objects to maximize reuse
|
||||
/////////////////////////////////////////////////////
|
||||
static void StapleAndRectStapleAll(std::vector<GaugeMat> &Stap, std::vector<GaugeMat> &RectStap, const std::vector<GaugeMat> &U, StapleAndRectStapleAllWorkspace &wk){
|
||||
#if 0
|
||||
StapleAll(Stap, U);
|
||||
RectStapleAll(RectStap, U);
|
||||
#else
|
||||
double t0 = usecond();
|
||||
|
||||
GridCartesian* unpadded_grid = dynamic_cast<GridCartesian*>(U[0].Grid());
|
||||
const PaddedCell &Ghost = wk.getPaddedCell(unpadded_grid);
|
||||
|
||||
CshiftImplGauge<Gimpl> cshift_impl;
|
||||
std::vector<GaugeMat> U_pad(Nd, Ghost.grids.back());
|
||||
for(int mu=0;mu<Nd;mu++) U_pad[mu] = Ghost.Exchange(U[mu], cshift_impl);
|
||||
double t1 = usecond();
|
||||
StaplePaddedAll(Stap, U_pad, Ghost, wk.getStencil(0,unpadded_grid) );
|
||||
double t2 = usecond();
|
||||
RectStaplePaddedAll(RectStap, U_pad, Ghost, wk.getStencil(1,unpadded_grid));
|
||||
double t3 = usecond();
|
||||
std::cout << GridLogPerformance << "StapleAndRectStapleAll timings: pad:" << (t1-t0)/1000 << "ms, staple:" << (t2-t1)/1000 << "ms, rect-staple:" << (t3-t2)/1000 << "ms" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Wilson loop of size (R1, R2), oriented in mu,nu plane
|
||||
//////////////////////////////////////////////////
|
||||
|
@ -320,7 +320,7 @@ struct Conj{
|
||||
|
||||
struct TimesMinusI{
|
||||
//Complex single
|
||||
inline float32x4_t operator()(float32x4_t in, float32x4_t ret){
|
||||
inline float32x4_t operator()(float32x4_t in){
|
||||
// ar ai br bi -> ai -ar ai -br
|
||||
float32x4_t r0, r1;
|
||||
r0 = vnegq_f32(in); // -ar -ai -br -bi
|
||||
@ -328,7 +328,7 @@ struct TimesMinusI{
|
||||
return vtrn1q_f32(r1, r0); // ar -ai br -bi
|
||||
}
|
||||
//Complex double
|
||||
inline float64x2_t operator()(float64x2_t in, float64x2_t ret){
|
||||
inline float64x2_t operator()(float64x2_t in){
|
||||
// a ib -> b -ia
|
||||
float64x2_t tmp;
|
||||
tmp = vnegq_f64(in);
|
||||
@ -338,7 +338,7 @@ struct TimesMinusI{
|
||||
|
||||
struct TimesI{
|
||||
//Complex single
|
||||
inline float32x4_t operator()(float32x4_t in, float32x4_t ret){
|
||||
inline float32x4_t operator()(float32x4_t in){
|
||||
// ar ai br bi -> -ai ar -bi br
|
||||
float32x4_t r0, r1;
|
||||
r0 = vnegq_f32(in); // -ar -ai -br -bi
|
||||
@ -346,7 +346,7 @@ struct TimesI{
|
||||
return vtrn1q_f32(r1, in); // -ai ar -bi br
|
||||
}
|
||||
//Complex double
|
||||
inline float64x2_t operator()(float64x2_t in, float64x2_t ret){
|
||||
inline float64x2_t operator()(float64x2_t in){
|
||||
// a ib -> -b ia
|
||||
float64x2_t tmp;
|
||||
tmp = vnegq_f64(in);
|
||||
|
@ -43,7 +43,7 @@ class GeneralLocalStencilView {
|
||||
int _npoints; // Move to template param?
|
||||
GeneralStencilEntry* _entries_p;
|
||||
|
||||
accelerator_inline GeneralStencilEntry * GetEntry(int point,int osite) {
|
||||
accelerator_inline GeneralStencilEntry * GetEntry(int point,int osite) const {
|
||||
return & this->_entries_p[point+this->_npoints*osite];
|
||||
}
|
||||
|
||||
@ -79,60 +79,60 @@ public:
|
||||
this->_entries.resize(npoints* osites);
|
||||
this->_entries_p = &_entries[0];
|
||||
|
||||
thread_for(site, osites, {
|
||||
Coordinate Coor;
|
||||
Coordinate NbrCoor;
|
||||
|
||||
Coordinate Coor;
|
||||
Coordinate NbrCoor;
|
||||
for(Integer site=0;site<osites;site++){
|
||||
for(Integer ii=0;ii<npoints;ii++){
|
||||
Integer lex = site*npoints+ii;
|
||||
GeneralStencilEntry SE;
|
||||
////////////////////////////////////////////////
|
||||
// Outer index of neighbour Offset calculation
|
||||
////////////////////////////////////////////////
|
||||
grid->oCoorFromOindex(Coor,site);
|
||||
for(int d=0;d<Coor.size();d++){
|
||||
int rd = grid->_rdimensions[d];
|
||||
NbrCoor[d] = (Coor[d] + shifts[ii][d] + rd )%rd;
|
||||
for(Integer ii=0;ii<npoints;ii++){
|
||||
Integer lex = site*npoints+ii;
|
||||
GeneralStencilEntry SE;
|
||||
////////////////////////////////////////////////
|
||||
// Outer index of neighbour Offset calculation
|
||||
////////////////////////////////////////////////
|
||||
grid->oCoorFromOindex(Coor,site);
|
||||
for(int d=0;d<Coor.size();d++){
|
||||
int rd = grid->_rdimensions[d];
|
||||
NbrCoor[d] = (Coor[d] + shifts[ii][d] + rd )%rd;
|
||||
}
|
||||
SE._offset = grid->oIndexReduced(NbrCoor);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Inner index permute calculation
|
||||
// Simpler version using icoor calculation
|
||||
////////////////////////////////////////////////
|
||||
SE._permute =0;
|
||||
for(int d=0;d<Coor.size();d++){
|
||||
|
||||
int fd = grid->_fdimensions[d];
|
||||
int rd = grid->_rdimensions[d];
|
||||
int ly = grid->_simd_layout[d];
|
||||
|
||||
assert((ly==1)||(ly==2));
|
||||
|
||||
int shift = (shifts[ii][d]+fd)%fd; // make it strictly positive 0.. L-1
|
||||
int x = Coor[d]; // x in [0... rd-1] as an oSite
|
||||
|
||||
int permute_dim = grid->PermuteDim(d);
|
||||
int permute_slice=0;
|
||||
if(permute_dim){
|
||||
int num = shift%rd; // Slice within dest osite cell of slice zero
|
||||
int wrap = shift/rd; // Number of osite local volume cells crossed through
|
||||
// x+num < rd dictates whether we are in same permute state as slice 0
|
||||
if ( x< rd-num ) permute_slice=wrap;
|
||||
else permute_slice=(wrap+1)%ly;
|
||||
}
|
||||
if ( permute_slice ) {
|
||||
int ptype =grid->PermuteType(d);
|
||||
uint8_t mask =0x1<<ptype;
|
||||
SE._permute |= mask;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
// Store in look up table
|
||||
////////////////////////////////////////////////
|
||||
this->_entries[lex] = SE;
|
||||
}
|
||||
SE._offset = grid->oIndexReduced(NbrCoor);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Inner index permute calculation
|
||||
// Simpler version using icoor calculation
|
||||
////////////////////////////////////////////////
|
||||
SE._permute =0;
|
||||
for(int d=0;d<Coor.size();d++){
|
||||
|
||||
int fd = grid->_fdimensions[d];
|
||||
int rd = grid->_rdimensions[d];
|
||||
int ly = grid->_simd_layout[d];
|
||||
|
||||
assert((ly==1)||(ly==2));
|
||||
|
||||
int shift = (shifts[ii][d]+fd)%fd; // make it strictly positive 0.. L-1
|
||||
int x = Coor[d]; // x in [0... rd-1] as an oSite
|
||||
|
||||
int permute_dim = grid->PermuteDim(d);
|
||||
int permute_slice=0;
|
||||
if(permute_dim){
|
||||
int num = shift%rd; // Slice within dest osite cell of slice zero
|
||||
int wrap = shift/rd; // Number of osite local volume cells crossed through
|
||||
// x+num < rd dictates whether we are in same permute state as slice 0
|
||||
if ( x< rd-num ) permute_slice=wrap;
|
||||
else permute_slice=(wrap+1)%ly;
|
||||
}
|
||||
if ( permute_slice ) {
|
||||
int ptype =grid->PermuteType(d);
|
||||
uint8_t mask =grid->Nsimd() >> (ptype + 1);
|
||||
SE._permute |= mask;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
// Store in look up table
|
||||
////////////////////////////////////////////////
|
||||
this->_entries[lex] = SE;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include <Grid/stencil/SimpleCompressor.h> // subdir aggregate
|
||||
#include <Grid/stencil/Lebesgue.h> // subdir aggregate
|
||||
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Must not lose sight that goal is to be able to construct really efficient
|
||||
@ -339,8 +340,8 @@ public:
|
||||
// Vectors that live on the symmetric heap in case of SHMEM
|
||||
// These are used; either SHM objects or refs to the above symmetric heap vectors
|
||||
// depending on comms target
|
||||
Vector<cobj *> u_simd_send_buf;
|
||||
Vector<cobj *> u_simd_recv_buf;
|
||||
std::vector<cobj *> u_simd_send_buf;
|
||||
std::vector<cobj *> u_simd_recv_buf;
|
||||
|
||||
int u_comm_offset;
|
||||
int _unified_buffer_size;
|
||||
@ -348,7 +349,7 @@ public:
|
||||
////////////////////////////////////////
|
||||
// Stencil query
|
||||
////////////////////////////////////////
|
||||
#ifdef SHM_FAST_PATH
|
||||
#if 1
|
||||
inline int SameNode(int point) {
|
||||
|
||||
int dimension = this->_directions[point];
|
||||
@ -451,7 +452,6 @@ public:
|
||||
else if ( this->fullDirichlet ) DslashLogDirichlet();
|
||||
else DslashLogFull();
|
||||
acceleratorCopySynchronise();
|
||||
// Everyone agrees we are all done
|
||||
_grid->StencilBarrier();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@ -540,6 +540,7 @@ public:
|
||||
compress.Point(point);
|
||||
HaloGatherDir(source,compress,point,face_idx);
|
||||
}
|
||||
accelerator_barrier();
|
||||
face_table_computed=1;
|
||||
assert(u_comm_offset==_unified_buffer_size);
|
||||
|
||||
@ -665,11 +666,9 @@ public:
|
||||
for(int i=0;i<mm.size();i++){
|
||||
decompressor::MergeFace(decompress,mm[i]);
|
||||
}
|
||||
if ( mm.size() ) acceleratorFenceComputeStream();
|
||||
for(int i=0;i<dd.size();i++){
|
||||
decompressor::DecompressFace(decompress,dd[i]);
|
||||
}
|
||||
if ( dd.size() ) acceleratorFenceComputeStream();
|
||||
}
|
||||
////////////////////////////////////////
|
||||
// Set up routines
|
||||
@ -707,6 +706,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << GridLogDebug << "BuildSurfaceList size is "<<surface_list.size()<<std::endl;
|
||||
}
|
||||
/// Introduce a block structure and switch off comms on boundaries
|
||||
void DirichletBlock(const Coordinate &dirichlet_block)
|
||||
@ -1368,10 +1368,11 @@ public:
|
||||
int recv_from_rank;
|
||||
int xmit_to_rank;
|
||||
int shm_send=0;
|
||||
int shm_recv=0;
|
||||
|
||||
_grid->ShiftedRanks(dimension,nbr_proc,xmit_to_rank,recv_from_rank);
|
||||
#ifdef SHM_FAST_PATH
|
||||
#warning STENCIL SHM FAST PATH SELECTED
|
||||
int shm_recv=0;
|
||||
// shm == receive pointer if offnode
|
||||
// shm == Translate[send pointer] if on node -- my view of his send pointer
|
||||
cobj *shm = (cobj *) _grid->ShmBufferTranslate(recv_from_rank,sp);
|
||||
@ -1404,7 +1405,6 @@ public:
|
||||
acceleratorMemSet(rp,0,bytes); // Zero prefill comms buffer to zero
|
||||
}
|
||||
int do_send = (comms_send|comms_partial_send) && (!shm_send );
|
||||
int do_recv = (comms_send|comms_partial_send) && (!shm_recv );
|
||||
AddPacket((void *)sp,(void *)rp,
|
||||
xmit_to_rank,do_send,
|
||||
recv_from_rank,do_send,
|
||||
|
@ -73,6 +73,16 @@ vobj coalescedReadPermute(const vobj & __restrict__ vec,int ptype,int doperm,int
|
||||
return vec;
|
||||
}
|
||||
}
|
||||
//'perm_mask' acts as a bitmask
|
||||
template<class vobj> accelerator_inline
|
||||
vobj coalescedReadGeneralPermute(const vobj & __restrict__ vec,int perm_mask,int nd,int lane=0)
|
||||
{
|
||||
auto obj = vec, tmp = vec;
|
||||
for (int d=0;d<nd;d++)
|
||||
if (perm_mask & (0x1 << d)) { permute(obj,tmp,d); tmp=obj;}
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<class vobj> accelerator_inline
|
||||
void coalescedWrite(vobj & __restrict__ vec,const vobj & __restrict__ extracted,int lane=0)
|
||||
{
|
||||
@ -83,7 +93,7 @@ void coalescedWriteNonTemporal(vobj & __restrict__ vec,const vobj & __restrict__
|
||||
{
|
||||
vstream(vec, extracted);
|
||||
}
|
||||
#else
|
||||
#else //==GRID_SIMT
|
||||
|
||||
|
||||
//#ifndef GRID_SYCL
|
||||
@ -166,6 +176,14 @@ typename vobj::scalar_object coalescedReadPermute(const vobj & __restrict__ vec,
|
||||
return extractLane(plane,vec);
|
||||
}
|
||||
template<class vobj> accelerator_inline
|
||||
typename vobj::scalar_object coalescedReadGeneralPermute(const vobj & __restrict__ vec,int perm_mask,int nd,int lane=acceleratorSIMTlane(vobj::Nsimd()))
|
||||
{
|
||||
int plane = lane;
|
||||
for (int d=0;d<nd;d++)
|
||||
plane = (perm_mask & (0x1 << d)) ? plane ^ (vobj::Nsimd() >> (d + 1)) : plane;
|
||||
return extractLane(plane,vec);
|
||||
}
|
||||
template<class vobj> accelerator_inline
|
||||
void coalescedWrite(vobj & __restrict__ vec,const typename vobj::scalar_object & __restrict__ extracted,int lane=acceleratorSIMTlane(vobj::Nsimd()))
|
||||
{
|
||||
insertLane(lane,vec,extracted);
|
||||
|
@ -66,13 +66,61 @@ template<class vtype,int N> accelerator_inline iMatrix<vtype,N> Ta(const iMatrix
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype> accelerator_inline iScalar<vtype> SpTa(const iScalar<vtype>&r)
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal = SpTa(r._internal);
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N> accelerator_inline iVector<vtype,N> SpTa(const iVector<vtype,N>&r)
|
||||
{
|
||||
iVector<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
ret._internal[i] = SpTa(r._internal[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
accelerator_inline iMatrix<vtype,N> SpTa(const iMatrix<vtype,N> &arg)
|
||||
{
|
||||
// Generalises Ta to Sp2n
|
||||
// Applies the following projections
|
||||
// P_{antihermitian} P_{antihermitian-Sp-algebra} P_{traceless}
|
||||
// where the ordering matters
|
||||
// P_{traceless} subtracts the trace
|
||||
// P_{antihermitian-Sp-algebra} provides the block structure of the algebra based on U = exp(T) i.e. anti-hermitian generators
|
||||
// P_{antihermitian} does in-adj(in) / 2
|
||||
iMatrix<vtype,N> ret(arg);
|
||||
double factor = (1.0/(double)N);
|
||||
vtype nrm;
|
||||
nrm = 0.5;
|
||||
|
||||
ret = arg - (trace(arg)*factor);
|
||||
|
||||
for(int c1=0;c1<N/2;c1++)
|
||||
{
|
||||
for(int c2=0;c2<N/2;c2++)
|
||||
{
|
||||
ret._internal[c1][c2] = nrm*(conjugate(ret._internal[c1+N/2][c2+N/2]) + ret._internal[c1][c2]); // new[up-left] = old[up-left]+old*[down-right]
|
||||
ret._internal[c1][c2+N/2] = nrm*(ret._internal[c1][c2+N/2] - conjugate(ret._internal[c1+N/2][c2])); // new[up-right] = old[up-right]-old*[down-left]
|
||||
}
|
||||
for(int c2=N/2;c2<N;c2++)
|
||||
{
|
||||
ret._internal[c1+N/2][c2-N/2] = -conjugate(ret._internal[c1][c2]); // reconstructs lower blocks
|
||||
ret._internal[c1+N/2][c2] = conjugate(ret._internal[c1][c2-N/2]); // from upper blocks
|
||||
}
|
||||
}
|
||||
|
||||
ret = (ret - adj(ret))*0.5;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// ProjectOnGroup function for scalar, vector, matrix
|
||||
// Projects on orthogonal, unitary group
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
template<class vtype> accelerator_inline iScalar<vtype> ProjectOnGroup(const iScalar<vtype>&r)
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
@ -90,10 +138,12 @@ template<class vtype,int N> accelerator_inline iVector<vtype,N> ProjectOnGroup(c
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
accelerator_inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
||||
{
|
||||
typedef typename iMatrix<vtype,N>::scalar_type scalar;
|
||||
// need a check for the group type?
|
||||
iMatrix<vtype,N> ret(arg);
|
||||
vtype nrm;
|
||||
vtype inner;
|
||||
scalar one(1.0);
|
||||
for(int c1=0;c1<N;c1++){
|
||||
|
||||
// Normalises row c1
|
||||
@ -102,7 +152,7 @@ accelerator_inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
||||
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
|
||||
|
||||
nrm = sqrt(inner);
|
||||
nrm = 1.0/nrm;
|
||||
nrm = one/nrm;
|
||||
for(int c2=0;c2<N;c2++)
|
||||
ret._internal[c1][c2]*= nrm;
|
||||
|
||||
@ -127,7 +177,7 @@ accelerator_inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
||||
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
|
||||
|
||||
nrm = sqrt(inner);
|
||||
nrm = 1.0/nrm;
|
||||
nrm = one/nrm;
|
||||
for(int c2=0;c2<N;c2++)
|
||||
ret._internal[c1][c2]*= nrm;
|
||||
}
|
||||
@ -135,6 +185,85 @@ accelerator_inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// re-do for sp2n
|
||||
|
||||
// Ta cannot be defined here for Sp2n because I need the generators from the Sp class
|
||||
// It is defined in gauge impl types
|
||||
|
||||
template<class vtype> accelerator_inline iScalar<vtype> ProjectOnSpGroup(const iScalar<vtype>&r)
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal = ProjectOnSpGroup(r._internal);
|
||||
return ret;
|
||||
}
|
||||
template<class vtype,int N> accelerator_inline iVector<vtype,N> ProjectOnSpGroup(const iVector<vtype,N>&r)
|
||||
{
|
||||
iVector<vtype,N> ret;
|
||||
for(int i=0;i<N;i++){
|
||||
ret._internal[i] = ProjectOnSpGroup(r._internal[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// int N is 2n in Sp(2n)
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
accelerator_inline iMatrix<vtype,N> ProjectOnSpGroup(const iMatrix<vtype,N> &arg)
|
||||
{
|
||||
// need a check for the group type?
|
||||
iMatrix<vtype,N> ret(arg);
|
||||
vtype nrm;
|
||||
vtype inner;
|
||||
|
||||
for(int c1=0;c1<N/2;c1++)
|
||||
{
|
||||
|
||||
for (int b=0; b<c1; b++) // remove the b-rows from U_c1
|
||||
{
|
||||
decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
|
||||
decltype(ret._internal[b][b]*ret._internal[b][b]) prn;
|
||||
zeroit(pr);
|
||||
zeroit(prn);
|
||||
|
||||
for(int c=0; c<N; c++)
|
||||
{
|
||||
pr += conjugate(ret._internal[c1][c])*ret._internal[b][c]; // <U_c1 | U_b >
|
||||
prn += conjugate(ret._internal[c1][c])*ret._internal[b+N/2][c]; // <U_c1 | U_{b+N} >
|
||||
}
|
||||
|
||||
|
||||
for(int c=0; c<N; c++)
|
||||
{
|
||||
ret._internal[c1][c] -= (conjugate(pr) * ret._internal[b][c] + conjugate(prn) * ret._internal[b+N/2][c] ); // U_c1 -= ( <U_c1 | U_b > U_b + <U_c1 | U_{b+N} > U_{b+N} )
|
||||
}
|
||||
}
|
||||
|
||||
zeroit(inner);
|
||||
for(int c2=0;c2<N;c2++)
|
||||
{
|
||||
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
|
||||
}
|
||||
|
||||
nrm = sqrt(inner);
|
||||
nrm = 1.0/nrm;
|
||||
for(int c2=0;c2<N;c2++)
|
||||
{
|
||||
ret._internal[c1][c2]*= nrm;
|
||||
}
|
||||
|
||||
for(int c2=0;c2<N/2;c2++)
|
||||
{
|
||||
ret._internal[c1+N/2][c2+N/2] = conjugate(ret._internal[c1][c2]); // down right in the new matrix = (up-left)* of the old matrix
|
||||
}
|
||||
|
||||
for(int c2=N/2;c2<N;c2++)
|
||||
{
|
||||
ret._internal[c1+N/2][c2-N/2] = -conjugate(ret._internal[c1][c2]);; // down left in the new matrix = -(up-right)* of the old
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user