13 #include "libmesh/communicator.h" 24 static constexpr
bool value =
false;
29 static constexpr
bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>
::value;
34 static constexpr
bool value =
false;
40 std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>
::value ||
41 std::is_same<T, std::string>::value || std::is_same<T, bool>::value;
51 ::mooseError(
"Cannot gather values of type ", MooseUtils::prettyCppType<T>());
54 typename std::enable_if<canDefaultGather<std::vector<T>>::value,
int>::type = 0>
64 typename std::enable_if<canStochasticGather<std::vector<std::vector<T>>>::value,
int>::type = 0>
68 std::vector<std::vector<T>> & val)
71 std::size_t num_local_vecs = val.size();
72 std::vector<std::size_t> val_sizes;
73 val_sizes.reserve(num_local_vecs);
74 std::size_t num_local_vals = 0;
75 for (
const auto &
v : val)
77 val_sizes.push_back(
v.size());
78 num_local_vals +=
v.size();
82 std::vector<T> val_exp;
83 val_exp.reserve(num_local_vals);
85 std::copy(
v.begin(),
v.end(), std::back_inserter(val_exp));
88 comm.
gather(root_id, val_sizes);
92 if (comm.
rank() == root_id)
94 val.resize(val_sizes.size());
95 std::size_t ind = num_local_vals;
96 for (std::size_t i = num_local_vecs; i < val_sizes.size(); ++i)
98 val[i].resize(val_sizes[i]);
99 std::move(val_exp.begin() + ind, val_exp.begin() + ind + val_sizes[i], val[i].begin());
106 template <
typename T>
110 std::vector<std::basic_string<T>> & val)
112 std::vector<std::basic_string<T>> val_gath = val;
114 if (comm.
rank() == root_id)
115 val = std::move(val_gath);
118 template <
typename A>
122 std::vector<bool, A> & val)
124 std::vector<unsigned short int> temp(val.size());
125 for (std::size_t i = 0; i < val.size(); ++i)
126 temp[i] = val[i] ? 1 : 0;
127 comm.
gather(root_id, temp);
128 if (comm.
rank() == root_id)
130 val.resize(temp.size());
131 for (std::size_t i = 0; i < temp.size(); ++i)
132 val[i] = temp[i] == 1;
139 template <
typename T>
143 ::mooseError(
"Cannot gather values of type ", MooseUtils::prettyCppType<T>());
145 template <
typename T,
146 typename std::enable_if<canDefaultGather<std::vector<T>>::value,
int>::type = 0>
154 typename std::enable_if<canStochasticGather<std::vector<std::vector<T>>>::value,
int>::type = 0>
159 std::size_t num_local_vecs = val.size();
160 std::vector<std::size_t> val_sizes;
161 val_sizes.reserve(num_local_vecs);
162 std::size_t num_local_vals = 0;
163 for (
const auto &
v : val)
165 val_sizes.push_back(
v.size());
166 num_local_vals +=
v.size();
170 std::vector<T> val_exp;
171 val_exp.reserve(num_local_vals);
173 std::copy(
v.begin(),
v.end(), std::back_inserter(val_exp));
180 val.resize(val_sizes.size());
182 for (std::size_t i = 0; i < val_sizes.size(); ++i)
184 val[i].resize(val_sizes[i]);
185 std::move(val_exp.begin() + ind, val_exp.begin() + ind + val_sizes[i], val[i].begin());
191 template <
typename T>
194 std::vector<std::basic_string<T>> & val)
199 template <
typename A>
203 std::vector<unsigned short int> temp(val.size());
204 for (std::size_t i = 0; i < val.size(); ++i)
205 temp[i] = val[i] ? 1 : 0;
207 val.resize(temp.size());
208 for (std::size_t i = 0; i < temp.size(); ++i)
209 val[i] = temp[i] == 1;
216 template <
typename T>
220 std::sort(values.begin(), values.end());
222 template <
typename T>
229 const std::size_t sz = values[0].size();
230 mooseAssert(std::find_if(values.begin(),
232 [&sz](
const std::vector<T> & val)
233 {
return val.size() != sz; }) == values.end(),
234 "All vectors must be same size to sort.");
236 std::vector<T> vals(values.size());
240 vals[
k] = values[
k][i];
243 values[
k][i] = std::move(vals[
k]);
257 template <
typename T>
258 std::vector<std::vector<T>>
261 const auto nelem = vec.size();
262 const auto nrow = row_major ? nelem / n : n;
263 const auto ncol = row_major ? n : nelem / n;
266 "Reshaping dimensions (", nrow,
", ", ncol,
") does not match vector size (", nelem,
").");
268 std::vector<std::vector<T>> mat(nrow, std::vector<T>(ncol));
272 const auto k = row_major ? (i * ncol +
j) : (
j * nrow + i);
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
processor_id_type rank() const
uint8_t processor_id_type
static const std::string v
IntRange< T > make_range(T beg, T end)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
static const std::string k
auto index_range(const T &sizable)