本文整理汇总了C++中Environment::barrier方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::barrier方法的具体用法?C++ Environment::barrier怎么用?C++ Environment::barrier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::barrier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
double
twoSiteDMRG(Environment const& mpienv,
Hubbard& sites,
IQMPS& psi,
std::vector<IQMPO>const& Hs,
Sweeps const& sweeps,
Args const& args)
{
auto L = sites.N();
auto nSweeps = sweeps.nsweep();
psi.position(1);
mpienv.barrier();
std::vector<EnvironmentHandler<IQTensor>*> handlerLeft;
std::vector<EnvironmentHandler<IQTensor>*> handlerRight;
std::for_each(Hs.begin(), Hs.end(), [&] (IQMPO const& element) {
auto left = new EnvironmentHandler<IQTensor>(element, psi, Left, 0, false);
handlerLeft.push_back(left);
auto right = new EnvironmentHandler<IQTensor>(element, psi, Right, 3, false);
handlerRight.push_back(right);
});
mpienv.barrier();
auto forN = AutoMPO(sites); for(int j = 1; j <= L; ++j) { forN += 1,"Ntot",j; } MPOt<IQTensor> N(forN);
auto forSz = AutoMPO(sites); for(int j = 1; j <= L; ++j) { forSz += 1,"Sz",j; } MPOt<IQTensor> Sz(forSz);
double nVal = itensor::overlap(psi, N, psi);
double szVal = itensor::overlap(psi, Sz, psi);
std::cout << "L " << L << " N " << nVal << " Sz" << szVal << std::endl;
double lastExpec = 0;
double minExpec;
IQMPS minState;
std::for_each(Hs.begin(), Hs.end(), [&] (IQMPO const& element) { lastExpec += overlap(psi, element, psi); });
lastExpec = sum(mpienv, lastExpec);
if (mpienv.rank() == 0) {
printStatus(-1, 0, L, lastExpec, 0, szVal, nVal, maxM(psi));
double minExpec = lastExpec;
minState = psi;
}
vector<Direction> directions {Fromleft, Fromright};
for (int nS = 1; nS <= nSweeps; ++nS)
{
Args args;
args.add("Cutoff",sweeps.cutoff(nS));
args.add("Maxm",sweeps.maxm(nS));
args.add("Minm",sweeps.minm(nS));
args.add("Niter",sweeps.niter(nS));
args.add("Noise",sweeps.noise(nS));
for (Direction &dir : directions)
{
int start = dir==Fromleft?1:L-1;
int end = dir==Fromleft?L-1:1;
for (int i = start; dir == Fromleft ? i < end : i > end; dir == Fromleft ? i++ : i--)
{
IQTensor guess = psi.A(i) * psi.A(i+1);
std::vector<IQTensor> leftEn;
std::vector<IQTensor> rightEn;
std::vector<IQTensor> leftH;
std::vector<IQTensor> rightH;
std::for_each(handlerLeft.begin(), handlerLeft.end(),
[&] (EnvironmentHandler<IQTensor>* handler) {
leftEn.push_back(handler->currentElement());
});
std::for_each(handlerRight.begin(), handlerRight.end(),
[&] (EnvironmentHandler<IQTensor>* handler) {
rightEn.push_back(handler->currentElement());
});
std::for_each(Hs.begin(), Hs.end(), [&] (IQMPO const& H) {
leftH.push_back(H.A(i));
rightH.push_back(H.A(i+1));
});
LocalHSum<IQTensor> lop(leftH, rightH, leftEn, rightEn);
double expec = MPI_davidson(mpienv, lop, guess, args);
mpienv.barrier();
if (i == 1) { MPI_insertBond(mpienv, psi, i, Fromleft, guess, leftEn, leftH, rightH, rightEn, args); }
else if (i + 1 == L) { MPI_insertBond(mpienv, psi, i, Fromright, guess, leftEn, leftH, rightH, rightEn, args); }
else { MPI_insertBond(mpienv, psi, i, dir, guess, leftEn, leftH, rightH, rightEn, args); }
if (mpienv.rank() == 0)
{
double nVal = itensor::overlap(psi, N, psi);
double szVal = itensor::overlap(psi, Sz, psi);
printStatus(nS, i, L-i, expec, expec - lastExpec, szVal, nVal, maxM(psi));
//.........这里部分代码省略.........