Skip to content

Commit

Permalink
debugging sep tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Aug 30, 2024
1 parent 735be56 commit 03090fb
Showing 1 changed file with 76 additions and 9 deletions.
85 changes: 76 additions & 9 deletions include/rxmesh/matrix/nd_permute.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "rxmesh/rxmesh_static.h"

#include "rxmesh/matrix/permute_util.h"
#include "rxmesh/matrix/separator_tree.h"

#include "metis.h"
Expand All @@ -23,6 +24,21 @@ struct Graph
// adjncy stores the adjacency lists of the vertices. The adjnacy list of a
// vertex should not contain the vertex itself.
std::vector<T> adjncy;

void print()
{
std::cout << "\n*** graph ***\n";
for (int i = 0; i < n; ++i) {
// std::cout << "Row " << i << "\n ";
for (int j = xadj[i]; j < xadj[i + 1]; ++j) {
if (i <= adjncy[j]) {
std::cout << i << " -> " << adjncy[j] << ";\n";
}
}
std::cout << "\n";
}
std::cout << "\n";
}
};

/**
Expand Down Expand Up @@ -77,32 +93,83 @@ void run_metis(Graph<idx_t>& patches_graph,
}
}

template <typename integer_t>
void print_graph_vertices_at_each_level(
const SeparatorTree<integer_t>& tree,
const std::vector<integer_t>& inv_permute,
integer_t node,
integer_t level)
{
if (node == -1)
return;

// Extract the range of vertices in the permuted graph
integer_t start = tree.sizes[node];
integer_t end = tree.sizes[node + 1];

std::cout << "Level " << level << ": Separator node " << node
<< " separates original vertices: ";

// Map the permuted indices back to the original graph vertices
for (integer_t i = start; i < end; i++) {
std::cout << inv_permute[i] << " ";
}
std::cout << std::endl;

// Recursively traverse the left and right children
if (tree.lch[node] != -1) {
print_graph_vertices_at_each_level(
tree, inv_permute, tree.lch[node], level + 1);
}
if (tree.rch[node] != -1) {
print_graph_vertices_at_each_level(
tree, inv_permute, tree.rch[node], level + 1);
}
}

void nd_permute(RXMeshStatic& rx, std::vector<int>& h_permute)
{
// a graph representing the patch connectivity
Graph<idx_t> p_graph;

construct_patches_neighbor_graph(rx, p_graph);

p_graph.print();

std::vector<idx_t> p_graph_permute(p_graph.n);
std::vector<idx_t> p_graph_inv_permute(p_graph.n);

run_metis(p_graph, p_graph_permute, p_graph_inv_permute);
fill_with_sequential_numbers(p_graph_permute.data(),
p_graph_permute.size());

fill_with_sequential_numbers(p_graph_inv_permute.data(),
p_graph_inv_permute.size());
// run_metis(p_graph, p_graph_permute, p_graph_inv_permute);

if (!is_unique_permutation(p_graph_permute.size(),
p_graph_permute.data())) {
RXMESH_ERROR("nd_permute() METIS failed to give unique permutation");
}

SeparatorTree<idx_t> sep_tree =
build_sep_tree_from_perm(p_graph.xadj.data(),
p_graph.adjncy.data(),
p_graph_permute,
p_graph_inv_permute);

//sep_tree.print();
//sep_tree.printm("sep_tree");
//
//rx.render_vertex_patch();
//rx.render_edge_patch();
//rx.render_face_patch();
//
//polyscope::show();
sep_tree.print();
sep_tree.printm("sep_tree");
sep_tree.check();

print_graph_vertices_at_each_level(
sep_tree, p_graph_inv_permute, sep_tree.root(), idx_t(0));


rx.render_vertex_patch();
rx.render_edge_patch();
rx.render_face_patch();

polyscope::show();
}

} // namespace rxmesh

0 comments on commit 03090fb

Please sign in to comment.