Classes | |
struct | Traits |
Public Member Functions | |
SparseMatrix () | |
SparseMatrix (const unsigned int m, const unsigned int n, const unsigned int n_nonzero_per_row, const bool is_symmetric=false) | |
SparseMatrix (const unsigned int m, const unsigned int n, const std::vector< unsigned int > &row_lengths, const bool is_symmetric=false) | |
template<typename SparsityType > | |
SparseMatrix (const SparsityType &sparsity_pattern, const bool preset_nonzero_locations=false) | |
SparseMatrix & | operator= (const double d) |
void | reinit (const unsigned int m, const unsigned int n, const unsigned int n_nonzero_per_row, const bool is_symmetric=false) |
void | reinit (const unsigned int m, const unsigned int n, const std::vector< unsigned int > &row_lengths, const bool is_symmetric=false) |
template<typename SparsityType > | |
void | reinit (const SparsityType &sparsity_pattern, const bool preset_nonzero_locations=false) |
virtual const MPI_Comm & | get_mpi_communicator () const |
Private Member Functions | |
void | do_reinit (const unsigned int m, const unsigned int n, const unsigned int n_nonzero_per_row, const bool is_symmetric=false) |
void | do_reinit (const unsigned int m, const unsigned int n, const std::vector< unsigned int > &row_lengths, const bool is_symmetric=false) |
template<typename SparsityType > | |
void | do_reinit (const SparsityType &sparsity_pattern, const bool preset_nonzero_locations) |
PETScWrappers::SparseMatrix::SparseMatrix | ( | ) |
Default constructor. Create an empty matrix.
PETScWrappers::SparseMatrix::SparseMatrix | ( | const unsigned int | m, | |
const unsigned int | n, | |||
const unsigned int | n_nonzero_per_row, | |||
const bool | is_symmetric = false | |||
) |
Create a sparse matrix of dimensions m
times n
, with an initial guess of n_nonzero_per_row
nonzero elements per row. PETSc is able to cope with the situation that more than this number of elements is later allocated for a row, but this involves copying data, and is thus expensive.
The is_symmetric
flag determines whether we should tell PETSc that the matrix is going to be symmetric (as indicated by the call MatSetOption(mat, MAT_SYMMETRIC)
. Note that the PETSc documentation states that one cannot form an ILU decomposition of a matrix for which this flag has been set to true
, only an ICC. The default value of this flag is false
.
PETScWrappers::SparseMatrix::SparseMatrix | ( | const unsigned int | m, | |
const unsigned int | n, | |||
const std::vector< unsigned int > & | row_lengths, | |||
const bool | is_symmetric = false | |||
) |
Initialize a rectangular matrix with m
rows and n
columns. The maximal number of nonzero entries for each row separately is given by the row_lengths
array.
Just as for the other constructors: PETSc is able to cope with the situation that more than this number of elements is later allocated for a row, but this involves copying data, and is thus expensive.
The is_symmetric
flag determines whether we should tell PETSc that the matrix is going to be symmetric (as indicated by the call MatSetOption(mat, MAT_SYMMETRIC)
. Note that the PETSc documentation states that one cannot form an ILU decomposition of a matrix for which this flag has been set to true
, only an ICC. The default value of this flag is false
.
PETScWrappers::SparseMatrix::SparseMatrix | ( | const SparsityType & | sparsity_pattern, | |
const bool | preset_nonzero_locations = false | |||
) | [inline] |
Initialize a sparse matrix using the given sparsity pattern.
Note that PETSc can be very slow if you do not provide it with a good estimate of the lengths of rows. Using the present function is a very efficient way to do this, as it uses the exact number of nonzero entries for each row of the matrix by using the given sparsity pattern argument. If the preset_nonzero_locations
flag is true
, this function in addition not only sets the correct row sizes up front, but also pre-allocated the correct nonzero entries in the matrix.
PETsc allows to later add additional nonzero entries to a matrix, by simply writing to these elements. However, this will then lead to additional memory allocations which are very inefficient and will greatly slow down your program. It is therefore significantly more efficient to get memory allocation right from the start.
Despite the fact that it would seem to be an obvious win, setting the preset_nonzero_locations
flag to true
doesn't seem to accelerate program. Rather on the contrary, it seems to be able to slow down entire programs somewhat. This is suprising, since we can use efficient function calls into PETSc that allow to create multiple entries at once; nevertheless, given the fact that it is inefficient, the respective flag has a default value equal to false
.
SparseMatrix& PETScWrappers::SparseMatrix::operator= | ( | const double | d | ) |
This operator assigns a scalar to a matrix. Since this does usually not make much sense (should we set all matrix entries to this value? Only the nonzero entries of the sparsity pattern?), this operation is only allowed if the actual value to be assigned is zero. This operator only exists to allow for the obvious notation matrix=0
, which sets all elements of the matrix to zero, but keep the sparsity pattern previously used.
Reimplemented from PETScWrappers::MatrixBase.
void PETScWrappers::SparseMatrix::reinit | ( | const unsigned int | m, | |
const unsigned int | n, | |||
const unsigned int | n_nonzero_per_row, | |||
const bool | is_symmetric = false | |||
) |
Throw away the present matrix and generate one that has the same properties as if it were created by the constructor of this class with the same argument list as the present function.
void PETScWrappers::SparseMatrix::reinit | ( | const unsigned int | m, | |
const unsigned int | n, | |||
const std::vector< unsigned int > & | row_lengths, | |||
const bool | is_symmetric = false | |||
) |
Throw away the present matrix and generate one that has the same properties as if it were created by the constructor of this class with the same argument list as the present function.
void PETScWrappers::SparseMatrix::reinit | ( | const SparsityType & | sparsity_pattern, | |
const bool | preset_nonzero_locations = false | |||
) | [inline] |
Initialize a sparse matrix using the given sparsity pattern.
Note that PETSc can be very slow if you do not provide it with a good estimate of the lengths of rows. Using the present function is a very efficient way to do this, as it uses the exact number of nonzero entries for each row of the matrix by using the given sparsity pattern argument. If the preset_nonzero_locations
flag is true
, this function in addition not only sets the correct row sizes up front, but also pre-allocated the correct nonzero entries in the matrix.
PETsc allows to later add additional nonzero entries to a matrix, by simply writing to these elements. However, this will then lead to additional memory allocations which are very inefficient and will greatly slow down your program. It is therefore significantly more efficient to get memory allocation right from the start.
Despite the fact that it would seem to be an obvious win, setting the preset_nonzero_locations
flag to true
doesn't seem to accelerate program. Rather on the contrary, it seems to be able to slow down entire programs somewhat. This is suprising, since we can use efficient function calls into PETSc that allow to create multiple entries at once; nevertheless, given the fact that it is inefficient, the respective flag has a default value equal to false
.
virtual const MPI_Comm& PETScWrappers::SparseMatrix::get_mpi_communicator | ( | ) | const [virtual] |
Return a reference to the MPI communicator object in use with this matrix. Since this is a sequential matrix, it returns the MPI_COMM_SELF communicator.
Implements PETScWrappers::MatrixBase.
void PETScWrappers::SparseMatrix::do_reinit | ( | const unsigned int | m, | |
const unsigned int | n, | |||
const unsigned int | n_nonzero_per_row, | |||
const bool | is_symmetric = false | |||
) | [private] |
Do the actual work for the respective reinit() function and the matching constructor, i.e. create a matrix. Getting rid of the previous matrix is left to the caller.
void PETScWrappers::SparseMatrix::do_reinit | ( | const unsigned int | m, | |
const unsigned int | n, | |||
const std::vector< unsigned int > & | row_lengths, | |||
const bool | is_symmetric = false | |||
) | [private] |
Same as previous function.
void PETScWrappers::SparseMatrix::do_reinit | ( | const SparsityType & | sparsity_pattern, | |
const bool | preset_nonzero_locations | |||
) | [inline, private] |
Same as previous function.