9 #include <boost/functional/hash.hpp>
11 #include <dolfinx/common/MPI.h>
28 template <
typename U,
typename V>
29 std::pair<U, V>
sort_unique(
const U& indices,
const V& values)
31 if (indices.size() != values.size())
32 throw std::runtime_error(
"Cannot sort two arrays of different lengths");
34 std::vector<std::pair<typename U::value_type, typename V::value_type>> data(
36 for (std::size_t i = 0; i < indices.size(); ++i)
37 data[i] = {indices[i], values[i]};
40 std::sort(data.begin(), data.end());
41 auto it = std::unique(data.begin(), data.end(),
42 [](
auto& a,
auto& b) { return a.first == b.first; });
46 indices_new.reserve(data.size());
47 values_new.reserve(data.size());
48 for (
auto d = data.begin(); d != it; ++d)
50 indices_new.push_back(d->first);
51 values_new.push_back(d->second);
54 return {std::move(indices_new), std::move(values_new)};
58 std::string
indent(std::string block);
66 s.precision(precision);
68 for (std::size_t i = 0; i < (std::size_t)x.size(); ++i)
70 if ((i + 1) % linebreak == 0 && linebreak != 0)
71 s << x.data()[i] << std::endl;
73 s << x.data()[i] <<
" ";
97 MPI_Gather(&local_hash, 1, MPI_INT64_T, all_hashes.data(), 1, MPI_INT64_T, 0,
101 boost::hash<std::vector<int64_t>> hash;
102 int64_t global_hash = hash(all_hashes);
105 MPI_Bcast(&global_hash, 1, MPI_INT64_T, 0, comm);
int size(MPI_Comm comm)
Return size of the group (number of processes) associated with the communicator.
Definition: MPI.cpp:82
Miscellaneous classes, functions and types.
std::string container_to_string(const T &x, const int precision, const int linebreak)
Convert a container to string.
Definition: utils.h:62
std::string indent(std::string block)
Indent string block.
Definition: utils.cpp:11
std::size_t hash_local(const T &x)
Return a hash of a given object.
Definition: utils.h:80
std::pair< U, V > 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:29
std::int64_t hash_global(const MPI_Comm comm, const T &x)
Return a hash for a distributed (MPI) object. A hash is computed on each process, and the hash of the...
Definition: utils.h:90