本文整理汇总了C++中boost::mpi::communicator::split方法的典型用法代码示例。如果您正苦于以下问题:C++ communicator::split方法的具体用法?C++ communicator::split怎么用?C++ communicator::split使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::mpi::communicator
的用法示例。
在下文中一共展示了communicator::split方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeAll_split
void TwoParticleGFContainer::computeAll_split(bool clearTerms, const boost::mpi::communicator & comm)
{
// split communicator
size_t ncomponents = NonTrivialElements.size();
size_t ncolors = std::min(int(comm.size()), int(NonTrivialElements.size()));
RealType color_size = 1.0*comm.size()/ncolors;
std::map<int,int> proc_colors;
std::map<int,int> elem_colors;
std::map<int,int> color_roots;
bool calc = false;
for (size_t p=0; p<comm.size(); p++) {
int color = int (1.0*p / color_size);
proc_colors[p] = color;
color_roots[color]=p;
}
for (size_t i=0; i<ncomponents; i++) {
int color = i*ncolors/ncomponents;
elem_colors[i] = color;
};
if (!comm.rank()) {
INFO("Splitting " << ncomponents << " components in " << ncolors << " communicators");
for (size_t i=0; i<ncomponents; i++)
INFO("2pgf " << i << " color: " << elem_colors[i] << " color_root: " << color_roots[elem_colors[i]]);
};
comm.barrier();
int comp = 0;
boost::mpi::communicator comm_split = comm.split(proc_colors[comm.rank()]);
for(std::map<IndexCombination4, boost::shared_ptr<TwoParticleGF> >::iterator iter = NonTrivialElements.begin(); iter != NonTrivialElements.end(); iter++, comp++) {
bool calc = (elem_colors[comp] == proc_colors[comm.rank()]);
if (calc) {
INFO("C" << elem_colors[comp] << "p" << comm.rank() << ": computing 2PGF for " << iter->first);
if (calc) static_cast<TwoParticleGF&>(*(iter->second)).compute(clearTerms, comm_split);
};
};
comm.barrier();
// distribute data
if (!comm.rank()) INFO_NONEWLINE("Distributing 2PGF container...");
comp = 0;
for(std::map<IndexCombination4, boost::shared_ptr<TwoParticleGF> >::iterator iter = NonTrivialElements.begin(); iter != NonTrivialElements.end(); iter++, comp++) {
int sender = color_roots[elem_colors[comp]];
TwoParticleGF& chi = *((iter)->second);
for (size_t p = 0; p<chi.parts.size(); p++) {
// if (comm.rank() == sender) INFO("P" << comm.rank() << " 2pgf " << p << " " << chi.parts[p]->NonResonantTerms.size());
boost::mpi::broadcast(comm, chi.parts[p]->NonResonantTerms, sender);
boost::mpi::broadcast(comm, chi.parts[p]->ResonantTerms, sender);
if (comm.rank() != sender) {
chi.setStatus(TwoParticleGF::Computed);
};
};
}
comm.barrier();
if (!comm.rank()) INFO("done.");
}