11#include <boost/functional/hash.hpp>
14#include <dolfinx/graph/AdjacencyList.h>
36template <std::ranges::input_range U, std::ranges::input_range V>
37std::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 = std::pair<typename U::value_type, typename V::value_type>;
45 std::vector<T> data(indices.size());
46 std::ranges::transform(indices, values, data.begin(),
47 [](
const auto& idx,
const auto& v) -> T
48 { return {idx, v}; });
52 std::ranges::sort(data);
53 auto it = std::ranges::unique(data, [](
const auto& a,
const auto& b)
54 {
return a.first == b.first; })
57 std::vector<typename U::value_type> indices_new;
58 std::vector<typename V::value_type> values_new;
59 std::size_t n = std::distance(data.begin(), it);
60 indices_new.reserve(n);
61 values_new.reserve(n);
62 std::transform(data.begin(), it, std::back_inserter(indices_new),
63 [](
const auto& d) { return d.first; });
64 std::transform(data.begin(), it, std::back_inserter(values_new),
65 [](
const auto& d) { return d.second; });
67 return {std::move(indices_new), std::move(values_new)};
109 boost::hash<std::vector<std::size_t>> hash;
110 std::size_t global_hash = hash(all_hashes);
134 std::pair<std::int32_t, std::int32_t>>& g);
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:41
MPI_Datatype mpi_t
Retrieves the MPI data type associated to the provided type.
Definition MPI.h:257
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
int size(MPI_Comm comm)
Definition MPI.cpp:72
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
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.
Definition utils.h:39
std::size_t hash_global(MPI_Comm comm, const T &x)
Compute a hash for a distributed (MPI) object.
Definition utils.h:96
std::size_t hash_local(const T &x)
Compute a hash of a given object.
Definition utils.h:78
std::string comm_to_json(const graph::AdjacencyList< std::tuple< int, std::size_t, std::int8_t >, std::pair< std::int32_t, std::int32_t > > &g)
Build communication graph data as a JSON string.