Eigen::MetisOrdering< StorageIndex > Class Template Reference

#include <MetisSupport.h>

Public Types

typedef PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
 
typedef Matrix< StorageIndex, Dynamic, 1 > IndexVector
 

Public Member Functions

template<typename MatrixType >
void get_symmetrized_graph (const MatrixType &A)
 
template<typename MatrixType >
void operator() (const MatrixType &A, PermutationType &matperm)
 

Protected Attributes

IndexVector m_indexPtr
 
IndexVector m_innerIndices
 

Detailed Description

template<typename StorageIndex>
class Eigen::MetisOrdering< StorageIndex >

Get the fill-reducing ordering from the METIS package

If A is the original matrix and Ap is the permuted matrix, the fill-reducing permutation is defined as follows : Row (column) i of A is the matperm(i) row (column) of Ap. WARNING: As computed by METIS, this corresponds to the vector iperm (instead of perm)

Member Typedef Documentation

◆ IndexVector

template<typename StorageIndex >
typedef Matrix<StorageIndex, Dynamic, 1> Eigen::MetisOrdering< StorageIndex >::IndexVector

◆ PermutationType

template<typename StorageIndex >
typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> Eigen::MetisOrdering< StorageIndex >::PermutationType

Member Function Documentation

◆ get_symmetrized_graph()

template<typename StorageIndex >
template<typename MatrixType >
void Eigen::MetisOrdering< StorageIndex >::get_symmetrized_graph ( const MatrixType A)
inline
31  {
32  Index m = A.cols();
33  eigen_assert((A.rows() == A.cols()) && "ONLY FOR SQUARED MATRICES");
34  // Get the transpose of the input matrix
35  MatrixType At = A.transpose();
36  // Get the number of nonzeros elements in each row/col of At+A
37  Index TotNz = 0;
38  IndexVector visited(m);
39  visited.setConstant(-1);
40  for (StorageIndex j = 0; j < m; j++) {
41  // Compute the union structure of of A(j,:) and At(j,:)
42  visited(j) = j; // Do not include the diagonal element
43  // Get the nonzeros in row/column j of A
44  for (typename MatrixType::InnerIterator it(A, j); it; ++it) {
45  Index idx = it.index(); // Get the row index (for column major) or column index (for row major)
46  if (visited(idx) != j) {
47  visited(idx) = j;
48  ++TotNz;
49  }
50  }
51  // Get the nonzeros in row/column j of At
52  for (typename MatrixType::InnerIterator it(At, j); it; ++it) {
53  Index idx = it.index();
54  if (visited(idx) != j) {
55  visited(idx) = j;
56  ++TotNz;
57  }
58  }
59  }
60  // Reserve place for A + At
61  m_indexPtr.resize(m + 1);
62  m_innerIndices.resize(TotNz);
63 
64  // Now compute the real adjacency list of each column/row
65  visited.setConstant(-1);
66  StorageIndex CurNz = 0;
67  for (StorageIndex j = 0; j < m; j++) {
68  m_indexPtr(j) = CurNz;
69 
70  visited(j) = j; // Do not include the diagonal element
71  // Add the pattern of row/column j of A to A+At
72  for (typename MatrixType::InnerIterator it(A, j); it; ++it) {
73  StorageIndex idx = it.index(); // Get the row index (for column major) or column index (for row major)
74  if (visited(idx) != j) {
75  visited(idx) = j;
76  m_innerIndices(CurNz) = idx;
77  CurNz++;
78  }
79  }
80  // Add the pattern of row/column j of At to A+At
81  for (typename MatrixType::InnerIterator it(At, j); it; ++it) {
82  StorageIndex idx = it.index();
83  if (visited(idx) != j) {
84  visited(idx) = j;
85  m_innerIndices(CurNz) = idx;
86  ++CurNz;
87  }
88  }
89  }
90  m_indexPtr(m) = CurNz;
91  }
#define eigen_assert(x)
Definition: Macros.h:910
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Matrix< StorageIndex, Dynamic, 1 > IndexVector
Definition: MetisSupport.h:28
IndexVector m_indexPtr
Definition: MetisSupport.h:120
IndexVector m_innerIndices
Definition: MetisSupport.h:121
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::PlainObjectBase< Derived >::cols(), eigen_assert, j, m, Eigen::MetisOrdering< StorageIndex >::m_indexPtr, Eigen::MetisOrdering< StorageIndex >::m_innerIndices, Eigen::PlainObjectBase< Derived >::resize(), Eigen::PlainObjectBase< Derived >::rows(), and Eigen::PlainObjectBase< Derived >::setConstant().

Referenced by Eigen::MetisOrdering< StorageIndex >::operator()().

◆ operator()()

template<typename StorageIndex >
template<typename MatrixType >
void Eigen::MetisOrdering< StorageIndex >::operator() ( const MatrixType A,
PermutationType matperm 
)
inline
94  {
95  StorageIndex m = internal::convert_index<StorageIndex>(
96  A.cols()); // must be StorageIndex, because it is passed by address to METIS
97  IndexVector perm(m), iperm(m);
98  // First, symmetrize the matrix graph.
100  int output_error;
101 
102  // Call the fill-reducing routine from METIS
103  output_error = METIS_NodeND(&m, m_indexPtr.data(), m_innerIndices.data(), NULL, NULL, perm.data(), iperm.data());
104 
105  if (output_error != METIS_OK) {
106  // FIXME The ordering interface should define a class of possible errors
107  std::cerr << "ERROR WHILE CALLING THE METIS PACKAGE \n";
108  return;
109  }
110 
111  // Get the fill-reducing permutation
112  // NOTE: If Ap is the permuted matrix then perm and iperm vectors are defined as follows
113  // Row (column) i of Ap is the perm(i) row(column) of A, and row (column) i of A is the iperm(i) row(column) of Ap
114 
115  matperm.resize(m);
116  for (int j = 0; j < m; j++) matperm.indices()(iperm(j)) = j;
117  }
void get_symmetrized_graph(const MatrixType &A)
Definition: MetisSupport.h:31
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
void METIS_NodeND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *)

References Eigen::PlainObjectBase< Derived >::cols(), Eigen::PlainObjectBase< Derived >::data(), Eigen::MetisOrdering< StorageIndex >::get_symmetrized_graph(), Eigen::PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_ >::indices(), j, m, Eigen::MetisOrdering< StorageIndex >::m_indexPtr, Eigen::MetisOrdering< StorageIndex >::m_innerIndices, METIS_NodeND(), and Eigen::PermutationBase< Derived >::resize().

Member Data Documentation

◆ m_indexPtr

template<typename StorageIndex >
IndexVector Eigen::MetisOrdering< StorageIndex >::m_indexPtr
protected

◆ m_innerIndices

template<typename StorageIndex >
IndexVector Eigen::MetisOrdering< StorageIndex >::m_innerIndices
protected

The documentation for this class was generated from the following file: