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


C++ list_type::emplace_back方法代码示例

本文整理汇总了C++中list_type::emplace_back方法的典型用法代码示例。如果您正苦于以下问题:C++ list_type::emplace_back方法的具体用法?C++ list_type::emplace_back怎么用?C++ list_type::emplace_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在list_type的用法示例。


在下文中一共展示了list_type::emplace_back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lb_migrate_points

static void lb_migrate_points(const par::communicator& comm, list_type& pl, LBData& lbd)
{
        const unsigned int num_proc = comm.size();
        const unsigned int dim = point_type::dim;

        // Sendcounts should be already filled
        // Perform alltoall for recvcounts from sendcounts
        lbd.recvcounts.resize(num_proc);
        comm.alltoall(lbd.sendcounts.data(), 1, lbd.recvcounts.data(), 1);

        // Resize the send buffer
        lbd.send.resize(pl.size() * dim);

        // Pack up the send buffer
        {
                unsigned int i = 0;
                for (const point_type& p : pl)
                        for (unsigned int d=0; d<dim; d++, i++)
                                lbd.send[i] = p[d];
        }

        // Offsets in memory (for alltoallv)
        lbd.sdispls[0] = 0;
        for (unsigned int i=1; i<num_proc; i++)
                lbd.sdispls[i] = lbd.sdispls[i-1] + lbd.sendcounts[i-1];

        lbd.rdispls[0] = 0;
        for (unsigned int i=1; i<num_proc; i++)
                lbd.rdispls[i] = lbd.rdispls[i-1] + lbd.recvcounts[i-1];

        // Create receive buffer
        const int total_recv = std::accumulate(lbd.recvcounts.begin(), lbd.recvcounts.end(), 0);
        lbd.recv.resize(total_recv);

        // Communicate points (alltoallv)
        comm.alltoallv(lbd.send.data(), lbd.sendcounts.data(), lbd.sdispls.data(),
                       lbd.recv.data(), lbd.recvcounts.data(), lbd.rdispls.data());

        // Clear out current points and reload from the receive buffer
        pl.clear();
        for (unsigned int i=0; i<lbd.recv.size(); i+=dim)
                pl.emplace_back(point_type(lbd.recv[i], lbd.recv[i+1]));
}
开发者ID:jdahm,项目名称:libcgeom,代码行数:43,代码来源:load_balance.cpp

示例2: halfcomm


//.........这里部分代码省略.........

        list_type other;
        list_type::iterator pit = std::find_if(pl.begin(), pl.end(),
                                               [midpt,dimen](const point_type& p)
                                               { return p[dimen] >= midpt; });
        list_type::size_type offset;
        if (my_rank < rank_midpt) {
                other.splice(other.begin(), pl, pit, pl.end());
                offset = pl.size();
        }
        else {
                other.splice(other.begin(), pl, pl.begin(), pit);
                offset = other.size();
        }
        // std::cout << "pl: ";
        // for (auto& p : pl) std::cout << p << " ";
        // std::cout << std::endl;
        // std::cout << "other: ";
        // for (auto& p : other) std::cout << p << " ";
        // std::cout << std::endl;
        // std::cout << "offset = " << offset << std::endl;
        lbd.send.resize(other.size() * dim);
        {
                list_type::iterator it=other.begin();
                list_type::size_type i = 0;
                while (it != other.end()) {
                        const point_type& p = *it;
                        for (unsigned int d=0; d<dim; d++, i++)
                                lbd.send[i] = p[d];
                        other.erase(it++);
                }
        }
        // std::cout << "send: ";
        // for (auto& p : lbd.send) std::cout << p << " ";
        // std::cout << std::endl;

        // std::cout << "midpt = " << midpt << std::endl;
        // std::cout << "rank_midpt = " << rank_midpt << std::endl;
        // std::cout << "this_offset = " << this_offset << std::endl;

        // Pack up points
        lbd.sendcounts.resize(num_proc);

        // Zero out
        std::fill(lbd.sendcounts.begin(), lbd.sendcounts.end(), 0);

        if (my_rank < rank_midpt) {
                // Left side
                for (unsigned int i=offset; i<orig_num_point; i++) {
                        const unsigned int inc = (i-offset) % (num_proc - rank_midpt);
                        lbd.sendcounts[rank_midpt + inc] += dim;
                }
        }
        else {
                // Right side
                for (unsigned int i=0; i<offset; i++) {
                        lbd.sendcounts[i % rank_midpt] += dim;
                }
        }

        // std::cout << "sendcounts: ";
        // for (auto& p : lbd.sendcounts) std::cout << p << " ";
        // std::cout << std::endl;

        // alltoall recvcounts
        comm.alltoall(lbd.sendcounts.data(), 1, lbd.recvcounts.data(), 1);

        // std::cout << "recvcounts: ";
        // for (auto& p : lbd.recvcounts) std::cout << p << " ";
        // std::cout << std::endl;

        // Offsets in memory (for alltoallv)
        lbd.sdispls[0] = 0;
        for (unsigned int i=1; i<num_proc; i++)
                lbd.sdispls[i] = lbd.sdispls[i-1] + lbd.sendcounts[i-1];

        lbd.rdispls[0] = 0;
        for (unsigned int i=1; i<num_proc; i++)
                lbd.rdispls[i] = lbd.rdispls[i-1] + lbd.recvcounts[i-1];

        // Create receive buffer
        const int total_recv = std::accumulate(lbd.recvcounts.begin(), lbd.recvcounts.end(), 0);
        lbd.recv.resize(total_recv);

        // Communicate points (alltoallv)
        comm.alltoallv(lbd.send.data(), lbd.sendcounts.data(), lbd.sdispls.data(),
                       lbd.recv.data(), lbd.recvcounts.data(), lbd.rdispls.data());

        // Clear out current points and reload from the receive buffer
        for (unsigned int i=0; i<lbd.recv.size(); i+=dim)
                pl.emplace_back(point_type(lbd.recv[i], lbd.recv[i+1]));

        // std::cout << "points: ";
        // for (auto& p : pl) std::cout << p << " ";
        // std::cout << std::endl;
        // std::cout << "--------------" << std::endl;

        par::communicator halfcomm(comm, my_rank < rank_midpt);
        rcb1d_recurse(halfcomm, dimen, pl, lbd);
}
开发者ID:jdahm,项目名称:libcgeom,代码行数:101,代码来源:load_balance.cpp


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