6#include <kernel/adjacency/graph.hpp>
7#include <kernel/adjacency/permutation.hpp>
24 Index num_nodes_domain,
25 Index num_nodes_image,
26 Index num_indices_image) :
27 _num_nodes_image(num_nodes_image),
28 _domain_ptr(num_nodes_domain + 1),
29 _image_idx(num_indices_image)
35 Index num_nodes_domain,
36 Index num_nodes_image,
37 Index num_indices_image,
38 const Index* domain_ptr,
39 const Index* image_idx) :
40 _num_nodes_image(num_nodes_image),
41 _domain_ptr(num_nodes_domain + 1),
42 _image_idx(num_indices_image)
44 FEAT_PRAGMA_OMP(parallel
for)
45 for(
Index i = 0; i <= num_nodes_domain; ++i)
49 FEAT_PRAGMA_OMP(parallel
for)
50 for(
Index i = 0; i < num_indices_image; ++i)
58 Index num_nodes_image,
61 _num_nodes_image(num_nodes_image),
62 _domain_ptr(domain_ptr),
69 Index num_nodes_image,
72 _num_nodes_image(num_nodes_image),
80 _num_nodes_image(other._num_nodes_image),
81 _domain_ptr(std::forward<
IndexVector>(other._domain_ptr)),
82 _image_idx(std::forward<
IndexVector>(other._image_idx))
84 other._num_nodes_image =
Index(0);
85 other._domain_ptr.clear();
86 other._image_idx.clear();
97 _domain_ptr = std::forward<IndexVector>(other._domain_ptr);
98 _image_idx = std::forward<IndexVector>(other._image_idx);
100 other._num_nodes_image =
Index(0);
101 other._domain_ptr.clear();
102 other._image_idx.clear();
109 _num_nodes_image(other.get_num_nodes_image()),
110 _domain_ptr(other.get_num_nodes_domain()+1),
111 _image_idx(other.get_num_indices())
118 for(
Index i(0); i < other.get_num_nodes_domain(); ++i)
120 _domain_ptr[i+1] = other._domain_ptr[domain_perm_pos[i]+1]
121 - other._domain_ptr[domain_perm_pos[i]]
130 for(
Index i(0); i < other.get_num_nodes_domain(); ++i)
132 Index _offset = other._domain_ptr[domain_perm_pos[i]];
133 Index _row_end = other._domain_ptr[domain_perm_pos[i]+1];
134 for(
Index j(_offset); j < _row_end; ++j)
136 _image_idx[count] = image_perm_pos[other._image_idx[j]];
148 XASSERTM(buffer.size() >= std::size_t(40u),
"invalid buffer size");
150 typedef std::uint64_t u64;
151 const u64* v =
reinterpret_cast<const u64*
>(buffer.data());
157 XASSERTM(v[1] == u64(buffer.size()),
"invalid buffer size");
163 const u64* x = &v[5];
166 if(domain_ptr_size >
Index(0))
169 for(
Index i(0); i <= this->get_num_nodes_domain(); ++i)
171 x += std::streamoff(this->get_num_nodes_domain() +1u);
175 if(num_indices_image >
Index(0))
178 for(
Index i(0); i < num_indices_image; ++i)
198 FEAT_PRAGMA_OMP(parallel
for reduction(max:deg))
212 FEAT_PRAGMA_OMP(parallel
for schedule(dynamic, 1000))
227 FEAT_PRAGMA_OMP(parallel
for)
237 typedef std::uint64_t u64;
240 std::vector<char> buffer(s * 8u);
241 u64* v =
reinterpret_cast<u64*
>(buffer.data());
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Adjacency Graph implementation.
Graph & operator=(Graph &&other)
move-assign operator
static constexpr std::uint64_t magic
magic number for Graph serialization
IndexVector _image_idx
Image node index Vector.
IndexVector _domain_ptr
Domain pointer Vector.
Graph()
Default constructor.
std::vector< Index > IndexVector
index vector type
void sort_indices()
Sorts the image indices to non-descending order.
Index degree() const
Returns the degree of the graph.
void permute_indices(const Adjacency::Permutation &inv_perm)
Permutes the image indices.
void clear()
Clears the graph.
virtual ~Graph()
virtual destructor
Index _num_nodes_image
total number of image nodes
std::vector< char > serialize() const
Serializes the graph into a buffer.
Index size() const
returns the size of the permutation
Index * get_perm_pos()
returns the permute-position array
std::uint64_t Index
Index data type.