10 #include <boost/functional/hash.hpp>
12 #include <dolfinx/common/MPI.h>
29 template <
typename U,
typename V>
30 std::pair<U, V>
sort_unique(
const U& indices,
const V& values)
32 if (indices.size() != values.size())
33 throw std::runtime_error(
"Cannot sort two arrays of different lengths");
35 std::vector<std::pair<typename U::value_type, typename V::value_type>> data(
37 for (std::size_t i = 0; i < indices.size(); ++i)
38 data[i] = {indices[i], values[i]};
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; });
47 indices_new.reserve(data.size());
48 values_new.reserve(data.size());
49 for (
auto d = data.begin(); d != it; ++d)
51 indices_new.push_back(d->first);
52 values_new.push_back(d->second);
55 return {std::move(indices_new), std::move(values_new)};
59 std::string
indent(std::string block);
65 int precision,
int linebreak = 0)
68 s.precision(precision);
74 for (
auto it = x.begin() + 1; it != x.end(); ++it)
75 s << delimiter << *it;
79 for (std::size_t i = 0; i != x.size(); ++i)
81 if ((i + 1) % linebreak == 0)
82 s << x[i] << std::endl;
84 s << x[i] << delimiter;
110 MPI_Gather(&local_hash, 1, MPI_INT64_T, all_hashes.data(), 1, MPI_INT64_T, 0,
114 boost::hash<std::vector<int64_t>> hash;
115 int64_t global_hash = hash(all_hashes);
118 MPI_Bcast(&global_hash, 1, MPI_INT64_T, 0, comm);
static int size(MPI_Comm comm)
Return size of the group (number of processes) associated with the communicator.
Definition: MPI.cpp:87
Miscellaneous classes, functions and types.
std::string indent(std::string block)
Indent string block.
Definition: utils.cpp:12
std::size_t hash_local(const T &x)
Return a hash of a given object.
Definition: utils.h:93
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:30
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:103
std::string container_to_string(const T &x, std::string delimiter, int precision, int linebreak=0)
Return string representation of given container of ints, floats, etc.
Definition: utils.h:64