本文整理汇总了C++中mpi::Intracomm::Reduce方法的典型用法代码示例。如果您正苦于以下问题:C++ Intracomm::Reduce方法的具体用法?C++ Intracomm::Reduce怎么用?C++ Intracomm::Reduce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpi::Intracomm
的用法示例。
在下文中一共展示了Intracomm::Reduce方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reduce
/*
* Reduce (add) distributions from multiple MPI processors.
*/
void Distribution::reduce(MPI::Intracomm& communicator, int root)
{
long* totHistogram = new long[nBin_];
communicator.Reduce(histogram_.cArray(), totHistogram, nBin_, MPI::LONG, MPI::SUM, root);
if (communicator.Get_rank() == root) {
for (int i=0; i < nBin_; ++i) {
histogram_[i] = totHistogram[i];
}
} else {
for (int i=0; i < nBin_; ++i) {
histogram_[i] = 0.0;
}
}
delete totHistogram;
long totSample;
communicator.Reduce(&nSample_, &totSample, 1, MPI::LONG, MPI::SUM, root);
if (communicator.Get_rank() == root) {
nSample_ = totSample;
} else {
nSample_ = 0;
}
long totReject;
communicator.Reduce(&nReject_, &totReject, 1, MPI::LONG, MPI::SUM, root);
if (communicator.Get_rank() == root) {
nReject_ = totReject;
} else {
nReject_ = 0;
}
}
示例2: computeNAtomTotal
/*
* Compute, store and return total number of atoms on all processors.
*/
void AtomStorage::computeNAtomTotal(MPI::Intracomm& communicator)
{
// If nAtomTotal is already set, do nothing and return.
// if (nAtomTotal_.isSet()) return;
int nAtomLocal = nAtom();
int nAtomTotal = 0;
communicator.Reduce(&nAtomLocal, &nAtomTotal, 1,
MPI::INT, MPI::SUM, 0);
if (communicator.Get_rank() !=0) {
nAtomTotal = 0;
}
nAtomTotal_.set(nAtomTotal);
}
示例3: resample_popsizes_mh
// Metropolis-Hastings population size resampling; not used anymore
void resample_popsizes_mh(ArgModel *model, const LocalTrees *trees,
bool sample_popsize_recomb, double heat) {
list<PopsizeConfigParam> &l = model->popsize_config.params;
double curr_like = sample_popsize_recomb ? calc_arg_prior(model, trees) :
calc_arg_prior_recomb_integrate(model, trees, NULL, NULL, NULL);
#ifdef ARGWEAVER_MPI
MPI::Intracomm *comm = model->mc3.group_comm;
int rank = comm->Get_rank();
comm->Reduce(rank == 0 ? MPI_IN_PLACE : &curr_like,
&curr_like, 1, MPI::DOUBLE, MPI_SUM, 0);
#endif
for (int rep=0; rep < model->popsize_config.numsample; rep++) {
int idx=0;
for (list<PopsizeConfigParam>::iterator it = l.begin();
it != l.end(); it++) {
curr_like =
resample_single_popsize_mh(model, trees, sample_popsize_recomb,
heat, it, curr_like, idx++);
}
}
}