MADNESS 0.10.1
Public Member Functions | Protected Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
madness::DistributedMatrix< T > Class Template Reference

Manages data associated with a row/column/block distributed array. More...

#include <distributed_matrix.h>

Inheritance diagram for madness::DistributedMatrix< T >:
Inheritance graph
[legend]
Collaboration diagram for madness::DistributedMatrix< T >:
Collaboration graph
[legend]

Public Member Functions

 DistributedMatrix ()
 Default constructor makes an empty matrix that cannot be used except as a target for assignemnt.
 
 DistributedMatrix (const DistributedMatrix< T > &A, bool deepcopy=false)
 Copy constructor copies dimensions, distribution, and shallow copy of content (unless deepcopy=true)
 
 DistributedMatrix (const DistributedMatrixDistribution &d)
 Constructs a distributed matrix with given distribution info.
 
virtual ~DistributedMatrix ()
 
void clear ()
 Frees memory and resets state to same as default constructor.
 
void copy_from_replicated (const Tensor< T > &s)
 Copy from the replicated (m,n) matrix into the distributed matrix.
 
void copy_from_replicated_patch (int64_t ilow, int64_t ihigh, int64_t jlow, int64_t jhigh, const Tensor< T > &s)
 Copy from replicated patch (inclusive index range) into the distributed matrix.
 
void copy_to_replicated (Tensor< T > &s) const
 Copy from the distributed (m,n) matrix into the replicated matrix (collective call)
 
void copy_to_replicated_patch (int64_t ilow, int64_t ihigh, int64_t jlow, int64_t jhigh, Tensor< T > &s) const
 Copy from distributed matrix into replicated patch (inclusive index range; collective call)
 
Tensor< T > & data ()
 Returns reference to the local data.
 
const Tensor< T > & data () const
 Returns const reference to data.
 
void extract_columns (int64_t jlow, int64_t jhigh, DistributedMatrix< T > &U) const
 
template<typename funcT >
void fill (const funcT &f)
 Fills the matrix with the provided function of the indices.
 
void fill (T value)
 Fills the matrix with a scalar.
 
void fill_identity ()
 
T get (int64_t i, int64_t j) const
 Gets element (i,j) if (i,j) is local, otherwise throws MadnessException.
 
template<typename R >
bool has_same_dimension_and_distribution (const DistributedMatrix< R > &A)
 
DistributedMatrix< T > & operator*= (const T s)
 Inplace scale by a constant.
 
DistributedMatrix< Toperator+ (const DistributedMatrix< T > &A) const
 Out of place addition — dimensions and distribution must be identical.
 
DistributedMatrix< T > & operator+= (const DistributedMatrix< T > &A)
 Inplace addition — dimensions and distribution must be identical.
 
DistributedMatrix< T > & operator= (const DistributedMatrix< T > &A)
 Assigment copies dimensions, distribution, and shallow copy of content.
 
void set (int64_t i, int64_t j, const T x)
 Sets element (i,j) to v if (i,j) is local, otherwise throws MadnessException.
 
- Public Member Functions inherited from madness::DistributedMatrixDistribution
 DistributedMatrixDistribution ()
 Default constructor makes an invalid distribution.
 
virtual ~DistributedMatrixDistribution ()
 
void clear ()
 Resets state to same as default constructor.
 
int64_t coldim () const
 Returns the column dimension of the matrix ... i.e., n for A(n,m)
 
int64_t coltile () const
 Returns the column tile size.
 
const DistributedMatrixDistributiondistribution () const
 Returns the distribution (aka *this)
 
void get_colrange (int p, int64_t &ilow, int64_t &ihigh) const
 Returns the inclusive range of column indices on processor p.
 
void get_range (int p, int64_t &ilow, int64_t &ihigh, int64_t &jlow, int64_t &jhigh) const
 Returns the inclusive ranges of column and row indicies on processor p.
 
void get_rowrange (int p, int64_t &jlow, int64_t &jhigh) const
 Returns the inclusive range of row indices on processor p.
 
Worldget_world () const
 Returns the associated world.
 
bool is_column_distributed () const
 Returns true if the matrix is column distributed (i.e., row dimension not distributed)
 
bool is_row_distributed () const
 Returns true if the matrix is row distributed (i.e., column dimension not distributed)
 
int64_t local_coldim () const
 Returns the no. of column elements stored on this processor.
 
void local_colrange (int64_t &ilow, int64_t &ihigh) const
 Returns the inclusive range of column indices on this processor.
 
int64_t local_ihigh () const
 Returns the last column index on this processor (-1 if no data present)
 
int64_t local_ilow () const
 Returns the first column index on this processor (0 if no data present)
 
int64_t local_jhigh () const
 Returns the last row index on this processor (0 if no data present)
 
int64_t local_jlow () const
 Returns the first row index on this processor (0 if no data present)
 
int64_t local_rowdim () const
 Returns the no. of row elements stored on this processor.
 
void local_rowrange (int64_t &jlow, int64_t &jhigh) const
 Returns the inclusive range of row indices on this processor.
 
int64_t local_size () const
 Returns the total no. of elements stored on this processor.
 
bool operator== (const DistributedMatrixDistribution &d) const
 
ProcessID owner (int64_t i, int64_t j) const
 Returns the number of the process that owns element (i,j)
 
int64_t process_coldim () const
 Returns the no. of processors in the column dimension.
 
int64_t process_rowdim () const
 Returns the no. of processors in the row dimension.
 
int64_t rowdim () const
 Returns the row dimension of the matrix ... i.e., m for A(n,m)
 
int64_t rowtile () const
 Returns the row tile size.
 

Protected Member Functions

 DistributedMatrix (World &world, int64_t n, int64_t m, int64_t coltile, int64_t rowtile)
 Constructs a distributed matrix dimension (n,m) with specified tile sizes and initialized to zero.
 
- Protected Member Functions inherited from madness::DistributedMatrixDistribution
 DistributedMatrixDistribution (World &world, int64_t n, int64_t m, int64_t coltile, int64_t rowtile)
 Constructs distribution and size info for a matrix (for use by factory functions only)
 

Static Private Member Functions

static T idij (const int64_t i, const int64_t j)
 

Private Attributes

Tensor< Tt
 The data.
 

Friends

DistributedMatrix< Tconcatenate_rows (const DistributedMatrix< T > &a, const DistributedMatrix< T > &b)
 Generates a column-distributed matrix with rows of a and b contatenated.
 
DistributedMatrix< Tinterleave_rows (const DistributedMatrix< T > &a, const DistributedMatrix< T > &b)
 Generates a distributed matrix with rows of a and b interleaved.
 

Additional Inherited Members

- Protected Attributes inherited from madness::DistributedMatrixDistribution
int64_t idim
 
int64_t ihi
 Range of column indices on this processor.
 
int64_t ilo
 
int64_t jdim
 Dimension of data on this processor.
 
int64_t jhi
 Range of row indices on this processor.
 
int64_t jlo
 
int64_t m
 Row dimension of A(n,m)
 
int64_t n
 Column dimension of A(n,m)
 
int64_t P
 No. of processors.
 
int64_t Pcol
 Column of processor grid for this processor.
 
int64_t Pcoldim
 Column dimension of processor grid.
 
int64_t Prow
 Row of processor grid for this processor.
 
int64_t Prowdim
 Row dimension of processor grid.
 
Worldpworld
 
ProcessID rank
 My processor rank.
 
int64_t tilem
 Tile size for row.
 
int64_t tilen
 Tile size for column.
 

Detailed Description

template<typename T>
class madness::DistributedMatrix< T >

Manages data associated with a row/column/block distributed array.

The class itself provides limited functionality for accessing the data and is primarily intended to provide base functionality for use by matrix algorithms and other matrix classes.

The constructor is deliberately simple. Factory functions are expected to be the main construction tool.

Assignment and copy are shallow just like for tensor and for the same reasons.

To get a deep copy use the copy function (again just like for tensors).

Constructor & Destructor Documentation

◆ DistributedMatrix() [1/4]

template<typename T >
madness::DistributedMatrix< T >::DistributedMatrix ( World world,
int64_t  n,
int64_t  m,
int64_t  coltile,
int64_t  rowtile 
)
inlineprotected

Constructs a distributed matrix dimension (n,m) with specified tile sizes and initialized to zero.

[deprecated ... use factory functions instead]

The matrix is tiled over a grid of processes as specified by the tile sizes.

Parameters
[in]worldThe world
[in]nThe matrix column dimension
[in]mThe matrix row dimension
[in]coltileTile size for the columns
[in]rowtileTile size for the rows

References madness::DistributedMatrixDistribution::idim, madness::DistributedMatrixDistribution::jdim, and madness::DistributedMatrix< T >::t.

◆ DistributedMatrix() [2/4]

template<typename T >
madness::DistributedMatrix< T >::DistributedMatrix ( )
inline

Default constructor makes an empty matrix that cannot be used except as a target for assignemnt.

◆ DistributedMatrix() [3/4]

template<typename T >
madness::DistributedMatrix< T >::DistributedMatrix ( const DistributedMatrixDistribution d)
inline

Constructs a distributed matrix with given distribution info.

References madness::DistributedMatrixDistribution::idim, madness::DistributedMatrixDistribution::jdim, and madness::DistributedMatrix< T >::t.

◆ DistributedMatrix() [4/4]

template<typename T >
madness::DistributedMatrix< T >::DistributedMatrix ( const DistributedMatrix< T > &  A,
bool  deepcopy = false 
)
inline

Copy constructor copies dimensions, distribution, and shallow copy of content (unless deepcopy=true)

◆ ~DistributedMatrix()

template<typename T >
virtual madness::DistributedMatrix< T >::~DistributedMatrix ( )
inlinevirtual

Member Function Documentation

◆ clear()

template<typename T >
void madness::DistributedMatrix< T >::clear ( )
inline

Frees memory and resets state to same as default constructor.

References madness::DistributedMatrixDistribution::clear(), and madness::DistributedMatrix< T >::t.

◆ copy_from_replicated()

template<typename T >
void madness::DistributedMatrix< T >::copy_from_replicated ( const Tensor< T > &  s)
inline

◆ copy_from_replicated_patch()

template<typename T >
void madness::DistributedMatrix< T >::copy_from_replicated_patch ( int64_t  ilow,
int64_t  ihigh,
int64_t  jlow,
int64_t  jhigh,
const Tensor< T > &  s 
)
inline

Copy from replicated patch (inclusive index range) into the distributed matrix.

Parameters
[in]ilowFirst i index in patch
[in]ihighLast i index in patch
[in]jlowFirst j index in patch
[in]jhighLast j index in patch

References madness::DistributedMatrixDistribution::ihi, madness::DistributedMatrixDistribution::ilo, madness::DistributedMatrixDistribution::jhi, madness::DistributedMatrixDistribution::jlo, and madness::DistributedMatrix< T >::t.

◆ copy_to_replicated()

template<typename T >
void madness::DistributedMatrix< T >::copy_to_replicated ( Tensor< T > &  s) const
inline

Copy from the distributed (m,n) matrix into the replicated matrix (collective call)

The entire output tensor is zeroed, the local data copied into it, and then a global sum performed to replicate the data.

Parameters
[out]sThe output tensor (assumed already allocated to be at least large enough in both dimensions)

References madness::___, madness::DistributedMatrixDistribution::get_world(), madness::World::gop, madness::DistributedMatrixDistribution::ihi, madness::DistributedMatrixDistribution::ilo, madness::DistributedMatrixDistribution::jhi, madness::DistributedMatrixDistribution::jlo, madness::DistributedMatrixDistribution::local_size(), MADNESS_CHECK, madness::WorldGopInterface::sum(), and madness::DistributedMatrix< T >::t.

Referenced by madness::Localizer::compute_localization_matrix(), and madness::SCF::initial_guess().

◆ copy_to_replicated_patch()

template<typename T >
void madness::DistributedMatrix< T >::copy_to_replicated_patch ( int64_t  ilow,
int64_t  ihigh,
int64_t  jlow,
int64_t  jhigh,
Tensor< T > &  s 
) const
inline

Copy from distributed matrix into replicated patch (inclusive index range; collective call)

The entire output tensor is zeroed, relevant local data copied into it, and then a global sum performed to replicate the data.

Parameters
[in]ilowFirst i index in patch
[in]ihighLast i index in patch
[in]jlowFirst j index in patch
[in]jhighLast j index in patch

References madness::DistributedMatrixDistribution::get_world(), madness::World::gop, madness::DistributedMatrixDistribution::ihi, madness::DistributedMatrixDistribution::ilo, madness::DistributedMatrixDistribution::jhi, madness::DistributedMatrixDistribution::jlo, MADNESS_CHECK, madness::WorldGopInterface::sum(), and madness::DistributedMatrix< T >::t.

◆ data() [1/2]

template<typename T >
Tensor< T > & madness::DistributedMatrix< T >::data ( )
inline

Returns reference to the local data.

The local data is a tensor dimension (local_coldim,local_rowdim) and if either of the dimensions are zero there is no data. A natural way to loop thru the data that gives you the actual row and column indices is

const Tensor<T>& t = A.data();
for (int64_t i=A.get_ilow(); i<=A.get_ihigh(); i++) {
for (int64_t j=A.get_jlow(); j<=A.get_jhigh(); j++) {
the ij'th element is t(i-ilo, j-jlo)
}
}
Definition test_ar.cc:118
Tensor< T > t
The data.
Definition distributed_matrix.h:392
A tensor is a multidimension array.
Definition tensor.h:317
double ij(int64_t i, int64_t j)
Definition test_distributed_matrix.cc:8
Returns
Reference to non-constant tensor holding the local data

References madness::DistributedMatrix< T >::t.

Referenced by madness::concatenate_rows(), and madness::DistributedMatrix< T >::extract_columns().

◆ data() [2/2]

template<typename T >
const Tensor< T > & madness::DistributedMatrix< T >::data ( ) const
inline

Returns const reference to data.

The local data is a tensor dimension (local_coldim,local_rowdim) and if either of the dimensions are zero there is no data. A natural way to loop thru the data that gives you the actual row and column indices is

const Tensor<T>& t = A.data();
for (int64_t i=A.get_ilow(); i<=A.get_ihigh(); i++) {
for (int64_t j=A.get_jlow(); j<=A.get_jhigh(); j++) {
the ij'th element is t(i-ilo, j-jlo)
}
}
Returns
Reference to constant tensor holding the local data

References madness::DistributedMatrix< T >::t.

◆ extract_columns()

template<typename T >
void madness::DistributedMatrix< T >::extract_columns ( int64_t  jlow,
int64_t  jhigh,
DistributedMatrix< T > &  U 
) const
inline

◆ fill() [1/2]

template<typename T >
template<typename funcT >
void madness::DistributedMatrix< T >::fill ( const funcT &  f)
inline

◆ fill() [2/2]

template<typename T >
void madness::DistributedMatrix< T >::fill ( T  value)
inline

Fills the matrix with a scalar.

Parameters
[in]valueThe matrix is filled using a[i,j]=value

References madness::DistributedMatrix< T >::t.

◆ fill_identity()

template<typename T >
void madness::DistributedMatrix< T >::fill_identity ( )
inline

◆ get()

template<typename T >
T madness::DistributedMatrix< T >::get ( int64_t  i,
int64_t  j 
) const
inline

◆ has_same_dimension_and_distribution()

template<typename T >
template<typename R >
bool madness::DistributedMatrix< T >::has_same_dimension_and_distribution ( const DistributedMatrix< R > &  A)
inline

◆ idij()

template<typename T >
static T madness::DistributedMatrix< T >::idij ( const int64_t  i,
const int64_t  j 
)
inlinestaticprivate

References T().

◆ operator*=()

template<typename T >
DistributedMatrix< T > & madness::DistributedMatrix< T >::operator*= ( const T  s)
inline

Inplace scale by a constant.

Parameters
[in]sThe scaling factor
Returns
A reference to the current matrix

References madness::DistributedMatrix< T >::t.

◆ operator+()

template<typename T >
DistributedMatrix< T > madness::DistributedMatrix< T >::operator+ ( const DistributedMatrix< T > &  A) const
inline

Out of place addition — dimensions and distribution must be identical.

Parameters
[in]AThe matrix to add to the current matrix
Returns
A new matrix with the same dimensions and distribution as the inputs

References madness::copy(), madness::DistributedMatrix< T >::has_same_dimension_and_distribution(), and MADNESS_CHECK.

◆ operator+=()

template<typename T >
DistributedMatrix< T > & madness::DistributedMatrix< T >::operator+= ( const DistributedMatrix< T > &  A)
inline

Inplace addition — dimensions and distribution must be identical.

Parameters
[in]AThe matrix to add to the current matrix
Returns
A reference to the current matrix

References madness::DistributedMatrix< T >::has_same_dimension_and_distribution(), MADNESS_CHECK, and madness::DistributedMatrix< T >::t.

◆ operator=()

template<typename T >
DistributedMatrix< T > & madness::DistributedMatrix< T >::operator= ( const DistributedMatrix< T > &  A)
inline

Assigment copies dimensions, distribution, and shallow copy of content.

References madness::DistributedMatrix< T >::t.

◆ set()

template<typename T >
void madness::DistributedMatrix< T >::set ( int64_t  i,
int64_t  j,
const T  x 
)
inline

Friends And Related Symbol Documentation

◆ concatenate_rows

template<typename T >
DistributedMatrix< T > concatenate_rows ( const DistributedMatrix< T > &  a,
const DistributedMatrix< T > &  b 
)
friend

Generates a column-distributed matrix with rows of a and b contatenated.

I.e., c[i,j] = a[i,j] if j<na or b[i,j-na] if j>=na

The matrices a and b must have the same column size (i.e., the same number of rows) and be column distributed with the same column tilesze. The result is also column distributed with the same column tilesize as the input matrices.

Parameters
[in]aThe first matrix
[in]bThe second matrix
Returns
The result matrix

◆ interleave_rows

template<typename T >
DistributedMatrix< T > interleave_rows ( const DistributedMatrix< T > &  a,
const DistributedMatrix< T > &  b 
)
friend

Generates a distributed matrix with rows of a and b interleaved.

I.e., the even rows of the result will be rows of a , and the odd rows those of b .

The matrices a and b must have the same dimensions and be identically distributed. The result will have a doubled column dimension and column tile size. The row dimension is unchanged.

Parameters
[in]aThe matrix providing even rows of the result
[in]bThe matrix providing odd rows of the result
Returns
The result matrix

Member Data Documentation

◆ t

template<typename T >
Tensor<T> madness::DistributedMatrix< T >::t
private

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