Skip to content

Commit

Permalink
fix ND final index
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Sep 5, 2024
1 parent fa99a0e commit afbd2f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 23 additions & 2 deletions apps/NDReorder/count_nnz_fillin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

#include <Eigen/Sparse>

template <typename SparseMatrixType>
void exportToPlainText(const SparseMatrixType& mat, const std::string& filename)
{
std::ofstream file(filename);
if (!file.is_open()) {
std::cerr << "Error opening file: " << filename << std::endl;
return;
}

for (int k = 0; k < mat.outerSize(); ++k) {
for (typename SparseMatrixType::InnerIterator it(mat, k); it; ++it) {
file << (it.row() + 1) << " " << (it.col() + 1) << " " << it.value()
<< std::endl; // 1-based indexing for MATLAB
}
}

file.close();
}

/**
* @brief calculate the total number of nnz after Cholesky factorization given a
* permutation array that will be applied before the factorization
Expand Down Expand Up @@ -39,12 +58,14 @@ int count_nnz_fillin(const EigeMatT& eigen_mat, std::vector<I>& h_permute)
perm.indices()[i] = h_permute[i];
}

Eigen::SparseMatrix<float> permuted_mat(eigen_mat.rows(), eigen_mat.rows());
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());

// compute Cholesky factorization on the permuted matrix
// exportToPlainText(permuted_mat, "mat.txt");

// compute Cholesky factorization on the permuted matrix

Eigen::SimplicialLLT<Eigen::SparseMatrix<float>,
Eigen::Lower,
Expand Down
5 changes: 4 additions & 1 deletion include/rxmesh/matrix/nd_permute.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,11 @@ void permute_separators(RXMeshStatic& rx,
// });

auto context = rx.get_context();
int num_v = rx.get_num_vertices();
rx.for_each_vertex(DEVICE, [=] __device__(const VertexHandle& vh) {
d_permute[context.linear_id(vh)] += d_count[v_index(vh)];
int l = d_permute[context.linear_id(vh)];
l += d_count[v_index(vh)];
d_permute[context.linear_id(vh)] = num_v - l - 1;
});

GPU_FREE(d_dfs_index);
Expand Down

0 comments on commit afbd2f2

Please sign in to comment.