13#ifndef KASKADE_BDDC_COARSE_REDUCTION_HH
14#define KASKADE_BDDC_COARSE_REDUCTION_HH
22#ifdef KASKADE_HAVE_MPI
37 inline void allreduceCoarseSum(std::vector<double>& values,
38 int chunkLimit = std::numeric_limits<int>::max())
41 throw std::invalid_argument(
"coarse reduction chunk limit must be positive");
42 for (std::size_t offset = 0; offset < values.size();)
44 int const count =
static_cast<int>(std::min(values.size()-offset,
45 static_cast<std::size_t
>(chunkLimit)));
46 MPI_Allreduce(MPI_IN_PLACE,values.data()+offset,
count,MPI_DOUBLE,MPI_SUM,
61 template <
class Matrix>
62 void reduceCoarseMatrix(Matrix& matrix,
63 int chunkLimit = std::numeric_limits<int>::max())
65 std::vector<double> values;
66 for (
auto row = matrix.begin(); row != matrix.end(); ++row)
67 for (
auto entry = row->begin(); entry != row->end(); ++entry)
68 values.push_back((*entry)[0][0]);
69 allreduceCoarseSum(values,chunkLimit);
70 std::size_t position = 0;
71 for (
auto row = matrix.begin(); row != matrix.end(); ++row)
72 for (
auto entry = row->begin(); entry != row->end(); ++entry)
73 (*entry)[0][0] = values[position++];
82 template <
class Vector>
83 void reduceCoarseRhs(Vector& rhs,
84 int chunkLimit = std::numeric_limits<int>::max())
86 std::vector<double> values(rhs.size());
87 for (std::size_t i = 0; i < values.size(); ++i)
88 values[i] = rhs[i][0];
89 allreduceCoarseSum(values,chunkLimit);
90 for (std::size_t i = 0; i < values.size(); ++i)
91 rhs[i][0] = values[i];
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.