10 #include <boost/functional/hash.hpp>
11 #include <dolfinx/common/MPI.h>
22 template <
int N,
class InputIt,
class OutputIt>
23 inline void copy_N(InputIt first, OutputIt result)
25 for (
int i = 0; i < N; ++i)
36 template <
typename U,
typename V>
37 std::pair<std::vector<typename U::value_type>,
38 std::vector<typename V::value_type>>
41 if (indices.size() != values.size())
42 throw std::runtime_error(
"Cannot sort two arrays of different lengths");
44 using T =
typename std::pair<typename U::value_type, typename V::value_type>;
45 std::vector<T> data(indices.size());
46 std::transform(indices.begin(), indices.end(), values.begin(), data.begin(),
47 [](
auto& idx,
auto& v) -> T {
52 std::sort(data.begin(), data.end());
53 auto it = std::unique(data.begin(), data.end(),
54 [](
auto& a,
auto& b) { return a.first == b.first; });
56 std::vector<typename U::value_type> indices_new;
57 std::vector<typename V::value_type> values_new;
58 indices_new.reserve(data.size());
59 values_new.reserve(data.size());
60 std::transform(data.begin(), it, std::back_inserter(indices_new),
61 [](
auto& d) { return d.first; });
62 std::transform(data.begin(), it, std::back_inserter(values_new),
63 [](
auto& d) { return d.second; });
65 return {std::move(indices_new), std::move(values_new)};
101 MPI_Gather(&local_hash, 1, dolfinx::MPI::mpi_type<std::size_t>(),
102 all_hashes.data(), 1, dolfinx::MPI::mpi_type<std::size_t>(), 0,
106 boost::hash<std::vector<std::size_t>> hash;
107 std::size_t global_hash = hash(all_hashes);
110 MPI_Bcast(&global_hash, 1, dolfinx::MPI::mpi_type<std::size_t>(), 0, comm);
int size(MPI_Comm comm)
Return size of the group (number of processes) associated with the communicator.
Definition: MPI.cpp:84
Miscellaneous classes, functions and types.
std::size_t hash_local(const T &x)
Compute a hash of a given object.
Definition: utils.h:76
std::size_t hash_global(MPI_Comm comm, const T &x)
Compute a hash for a distributed (MPI) object.
Definition: utils.h:94
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:39