30 if (indices.size() != values.size())
31 throw std::runtime_error(
"Cannot sort two arrays of different lengths");
33 using T =
typename std::pair<typename U::value_type, typename V::value_type>;
34 std::vector<T> data(indices.size());
35 std::transform(indices.begin(), indices.end(), values.begin(), data.begin(),
36 [](
auto& idx,
auto& v) -> T {
41 std::sort(data.begin(), data.end());
42 auto it = std::unique(data.begin(), data.end(),
43 [](
auto& a,
auto& b) { return a.first == b.first; });
45 std::vector<typename U::value_type> indices_new;
46 std::vector<typename V::value_type> values_new;
47 indices_new.reserve(data.size());
48 values_new.reserve(data.size());
49 std::transform(data.begin(), it, std::back_inserter(indices_new),
50 [](
auto& d) { return d.first; });
51 std::transform(data.begin(), it, std::back_inserter(values_new),
52 [](
auto& d) { return d.second; });
54 return {std::move(indices_new), std::move(values_new)};
90 int err = MPI_Gather(&local_hash, 1, dolfinx::MPI::mpi_type<std::size_t>(),
92 dolfinx::MPI::mpi_type<std::size_t>(), 0, comm);
96 boost::hash<std::vector<std::size_t>> hash;
97 std::size_t global_hash = hash(all_hashes);
100 err = MPI_Bcast(&global_hash, 1, dolfinx::MPI::mpi_type<std::size_t>(), 0,
void check_error(MPI_Comm comm, int code)
Check MPI error code. If the error code is not equal to MPI_SUCCESS, then std::abort is called.
Definition MPI.cpp:80
std::pair< std::vector< typename U::value_type >, std::vector< typename V::value_type > > sort_unique(const U &indices, const V &values)
Sort two arrays based on the values in array indices. Any duplicate indices and the corresponding val...
Definition utils.h:28