Skip to content

Commit

Permalink
Merge pull request #48 from Ahdhn/main
Browse files Browse the repository at this point in the history
Matrix Reordering
  • Loading branch information
Ahdhn authored Dec 17, 2024
2 parents 434f010 + 0ced73c commit c54401d
Show file tree
Hide file tree
Showing 3 changed files with 1,760 additions and 43 deletions.
26 changes: 20 additions & 6 deletions apps/NDReorder/count_nnz_fillin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,34 @@ int count_nnz_fillin(const EigeMatT& eigen_mat,
perm.indices()[i] = h_permute[i];
}

RXMESH_INFO(" Before perm_mat\n");

Eigen::SparseMatrix<float> permuted_mat(eigen_mat.rows(), eigen_mat.rows());

Eigen::internal::permute_symm_to_fullsymm<Eigen::Lower, false>(
eigen_mat, permuted_mat, perm.indices().data());

// export_to_plain_text(permuted_mat,
// std::string("C:\\Github\\Matlab_Reordering_Trial\\")
// +
// st + std::string(".txt"));
//
// return 0;
RXMESH_INFO(" After perm_mat\n");

// tmp fix that EIGEN doesn't work
export_to_plain_text(permuted_mat,
std::string("/home/ericyuan/Projects/RXMesh/build/output/")
+ st + std::string(".txt"));

return 0;

// compute Cholesky factorization on the permuted matrix

Eigen::SimplicialLLT<Eigen::SparseMatrix<float>,
Eigen::Lower,
Eigen::NaturalOrdering<int>>
solver;

solver.analyzePattern(permuted_mat);
solver.compute(permuted_mat);

RXMESH_INFO(" After solver\n");

if (solver.info() != Eigen::Success) {
RXMESH_ERROR(
"post_chol_factorization_nnz(): Cholesky decomposition with "
Expand All @@ -75,14 +83,20 @@ int count_nnz_fillin(const EigeMatT& eigen_mat,
return -1;
}

RXMESH_INFO(" before lower_mat\n");

// extract nnz from lower matrix
Eigen::SparseMatrix<float> lower_mat = solver.matrixL();

// std::cout << "ff\n" << ff << "\n";

RXMESH_INFO(" After lower_mat\n");

// these are the nnz on (strictly) the lower part
int lower_nnz = lower_mat.nonZeros() - lower_mat.rows();

RXMESH_INFO(" After lower_nnz\n");

// multiply by two to account for lower and upper parts of the matrix
// add rows() to account for entries along the diagonal
return 2 * lower_nnz + lower_mat.rows();
Expand Down
22 changes: 14 additions & 8 deletions apps/NDReorder/test_all_permutations.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ void no_permute(rxmesh::RXMeshStatic& rx, const EigeMatT& eigen_mat)

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

RXMESH_INFO(" No-permutation before fill.");

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

// render_permutation(rx, h_permute, "No_PERM");

RXMESH_INFO(" Before count_nnz_fillin");

int nnz = count_nnz_fillin(eigen_mat, h_permute, "natural");

RXMESH_INFO(" No-permutation NNZ = {}", nnz);
Expand Down Expand Up @@ -248,13 +252,13 @@ TEST(Apps, NDReorder)

cuda_query(Arg.device_id);

const std::string p_file = STRINGIFY(OUTPUT_DIR) +
extract_file_name(Arg.obj_file_name) +
"_patches";
RXMeshStatic rx(Arg.obj_file_name /*,p_file*/);
if (!std::filesystem::exists(p_file)) {
rx.save(p_file);
}
// const std::string p_file = STRINGIFY(OUTPUT_DIR) +
// extract_file_name(Arg.obj_file_name) +
// "_patches";
RXMeshStatic rx(Arg.obj_file_name);
// if (!std::filesystem::exists(p_file)) {
// rx.save(p_file);
// }

// VV matrix
rxmesh::SparseMatrix<float> rx_mat(rx);
Expand All @@ -276,6 +280,8 @@ TEST(Apps, NDReorder)
// convert matrix to Eigen
auto eigen_mat = rx_mat.to_eigen();

RXMESH_INFO(" Eigen Matrix NNZ = {}", eigen_mat.nonZeros());

no_permute(rx, eigen_mat);

with_amd(rx, rx_mat, eigen_mat);
Expand All @@ -288,7 +294,7 @@ TEST(Apps, NDReorder)

with_gpu_nd(rx, eigen_mat);

// polyscope::show();
polyscope::show();
}

int main(int argc, char** argv)
Expand Down
Loading

0 comments on commit c54401d

Please sign in to comment.