本文整理汇总了C++中communicator类的典型用法代码示例。如果您正苦于以下问题:C++ communicator类的具体用法?C++ communicator怎么用?C++ communicator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了communicator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gather
static void gather(const communicator& comm, const std::vector<T>& in, std::vector< std::vector<T> >& out, int root)
{
std::vector<int> counts(comm.size());
Collectives<int,void*>::gather(comm, (int) in.size(), counts, root);
std::vector<int> offsets(comm.size(), 0);
for (unsigned i = 1; i < offsets.size(); ++i)
offsets[i] = offsets[i-1] + counts[i-1];
std::vector<T> buffer(offsets.back() + counts.back());
MPI_Gatherv(Datatype::address(const_cast<T&>(in[0])),
in.size(),
Datatype::datatype(),
Datatype::address(buffer[0]),
&counts[0],
&offsets[0],
Datatype::datatype(),
root, comm);
out.resize(comm.size());
size_t cur = 0;
for (unsigned i = 0; i < (unsigned)comm.size(); ++i)
{
out[i].reserve(counts[i]);
for (unsigned j = 0; j < (unsigned)counts[i]; ++j)
out[i].push_back(buffer[cur++]);
}
}
示例2: operator
void operator()(const communicator& comm, const config& cfg,
T alpha, MatrixA& A, MatrixB& B, T beta, MatrixC& C)
{
using namespace matrix_constants;
len_type m = (Mat == MAT_A ? A.length(0) : Mat == MAT_B ? B.length(0) : C.length(0));
len_type n = (Mat == MAT_A ? A.length(1) : Mat == MAT_B ? B.length(1) : C.length(1));
if (!rscat)
{
if (comm.master())
{
scat_buffer = Pool.allocate<stride_type>(2*m + 2*n);
rscat = scat_buffer.get<stride_type>();
}
comm.broadcast(rscat);
cscat = rscat+m;
rbs = cscat+n;
cbs = rbs+m;
}
matrify_and_run<Mat>(*this, comm, cfg, alpha, A, B, beta, C);
}
示例3: broadcast_test
void
broadcast_test(const communicator& comm, const T& bc_value,
const char* kind, int root = -1)
{
if (root == -1) {
for (root = 0; root < comm.size(); ++root)
broadcast_test(comm, bc_value, kind, root);
} else {
using boost::mpi::broadcast;
T value;
if (comm.rank() == root) {
value = bc_value;
std::cout << "Broadcasting " << kind << " from root " << root << "...";
std::cout.flush();
}
broadcast(comm, value, root);
BOOST_CHECK(value == bc_value);
if (comm.rank() == root && value == bc_value)
std::cout << "OK." << std::endl;
}
(comm.barrier)();
}
示例4: gather_test
void
gather_test(const communicator& comm, Generator generator,
const char* kind, int root = -1)
{
typedef typename Generator::result_type value_type;
value_type value = generator(comm.rank());
if (root == -1) {
for (root = 0; root < comm.size(); ++root)
gather_test(comm, generator, kind, root);
} else {
using boost::mpi::gather;
std::vector<value_type> values;
if (comm.rank() == root) {
std::cout << "Gathering " << kind << " from root "
<< root << "..." << std::endl;
}
gather(comm, value, values, root);
if (comm.rank() == root) {
std::vector<value_type> expected_values;
for (int p = 0; p < comm.size(); ++p)
expected_values.push_back(generator(p));
BOOST_CHECK(values == expected_values);
} else {
BOOST_CHECK(values.empty());
}
}
(comm.barrier)();
}
示例5: block_scatter
void block_scatter(const communicator& comm, tensor_matrix<T>& A,
stride_type* rscat, len_type MB, stride_type* rbs,
stride_type* cscat, len_type NB, stride_type* cbs)
{
len_type m = A.length(0);
len_type n = A.length(1);
len_type first, last;
std::tie(first, last, std::ignore) = comm.distribute_over_threads(m, MB);
A.length(0, last-first);
A.shift(0, first);
A.fill_block_scatter(0, rscat+first, MB, rbs+first/MB);
A.shift(0, -first);
A.length(0, m);
std::tie(first, last, std::ignore) = comm.distribute_over_threads(n, NB);
A.length(1, last-first);
A.shift(1, first);
A.fill_block_scatter(1, cscat+first, NB, cbs+first/NB);
A.shift(1, -first);
A.length(1, n);
comm.barrier();
}
示例6: scatter_test
void
scatter_test(const communicator& comm, Generator generator,
const char* kind, int root = -1)
{
typedef typename Generator::result_type value_type;
if (root == -1) {
for (root = 0; root < comm.size(); ++root)
scatter_test(comm, generator, kind, root);
} else {
using boost::mpi::scatter;
value_type value;
if (comm.rank() == root) {
std::vector<value_type> values;
for (int p = 0; p < comm.size(); ++p)
values.push_back(generator(p));
if (comm.rank() == root) {
std::cout << "Scattering " << kind << " from root " << root << "...";
std::cout.flush();
}
scatter(comm, values, value, root);
} else {
scatter(comm, value, root);
}
BOOST_CHECK(value == generator(comm.rank()));
}
(comm.barrier)();
}
示例7: broadcast
//---------
static void broadcast(communicator c, A &a, int root) {
check_is_contiguous(a);
auto sh = a.shape();
MPI_Bcast(&sh[0], sh.size(), mpi_datatype<typename decltype(sh)::value_type>::invoke(), root, c.get());
if (c.rank() != root) a.resize(sh);
MPI_Bcast(a.data_start(), a.domain().number_of_elements(), D(), root, c.get());
}
示例8: mpi_reduce
std::vector<T> mpi_reduce(std::vector<T> const &a, communicator c, int root, bool all, MPI_Op op, std::true_type) {
std::vector<T> b(a.size());
if (!all)
MPI_Reduce((void *)a.data(), b.data(), a.size(), mpi_datatype<T>(), op, root, c.get());
else
MPI_Allreduce((void *)a.data(), b.data(), a.size(), mpi_datatype<T>(), op, c.get());
return b;
}
示例9: REQUIRES_IS_BASIC
template <typename T> REQUIRES_IS_BASIC(T, T) mpi_reduce(T a, communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) {
T b;
auto d = datatype<T>();
if (!all)
MPI_Reduce(&a, &b, 1, d, op, root, c.get());
else
MPI_Allreduce(&a, &b, 1, d, op, c.get());
return b;
}
示例10: gather
void
gather(const communicator& comm, const T* in_values, int n,
std::vector<T>& out_values, int root)
{
if (comm.rank() == root) {
out_values.resize(comm.size() * n);
::boost::mpi::gather(comm, in_values, n, &out_values[0], root);
}
else
::boost::mpi::gather(comm, in_values, n, root);
}
示例11: gather_impl
void
gather_impl(const communicator& comm, const T* in_values, int n,
T* out_values, int root, mpl::false_)
{
int tag = environment::collectives_tag();
int size = comm.size();
for (int src = 0; src < size; ++src) {
if (src == root)
std::copy(in_values, in_values + n, out_values + n * src);
else
comm.recv(src, tag, out_values + n * src, n);
}
}
示例12: gather
object gather(const communicator& comm, object value, int root)
{
if (comm.rank() == root) {
std::vector<object> values;
boost::mpi::gather(comm, value, values, root);
boost::python::list l;
for (int i = 0; i < comm.size(); ++i)
l.append(values[i]);
return boost::python::tuple(l);
} else {
boost::mpi::gather(comm, value, root);
return object();
}
}
示例13: scatter
object scatter(const communicator& comm, object values, int root)
{
object result;
if (comm.rank() == root) {
std::vector<object> values_vec(comm.size());
object iterator = object(handle<>(PyObject_GetIter(values.ptr())));
for (int i = 0; i < comm.size(); ++i)
values_vec[i] = object(handle<>(PyIter_Next(iterator.ptr())));
boost::mpi::scatter(comm, values_vec, result, root);
} else {
boost::mpi::scatter(comm, result, root);
}
return result;
}
示例14: DuplicateError
int espresso::esutil::Collectives::locateItem(bool here, int controller, communicator world) {
int node = here ? world.rank() : UniqueReduce::NotHere;
if (world.rank() != controller) {
reduce(world, node, UniqueReduce(), controller);
return None;
}
else {
int owner;
reduce(world, node, owner, UniqueReduce(), controller);
if (owner == UniqueReduce::Duplicate) {
throw DuplicateError();
}
return owner;
}
}
示例15: all_to_all
object all_to_all(const communicator& comm, object in_values)
{
// Build input values
std::vector<object> in_values_vec(comm.size());
object iterator = object(handle<>(PyObject_GetIter(in_values.ptr())));
for (int i = 0; i < comm.size(); ++i)
in_values_vec[i] = object(handle<>(PyIter_Next(iterator.ptr())));
std::vector<object> out_values_vec(comm.size());
boost::mpi::all_to_all(comm, in_values_vec, out_values_vec);
boost::python::list l;
for (int i = 0; i < comm.size(); ++i)
l.append(out_values_vec[i]);
return boost::python::tuple(l);
}