Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType > Class Template Reference

The Matrix class defines a (MPI-)distributed matrix. More...

#include <ginkgo/core/distributed/matrix.hpp>

Inheritance diagram for gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >:
[legend]
Collaboration diagram for gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >:
[legend]

Public Types

using value_type = ValueType
 
using index_type = GlobalIndexType
 
using local_index_type = LocalIndexType
 
using global_index_type = GlobalIndexType
 
using global_vector_type
 
using local_vector_type = typename global_vector_type::local_vector_type
 
- Public Types inherited from gko::EnablePolymorphicAssignment< ConcreteLinOp >
using result_type
 
- Public Types inherited from gko::ConvertibleTo< ResultType >
using result_type = ResultType
 

Public Member Functions

void convert_to (Matrix< next_precision< value_type >, local_index_type, global_index_type > *result) const override
 
void move_to (Matrix< next_precision< value_type >, local_index_type, global_index_type > *result) override
 
void read_distributed (const device_matrix_data< value_type, global_index_type > &data, ptr_param< const Partition< local_index_type, global_index_type > > partition)
 Reads a square matrix from the device_matrix_data structure and a global partition.
 
void read_distributed (const matrix_data< value_type, global_index_type > &data, ptr_param< const Partition< local_index_type, global_index_type > > partition)
 Reads a square matrix from the matrix_data structure and a global partition.
 
void read_distributed (const device_matrix_data< value_type, global_index_type > &data, ptr_param< const Partition< local_index_type, global_index_type > > row_partition, ptr_param< const Partition< local_index_type, global_index_type > > col_partition)
 Reads a matrix from the device_matrix_data structure, a global row partition, and a global column partition.
 
void read_distributed (const matrix_data< value_type, global_index_type > &data, ptr_param< const Partition< local_index_type, global_index_type > > row_partition, ptr_param< const Partition< local_index_type, global_index_type > > col_partition)
 Reads a matrix from the matrix_data structure, a global row partition, and a global column partition.
 
std::shared_ptr< const LinOpget_local_matrix () const
 Get read access to the stored local matrix.
 
std::shared_ptr< const LinOpget_non_local_matrix () const
 Get read access to the stored non-local matrix.
 
 Matrix (const Matrix &other)
 Copy constructs a Matrix.
 
 Matrix (Matrix &&other) noexcept
 Move constructs a Matrix.
 
Matrixoperator= (const Matrix &other)
 Copy assigns a Matrix.
 
Matrixoperator= (Matrix &&other)
 Move assigns a Matrix.
 
- Public Member Functions inherited from gko::experimental::EnableDistributedLinOp< ConcreteLinOp, PolymorphicBase >
const ConcreteLinOpapply (ptr_param< const LinOp > b, ptr_param< LinOp > x) const
 
ConcreteLinOpapply (ptr_param< const LinOp > b, ptr_param< LinOp > x)
 
const ConcreteLinOpapply (ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x) const
 
ConcreteLinOpapply (ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x)
 
- Public Member Functions inherited from gko::EnableAbstractPolymorphicObject< AbstractObject, PolymorphicBase >
std::unique_ptr< AbstractObjectcreate_default (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< AbstractObjectcreate_default () const
 
std::unique_ptr< AbstractObjectclone (std::shared_ptr< const Executor > exec) const
 
std::unique_ptr< AbstractObjectclone () const
 
AbstractObjectcopy_from (const PolymorphicObject *other)
 
template<typename Derived >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, AbstractObject > * copy_from (std::unique_ptr< Derived > &&other)
 
template<typename Derived >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, AbstractObject > * copy_from (const std::unique_ptr< Derived > &other)
 
AbstractObjectcopy_from (const std::shared_ptr< const PolymorphicObject > &other)
 
AbstractObjectmove_from (ptr_param< PolymorphicObject > other)
 
AbstractObjectclear ()
 
- Public Member Functions inherited from gko::PolymorphicObject
PolymorphicObjectoperator= (const PolymorphicObject &)
 
std::unique_ptr< PolymorphicObjectcreate_default (std::shared_ptr< const Executor > exec) const
 Creates a new "default" object of the same dynamic type as this object.
 
std::unique_ptr< PolymorphicObjectcreate_default () const
 Creates a new "default" object of the same dynamic type as this object.
 
std::unique_ptr< PolymorphicObjectclone (std::shared_ptr< const Executor > exec) const
 Creates a clone of the object.
 
std::unique_ptr< PolymorphicObjectclone () const
 Creates a clone of the object.
 
PolymorphicObjectcopy_from (const PolymorphicObject *other)
 Copies another object into this object.
 
template<typename Derived , typename Deleter >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * copy_from (std::unique_ptr< Derived, Deleter > &&other)
 Moves another object into this object.
 
template<typename Derived , typename Deleter >
std::enable_if_t< std::is_base_of< PolymorphicObject, std::decay_t< Derived > >::value, PolymorphicObject > * copy_from (const std::unique_ptr< Derived, Deleter > &other)
 Copies another object into this object.
 
PolymorphicObjectcopy_from (const std::shared_ptr< const PolymorphicObject > &other)
 Copies another object into this object.
 
PolymorphicObjectmove_from (ptr_param< PolymorphicObject > other)
 Moves another object into this object.
 
PolymorphicObjectclear ()
 Transforms the object into its default state.
 
std::shared_ptr< const Executorget_executor () const noexcept
 Returns the Executor of the object.
 
- Public Member Functions inherited from gko::log::EnableLogging< PolymorphicObject >
void add_logger (std::shared_ptr< const Logger > logger) override
 Adds a new logger to the list of subscribed loggers.
 
void remove_logger (const Logger *logger) override
 Removes a logger from the list of subscribed loggers.
 
void remove_logger (ptr_param< const Logger > logger)
 
const std::vector< std::shared_ptr< const Logger > > & get_loggers () const override
 Returns the vector containing all loggers registered at this object.
 
void clear_loggers () override
 Remove all loggers registered at this object.
 
- Public Member Functions inherited from gko::log::Loggable
void remove_logger (ptr_param< const Logger > logger)
 
- Public Member Functions inherited from gko::EnablePolymorphicAssignment< ConcreteLinOp >
void convert_to (result_type *result) const override
 Converts the implementer to an object of type result_type.
 
void move_to (result_type *result) override
 Converts the implementer to an object of type result_type by moving data from this object.
 
- Public Member Functions inherited from gko::ConvertibleTo< ResultType >
virtual void convert_to (result_type *result) const =0
 Converts the implementer to an object of type result_type.
 
void convert_to (ptr_param< result_type > result) const
 
virtual void move_to (result_type *result)=0
 Converts the implementer to an object of type result_type by moving data from this object.
 
void move_to (ptr_param< result_type > result)
 
- Public Member Functions inherited from gko::experimental::distributed::DistributedBase
 DistributedBase (const DistributedBase &other)=default
 
 DistributedBase (DistributedBase &&other)=default
 
DistributedBaseoperator= (const DistributedBase &)
 Copy assignment that doesn't change the used mpi::communicator.
 
DistributedBaseoperator= (DistributedBase &&) noexcept
 Move assignment that doesn't change the used mpi::communicator.
 
mpi::communicator get_communicator () const
 Access the used mpi::communicator.
 

Friends

class EnableCreateMethod< Matrix >
 
class EnableDistributedPolymorphicObject< Matrix, LinOp >
 
class Matrix< next_precision< ValueType >, LocalIndexType, GlobalIndexType >
 

Additional Inherited Members

- Static Public Member Functions inherited from gko::EnableCreateMethod< ConcreteType >
template<typename... Args>
static std::unique_ptr< ConcreteTypecreate (Args &&... args)
 

Detailed Description

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
class gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >

The Matrix class defines a (MPI-)distributed matrix.

The matrix is stored in a row-wise distributed format. Each process owns a specific set of rows, where the assignment of rows is defined by a row Partition. The following depicts the distribution of global rows according to their assigned part-id (which will usually be the owning process id):

0 | .. 1 2 .. .. .. | 0 | .. 1 2 .. .. .. |
1 | 3 4 .. .. .. .. | | 13 .. .. .. 14 .. |
2 | .. 5 6 .. 7 .. | ----> 1 | 3 4 .. .. .. .. |
2 | .. .. .. 8 .. 9 | ----> | .. .. .. 10 11 12 |
1 | .. .. .. 10 11 12 | 2 | .. 5 6 .. 7 .. |
0 | 13 .. .. .. 14 .. | | .. .. .. 8 .. 9 |
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803

The local rows are further split into two matrices on each process. One matrix, called local, contains only entries from columns that are also owned by the process, while the other one, called non_local, contains entries from columns that are not owned by the process. The non-local matrix is stored in a compressed format, where empty columns are discarded and the remaining columns are renumbered. This splitting is depicted in the following:

0 | .. 1 ! 2 .. ! .. .. | | .. 1 | | 2 |
0 | 3 4 ! .. .. ! .. .. | | 3 4 | | .. |
|-----------------------|
1 | .. 5 ! 6 .. ! 7 .. | ----> | 6 .. | | 5 7 .. |
1 | .. .. ! .. 8 ! .. 9 | ----> | 8 .. | | .. .. 9 |
|-----------------------|
2 | .. .. ! .. 10 ! 11 12 | | 11 12 | | .. 10 |
2 | 13 .. ! .. .. ! 14 .. | | 14 .. | | 13 .. |

This uses the same ownership of the columns as for the rows. Additionally, the ownership of the columns may be explicitly defined with an second column partition. If that is not provided, the same row partition will be used for the columns. Using a column partition also allows to create non-square matrices, like the one below:

P_R/P_C 2 2 0 1
0 | .. 1 2 .. | | 2 | | 1 .. |
0 | 3 4 .. .. | | .. | | 3 4 |
|-------------|
1 | .. 5 6 .. | ----> | .. | | 6 5 |
1 | .. .. .. 8 | ----> | 8 | | .. .. |
|-------------|
2 | .. .. .. 10 | | .. .. | | 10 |
2 | 13 .. .. .. | | 13 .. | | .. |

Here P_R denotes the row partition and P_C denotes the column partition.

The Matrix should be filled using the read_distributed method, e.g.

mat->read_distributed(matrix_data, part);
The Matrix class defines a (MPI-)distributed matrix.
Definition matrix.hpp:271
static std::unique_ptr< Partition > build_from_mapping(std::shared_ptr< const Executor > exec, const array< comm_index_type > &mapping, comm_index_type num_parts)
Builds a partition from a given mapping global_index -> part_id.
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:155

or if different partitions for the rows and columns are used:

This will set the dimensions of the global and local matrices automatically by deducing the sizes from the partitions.

By default the Matrix type uses Csr for both stored matrices. It is possible to explicitly change the datatype for the stored matrices, with the constraint that the new type should implement the LinOp and ReadableFromMatrixData interface. The type can be set by:

exec, comm,
Ell<ValueType, LocalIndexType>::create(exec).get(),
Coo<ValueType, LocalIndexType>::create(exec).get());

Alternatively, the helper function with_matrix_type can be used:

See also
with_matrix_type

The Matrix LinOp supports the following operations:

experimental::distributed::Matrix *A; // distributed matrix
experimental::distributed::Vector *b, *x; // distributed multi-vectors
matrix::Dense *alpha, *beta; // scalars of dimension 1x1
// Applying to distributed multi-vectors computes an SpMV/SpMM product
A->apply(b, x) // x = A*b
A->apply(alpha, b, beta, x) // x = alpha*A*b + beta*x
Vector is a format which explicitly stores (multiple) distributed column vectors in a dense storage f...
Definition vector.hpp:92
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:136
Template Parameters
ValueTypeThe underlying value type.
LocalIndexTypeThe index type used by the local matrices.
GlobalIndexTypeThe type for global indices.

Member Typedef Documentation

◆ global_vector_type

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
using gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::global_vector_type

Constructor & Destructor Documentation

◆ Matrix() [1/2]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::Matrix ( const Matrix< ValueType, LocalIndexType, GlobalIndexType > & other)

Copy constructs a Matrix.

Parameters
otherMatrix to copy from.

◆ Matrix() [2/2]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::Matrix ( Matrix< ValueType, LocalIndexType, GlobalIndexType > && other)
noexcept

Move constructs a Matrix.

Parameters
otherMatrix to move from.

Member Function Documentation

◆ get_local_matrix()

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
std::shared_ptr< const LinOp > gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::get_local_matrix ( ) const
inline

Get read access to the stored local matrix.

Returns
Shared pointer to the stored local matrix

◆ get_non_local_matrix()

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
std::shared_ptr< const LinOp > gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::get_non_local_matrix ( ) const
inline

Get read access to the stored non-local matrix.

Returns
Shared pointer to the stored non-local matrix

◆ operator=() [1/2]

Copy assigns a Matrix.

Parameters
otherMatrix to copy from, has to have a communicator of the same size as this.
Returns
this.

◆ operator=() [2/2]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
Matrix & gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::operator= ( Matrix< ValueType, LocalIndexType, GlobalIndexType > && other)

Move assigns a Matrix.

Parameters
otherMatrix to move from, has to have a communicator of the same size as this.
Returns
this.

◆ read_distributed() [1/4]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
void gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::read_distributed ( const device_matrix_data< value_type, global_index_type > & data,
ptr_param< const Partition< local_index_type, global_index_type > > partition )

Reads a square matrix from the device_matrix_data structure and a global partition.

The global size of the final matrix is inferred from the size of the partition. Both the number of rows and columns of the device_matrix_data are ignored.

Note
The matrix data can contain entries for rows other than those owned by the process. Entries for those rows are discarded.
Parameters
dataThe device_matrix_data structure.
partitionThe global row and column partition.

◆ read_distributed() [2/4]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
void gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::read_distributed ( const device_matrix_data< value_type, global_index_type > & data,
ptr_param< const Partition< local_index_type, global_index_type > > row_partition,
ptr_param< const Partition< local_index_type, global_index_type > > col_partition )

Reads a matrix from the device_matrix_data structure, a global row partition, and a global column partition.

The global size of the final matrix is inferred from the size of the row partition and the size of the column partition. Both the number of rows and columns of the device_matrix_data are ignored.

Note
The matrix data can contain entries for rows other than those owned by the process. Entries for those rows are discarded.
Parameters
dataThe device_matrix_data structure.
row_partitionThe global row partition.
col_partitionThe global col partition.

◆ read_distributed() [3/4]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
void gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::read_distributed ( const matrix_data< value_type, global_index_type > & data,
ptr_param< const Partition< local_index_type, global_index_type > > partition )

Reads a square matrix from the matrix_data structure and a global partition.

See also
read_distributed
Note
For efficiency it is advised to use the device_matrix_data overload.

◆ read_distributed() [4/4]

template<typename ValueType = default_precision, typename LocalIndexType = int32, typename GlobalIndexType = int64>
void gko::experimental::distributed::Matrix< ValueType, LocalIndexType, GlobalIndexType >::read_distributed ( const matrix_data< value_type, global_index_type > & data,
ptr_param< const Partition< local_index_type, global_index_type > > row_partition,
ptr_param< const Partition< local_index_type, global_index_type > > col_partition )

Reads a matrix from the matrix_data structure, a global row partition, and a global column partition.

See also
read_distributed
Note
For efficiency it is advised to use the device_matrix_data overload.

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