当前位置: 首页>>代码示例>>C++>>正文


C++ Environment::barrier方法代码示例

本文整理汇总了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));
//.........这里部分代码省略.........
开发者ID:lfrahm,项目名称:MOL,代码行数:101,代码来源:groundstatesearch.cpp


注:本文中的Environment::barrier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。