Seldon::PetscMatrix< T, Prop, Storage, Allocator > Class Template Reference

Matrix class based on PETSc matrix. More...

#include <PetscMatrix.hxx>

Inheritance diagram for Seldon::PetscMatrix< T, Prop, Storage, Allocator >:
Seldon::Matrix_Base< T, Allocator >

List of all members.

Public Types

typedef Allocator::value_type value_type
typedef Allocator::pointer pointer
typedef Allocator::const_pointer const_pointer
typedef Allocator::reference reference
typedef Allocator::const_reference const_reference
typedef Allocator::value_type entry_type
typedef Allocator::value_type access_type
typedef Allocator::value_type const_access_type

Public Member Functions

 PetscMatrix ()
 Default constructor.
 PetscMatrix (int i, int j)
 Main constructor.
 PetscMatrix (Mat &A)
 Copy constructor.
void SetCommunicator (MPI_Comm mpi_communicator)
 Sets the MPI communicator.
MPI_Comm GetCommunicator () const
 Returns the MPI communicator of the current PETSc matrix.
 ~PetscMatrix ()
 Destructor.
void Clear ()
 Clears the matrix.
void Nullify ()
 Clears the matrix without releasing memory.
Mat & GetPetscMatrix ()
 Returns a reference on the inner petsc matrix.
const Mat & GetPetscMatrix () const
 Returns a const reference on the inner petsc matrix.
void Resize (int i, int j)
 Reallocates memory to resize the matrix and keeps previous entries.
void SetData (int i, int j, pointer data)
 Changes the size of the matrix and sets its data array // (low level method).
const_reference Val (int i, int j) const
 Access operator.
reference Val (int i, int j)
 Access operator.
reference operator[] (int i)
 Access to elements of the data array.
const_reference operator[] (int i) const
 Access to elements of the data array.
void Set (int, int, T)
void SetBuffer (int, int, T, InsertMode)
 Inserts or adds values into certain locations of a matrix.
void Flush () const
 Assembles the PETSc matrix.
void GetProcessorRowRange (int &i, int &j) const
 Returns the range of row indices owned by this processor.
void Copy (const Mat &A)
 Duplicates a matrix.
void Zero ()
 Sets all elements to zero.
void SetIdentity ()
 Sets the matrix to the identity.
void Fill ()
 Fills the matrix with 0, 1, 2, ...
template<class T0 >
void Fill (const T0 &x)
 Fills the matrix with a given value.
void FillRand ()
 Fills a matrix randomly.
void Print (int a, int b, int m, int n) const
 Displays a sub-matrix on the standard output.
void Print (int l) const
 Displays a square sub-matrix on the standard output.
void Write (string FileName, bool with_size) const
 Writes the matrix in a file.
void Write (ostream &FileStream, bool with_size) const
 Writes the matrix to an output stream.
void WriteText (string FileName) const
 Writes the matrix in a file.
void WriteText (ostream &FileStream) const
 Writes the matrix to an output stream.
void Read (string FileName)
 Reads the matrix from a file.
void Read (istream &FileStream)
 Reads the matrix from an input stream.
void ReadText (string FileName)
 Reads the matrix from a file.
void ReadText (istream &FileStream)
 Reads the matrix from an input stream.
int GetM () const
 Returns the number of rows.
int GetM (const Seldon::SeldonTranspose &status) const
 Returns the number of rows of the matrix possibly transposed.
int GetN () const
 Returns the number of columns.
int GetN (const Seldon::SeldonTranspose &status) const
 Returns the number of columns of the matrix possibly transposed.
int GetSize () const
 Returns the number of elements in the matrix.
pointer GetData () const
 Returns a pointer to the data array.
const_pointer GetDataConst () const
 Returns a const pointer to the data array.
void * GetDataVoid () const
 Returns a pointer of type "void*" to the data array.
const void * GetDataConstVoid () const
 Returns a pointer of type "const void*" to the data array.
Allocator & GetAllocator ()
 Returns the allocator of the matrix.

Protected Attributes

Mat petsc_matrix_
 Encapsulated PETSc matrix.
MPI_Comm mpi_communicator_
 The MPI communicator to use.
bool petsc_matrix_deallocated_
 Boolean to indicate if the inner PETSc matrix is destroyed or not.
int m_
int n_
pointer data_

Static Protected Attributes

static Allocator allocator_

Detailed Description

template<class T, class Prop, class Storage, class Allocator = SELDON_DEFAULT_ALLOCATOR<T>>
class Seldon::PetscMatrix< T, Prop, Storage, Allocator >

Matrix class based on PETSc matrix.

Definition at line 40 of file PetscMatrix.hxx.


Constructor & Destructor Documentation

template<class T , class Prop , class Storage , class Allocator >
Seldon::PetscMatrix< T, Prop, Storage, Allocator >::PetscMatrix (  )  [inline]

Default constructor.

On exit, the matrix is an empty 0x0 matrix.

Definition at line 32 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
Seldon::PetscMatrix< T, Prop, Storage, Allocator >::PetscMatrix ( int  i,
int  j 
) [inline]

Main constructor.

Builds a i x j full matrix.

Parameters:
i number of rows.
j number of columns.

Definition at line 47 of file PetscMatrix.cxx.


Member Function Documentation

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Clear (  )  [inline]

Clears the matrix.

Destructs the matrix.

Warning:
On exit, the matrix is an empty 0x0 matrix.

Definition at line 106 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Copy ( const Mat &  A  )  [inline]

Duplicates a matrix.

Parameters:
A matrix to be copied.
Note:
Memory is duplicated: 'A' is therefore independent from the current instance after the copy.

Definition at line 323 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Fill (  ) 

Fills the matrix with 0, 1, 2, ...

On exit, the matrix is filled with 0, 1, 2, 3, ... The order of those numbers depends on the storage.

Definition at line 362 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
template<class T0 >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Fill ( const T0 &  x  ) 

Fills the matrix with a given value.

Parameters:
x the value to fill the matrix with.

Definition at line 375 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::FillRand (  ) 

Fills a matrix randomly.

Note:
The random generator is very basic.

Definition at line 387 of file PetscMatrix.cxx.

template<class T , class Allocator >
Allocator & Seldon::Matrix_Base< T, Allocator >::GetAllocator (  )  [inherited]

Returns the allocator of the matrix.

Returns:
The allocator.

Definition at line 258 of file Matrix_Base.cxx.

template<class T , class Prop , class Storage , class Allocator >
MPI_Comm Seldon::PetscMatrix< T, Prop, Storage, Allocator >::GetCommunicator (  )  const [inline]

Returns the MPI communicator of the current PETSc matrix.

Returns:
The MPI communicator of the current PETSc matrix.

Definition at line 84 of file PetscMatrix.cxx.

template<class T , class Allocator >
Matrix_Base< T, Allocator >::pointer Seldon::Matrix_Base< T, Allocator >::GetData (  )  const [inherited]

Returns a pointer to the data array.

Returns a pointer to data, i.e. the data array 'data_'.

Returns:
A pointer to the data array.

Definition at line 208 of file Matrix_Base.cxx.

template<class T , class Allocator >
Matrix_Base< T, Allocator >::const_pointer Seldon::Matrix_Base< T, Allocator >::GetDataConst (  )  const [inherited]

Returns a const pointer to the data array.

Returns a const pointer to data, i.e. the data array 'data_'.

Returns:
A const pointer to the data array.

Definition at line 221 of file Matrix_Base.cxx.

template<class T , class Allocator >
const void * Seldon::Matrix_Base< T, Allocator >::GetDataConstVoid (  )  const [inherited]

Returns a pointer of type "const void*" to the data array.

Returns a pointer of type "const void*" to data, i.e. the data array 'data_'.

Returns:
A const pointer of type "void*" to the data array.

Definition at line 247 of file Matrix_Base.cxx.

template<class T , class Allocator >
void * Seldon::Matrix_Base< T, Allocator >::GetDataVoid (  )  const [inherited]

Returns a pointer of type "void*" to the data array.

Returns a pointer of type "void*" to data, i.e. the data array 'data_'.

Returns:
A pointer of type "void*" to the data array.

Definition at line 234 of file Matrix_Base.cxx.

template<class T , class Allocator >
int Seldon::Matrix_Base< T, Allocator >::GetM ( const Seldon::SeldonTranspose status  )  const [inherited]

Returns the number of rows of the matrix possibly transposed.

Parameters:
status assumed status about the transposition of the matrix.
Returns:
The number of rows of the possibly-transposed matrix.

Reimplemented in Seldon::SubMatrix_Base< T, Prop, M, Allocator >.

Definition at line 130 of file Matrix_Base.cxx.

template<class T , class Allocator >
int Seldon::Matrix_Base< T, Allocator >::GetN ( const Seldon::SeldonTranspose status  )  const [inherited]

Returns the number of columns of the matrix possibly transposed.

Parameters:
status assumed status about the transposition of the matrix.
Returns:
The number of columns of the possibly-transposed matrix.

Reimplemented in Seldon::SubMatrix_Base< T, Prop, M, Allocator >.

Definition at line 145 of file Matrix_Base.cxx.

template<class T , class Prop , class Storage , class Allocator >
Mat & Seldon::PetscMatrix< T, Prop, Storage, Allocator >::GetPetscMatrix (  )  [inline]

Returns a reference on the inner petsc matrix.

Returns:
A reference on the inner petsc matrix.

Definition at line 138 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
const Mat & Seldon::PetscMatrix< T, Prop, Storage, Allocator >::GetPetscMatrix (  )  const [inline]

Returns a const reference on the inner petsc matrix.

Returns:
A const reference on the inner petsc matrix.

Definition at line 150 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::GetProcessorRowRange ( int &  i,
int &  j 
) const

Returns the range of row indices owned by this processor.

The matrix is laid out with the first $n_1$ rows on the first processor, next $n_2$ rows on the second, etc. If the current processor is $k$, this method returns $n_k$ in i and $n_{k+1}$ in j. If i is set to PETSC_NULL on entry, it is not modified by this function. Same is true for j.

Parameters:
[in,out] i the index of the first local row.
[in,out] j the index of the last local row, plus 1.

Definition at line 307 of file PetscMatrix.cxx.

template<class T , class Allocator >
int Seldon::Matrix_Base< T, Allocator >::GetSize (  )  const [inherited]
template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Nullify (  )  [inline]

Clears the matrix without releasing memory.

On exit, the matrix is empty and the memory has not been released. It is useful for low level manipulations on a Matrix instance.

Warning:
Memory is not released except for me_.

Definition at line 125 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
PetscMatrix< T, Prop, Storage, Allocator >::reference Seldon::PetscMatrix< T, Prop, Storage, Allocator >::operator[] ( int  i  )  [inline]

Access to elements of the data array.

Provides a direct access to the data array.

Parameters:
i index.
Returns:
i-th element of the data array.

Definition at line 236 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
PetscMatrix< T, Prop, Storage, Allocator >::const_reference Seldon::PetscMatrix< T, Prop, Storage, Allocator >::operator[] ( int  i  )  const [inline]

Access to elements of the data array.

Provides a direct access to the data array.

Parameters:
i index.
Returns:
i-th element of the data array.

Definition at line 250 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Print ( int  a,
int  b,
int  m,
int  n 
) const

Displays a sub-matrix on the standard output.

The sub-matrix is defined by its upper-left corner (a, b) and its bottom-right corner (m, n). So, elements with indices in [a, m] x [b, n] are displayed on the standard output, in text format. Each row is displayed on a single line and elements of a row are delimited by tabulations.

Parameters:
a row index of the upper-left corner.
b column index of the upper-left corner.
m row index of the bottom-right corner.
n column index of the bottom-right corner.

Definition at line 408 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Print ( int  l  )  const

Displays a square sub-matrix on the standard output.

The sub-matrix is defined by its bottom-right corner (l, l). So, elements with indices in [0, 0] x [l, l] are displayed on the standard output, in text format. Each row is displayed on a single line and elements of a row are delimited by tabulations.

Parameters:
l dimension of the square matrix to be displayed.

Definition at line 425 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Read ( string  FileName  ) 

Reads the matrix from a file.

Reads a matrix stored in binary format in a file. The number of rows (integer) and the number of columns (integer) are read, and matrix elements are then read in the same order as it should be in memory (e.g. row-major storage).

Parameters:
FileName input file name.

Definition at line 538 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Read ( istream &  FileStream  ) 

Reads the matrix from an input stream.

Reads a matrix in binary format from an input stream. The number of rows (integer) and the number of columns (integer) are read, and matrix elements are then read in the same order as it should be in memory (e.g. row-major storage).

Parameters:
FileStream input stream.

Definition at line 566 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::ReadText ( string  FileName  ) 

Reads the matrix from a file.

Reads a matrix stored in text format in a file.

Parameters:
FileName input file name.

Definition at line 579 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::ReadText ( istream &  FileStream  ) 

Reads the matrix from an input stream.

Reads a matrix in text format from an input stream.

Parameters:
FileStream input stream.

Definition at line 604 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Resize ( int  i,
int  j 
) [inline]

Reallocates memory to resize the matrix and keeps previous entries.

On exit, the matrix is a i x j matrix.

Parameters:
i new number of rows.
j new number of columns.
Warning:
The previous entries are kept, extra-entries may not be initialized (depending of the allocator).

Definition at line 166 of file PetscMatrix.cxx.

template<class T, class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::SetBuffer ( int  i,
int  j,
value,
InsertMode  insert_mode = INSERT_VALUES 
)

Inserts or adds values into certain locations of a matrix.

Warning:
These values may be cached, so 'Flush' must be called after all calls to SetBuffer() have been completed.
Parameters:
[in] i row index where to insert the value.
[in] i column index where to insert the value.
[in] value the value to insert.
[in] insert_mode either INSERT_VALUES or ADD_VALUES, where ADD_VALUES adds the value to the entry, and INSERT_VALUES replaces existing entry with new value.

Definition at line 275 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::SetCommunicator ( MPI_Comm  mpi_communicator  )  [inline]

Sets the MPI communicator.

Parameters:
[in] mpi_communicator the mpi communicator to be set.

Definition at line 72 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::SetData ( int  i,
int  j,
pointer  data 
) [inline]

Changes the size of the matrix and sets its data array // (low level method).

The matrix is first cleared (memory is freed). The matrix is then resized to a i x j matrix, and the data array of the matrix is set to 'data'. 'data' elements are not duplicated: the new data array of the matrix is the 'data' array. It is useful to create a matrix from pre-existing data.

Parameters:
i new number of rows.
j new number of columns.
data new array storing elements.
Warning:
'data' has to be used carefully outside the object. Unless you use 'Nullify', 'data' will be freed by the destructor, which means that 'data' must have been allocated carefully. The matrix allocator should be compatible.
Note:
This method should only be used by advanced users.

Definition at line 191 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
PetscMatrix< T, Prop, Storage, Allocator >::reference Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Val ( int  i,
int  j 
) [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
i row index.
j column index.
Returns:
Element (i, j) of the matrix.

Definition at line 222 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
PetscMatrix< T, Prop, Storage, Allocator >::const_reference Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Val ( int  i,
int  j 
) const [inline]

Access operator.

Returns the value of element (i, j).

Parameters:
i row index.
j column index.
Returns:
Element (i, j) of the matrix.

Definition at line 207 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Write ( string  FileName,
bool  with_size 
) const

Writes the matrix in a file.

Stores the matrix in a file in binary format. The number of rows (integer) and the number of columns (integer) are written, and matrix elements are then written in the same order as in memory (e.g. row-major storage).

Parameters:
FileName output file name.

Definition at line 447 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Write ( ostream &  FileStream,
bool  with_size 
) const

Writes the matrix to an output stream.

Writes the matrix to an output stream in binary format. The number of rows (integer) and the number of columns (integer) are written, and matrix elements are then written in the same order as in memory (e.g. row-major storage).

Parameters:
FileStream output stream.

Definition at line 475 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::WriteText ( string  FileName  )  const

Writes the matrix in a file.

Stores the matrix in a file in text format. Only matrix elements are written (not dimensions). Each row is written on a single line and elements of a row are delimited by tabulations.

Parameters:
FileName output file name.

Definition at line 492 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::WriteText ( ostream &  FileStream  )  const

Writes the matrix to an output stream.

Writes the matrix to an output stream in text format. Only matrix elements are written (not dimensions). Each row is written on a single line and elements of a row are delimited by tabulations.

Parameters:
FileStream output stream.

Definition at line 522 of file PetscMatrix.cxx.

template<class T , class Prop , class Storage , class Allocator >
void Seldon::PetscMatrix< T, Prop, Storage, Allocator >::Zero (  ) 

Sets all elements to zero.

Warning:
It fills the memory with zeros. If the matrix stores complex structures, use 'Fill' instead.

Definition at line 341 of file PetscMatrix.cxx.


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