Skip to content

Commit

Permalink
testing MGND
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Aug 29, 2024
1 parent 1d1b56a commit d1b9472
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
31 changes: 22 additions & 9 deletions apps/NDReorder/nd_reorder.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ struct arg
} Arg;

template <typename EigeMatT>
void no_permute(const rxmesh::RXMeshStatic& rx, const EigeMatT& eigen_mat)
void no_permute(const EigeMatT& eigen_mat)
{
using namespace rxmesh;

std::vector<int> h_permute(rx.get_num_vertices());
std::vector<int> h_permute(eigen_mat.rows());

fill_with_sequential_numbers(h_permute.data(), h_permute.size());

Expand Down Expand Up @@ -115,13 +115,29 @@ void with_metis(const rxmesh::SparseMatrix<T>& rx_mat,
h_permute.data(),
h_iperm.data());

EXPECT_TRUE(is_unique_permutation(h_permute.size(), h_permute.data()));
EXPECT_TRUE(
rxmesh::is_unique_permutation(h_permute.size(), h_permute.data()));

int nnz = count_nnz_fillin(eigen_mat, h_iperm);

RXMESH_INFO(" With METIS Nested Dissection NNZ = {}", nnz);
}

template <typename EigeMatT>
void with_mgnd(const rxmesh::RXMeshStatic& rx, const EigeMatT& eigen_mat)
{
std::vector<int> h_permute(eigen_mat.rows());

rxmesh::mgnd_permute(rx, h_permute);

EXPECT_TRUE(
rxmesh::is_unique_permutation(h_permute.size(), h_permute.data()));

int nnz = count_nnz_fillin(eigen_mat, h_permute);

RXMESH_INFO(" With MGND NNZ = {}", nnz);
}

TEST(Apps, NDReorder)
{
using namespace rxmesh;
Expand Down Expand Up @@ -153,16 +169,13 @@ TEST(Apps, NDReorder)
// convert matrix to Eigen
auto eigen_mat = rx_mat.to_eigen();

no_permute(rx, eigen_mat);
no_permute(eigen_mat);

with_metis(rx_mat, eigen_mat);

// cuda_nd_reorder(rx, h_reorder_array, Arg.nd_level);

with_mgnd(rx, eigen_mat);

// processmesh_ordering(Arg.obj_file_name, h_permute);
// processmesh_metis(Arg.obj_file_name);
// processmesh_original(Arg.obj_file_name);
// cuda_nd_reorder(rx, h_reorder_array, Arg.nd_level);
}

int main(int argc, char** argv)
Expand Down
2 changes: 1 addition & 1 deletion include/rxmesh/matrix/mgnd_permute.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ __global__ static void assign_permutation(const Context context,
* is order last. h_permute should be allocated with size equal to num of
* vertices of the mesh.
*/
inline void mgnd_permute(RXMeshStatic& rx, std::vector<int>& h_permute)
inline void mgnd_permute(const RXMeshStatic& rx, std::vector<int>& h_permute)
{
constexpr uint32_t blockThreads = 256;

Expand Down
13 changes: 8 additions & 5 deletions include/rxmesh/matrix/permute_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
#include <algorithm>
#include <vector>

namespace rxmesh {
/**
* @brief given a permutation array, verify that it is a unique permutation,
* i.e., every index is assigned to one permutation. This is done by sorting the
* array and then checking if every entry in the array matches its index.
*/
bool is_unique_permutation(uint32_t size, int* h_permute)
template <typename T>
bool is_unique_permutation(uint32_t size, T* h_permute)
{
std::vector<int> permute(size);
std::memcpy(permute.data(), h_permute, size * sizeof(int));
std::vector<T> permute(size);
std::memcpy(permute.data(), h_permute, size * sizeof(T));

std::sort(permute.begin(), permute.end());

for (int i = 0; i < int(permute.size()); ++i) {
for (T i = 0; i < T(permute.size()); ++i) {
if (i != permute[i]) {
return false;
}
}

return true;
}
}
} // namespace rxmesh

0 comments on commit d1b9472

Please sign in to comment.