MADNESS  version 0.9
Public Member Functions | Protected Member Functions | Friends | List of all members
madness::DistributedMatrix< T > Class Template Reference

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

#include <systolic.h>

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

Public Member Functions

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

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. More...
 
- 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) More...
 

Friends

DistributedMatrix< T > interleave_rows (const DistributedMatrix< T > &a, const DistributedMatrix< T > &b)
 Generates a distributed matrix with rows of a and b interleaved. More...
 
DistributedMatrix< T > concatenate_rows (const DistributedMatrix< T > &a, const DistributedMatrix< T > &b)
 Generates a distributed matrix with rows of a and b concatenated. More...
 

Additional Inherited Members

- Protected Attributes inherited from madness::DistributedMatrixDistribution
Worldpworld
 
int64_t P
 
ProcessID rank
 
int64_t n
 
int64_t m
 
int64_t tilen
 
int64_t tilem
 
int64_t Pcoldim
 
int64_t Prowdim
 
int64_t Pcol
 
int64_t Prow
 
int64_t ilo
 
int64_t ihi
 
int64_t jlo
 
int64_t jhi
 
int64_t idim
 
int64_t jdim
 

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.

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

template<typename T>
madness::DistributedMatrix< T >::DistributedMatrix ( World world,
int64_t  n,
int64_t  m,
int64_t  coltile,
int64_t  rowtile 
)
inline
template<typename T>
virtual madness::DistributedMatrix< T >::~DistributedMatrix ( )
inlinevirtual
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
template<typename T>
madness::DistributedMatrix< T >::DistributedMatrix ( )
inline

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

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

Constructs a distributed matrix with given distribution info.

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)

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

Member Function Documentation

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

Frees memory and resets state to same as default constructor.

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

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

Parameters
[in]Theinput tensor
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]jhjghLast j index in patch

Referenced by madness::matrix_inner(), and matrix_inner().

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]Theoutput tensor (assumed already allocated to be at least large enough in both dimensions)

Referenced by distributed_localize_PM(), madness::SCF::initial_guess(), madness::SCF::make_fock_matrix(), and madness::transform().

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]jhjghLast j index in patch
template<typename T>
void madness::DistributedMatrix< T >::copyin ( const Tensor< T > &  s)
inline

Given the full matrix(n,m), copy in the data range local to this processor.

Referenced by main(), and plocalize_boys().

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

Given the full matrix s(n,m), copy out the data range local to this processor.

Referenced by main().

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

Returns const reference to data.

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)
}
}
Returns
Reference to non-constant tensor holding the local data
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
template<typename T>
void madness::DistributedMatrix< T >::extract_columns ( int64_t  jlow,
int64_t  jhigh,
DistributedMatrix< T > &  U 
) const
inline

Referenced by distributed_localize_PM().

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

Fills the matrix with the provided function of the indices.

Parameters
[in]fThe matrix is filled using a[i,j]=f(i,j)

Referenced by madness::DistributedMatrix< double >::fill_identity().

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

Fills the matrix with a scalar.

Parameters
[in]valueThe matrix is filled using a[i,j]=value
template<typename T>
void madness::DistributedMatrix< T >::fill_identity ( )
inline

Referenced by distributed_localize_PM().

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

Gets element (i,j) if (i,j) is local, otherwise throws MadnessException.

template<typename T>
void madness::DistributedMatrix< T >::get_colrange ( int  p,
int64_t &  ilow,
int64_t &  ihigh 
) const
inline

Returns the inclusive range of column indices on processor p.

If there is no data on this processor it returns ilow=0 and ihigh=-1

Referenced by madness::SystolicMatrixAlgorithm< double >::SystolicMatrixAlgorithm().

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

Returns true if the matrix is column distributed (i.e., row dimension not distributed)

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

template<typename T>
bool madness::DistributedMatrix< T >::is_row_distributed ( ) const
inline

Returns true if the matrix is row distributed (i.e., column dimension not distributed)

Referenced by madness::concatenate_columns().

template<typename T>
int64_t madness::DistributedMatrix< T >::local_coldim ( ) const
inline

Returns the no. of column elements stored on this processor.

template<typename T>
void madness::DistributedMatrix< T >::local_colrange ( int64_t &  ilow,
int64_t &  ihigh 
) const
inline

Returns the inclusive range of column indices on this processor.

If there is no data on this processor it returns ilow=0 and ihigh=-1

Referenced by madness::idMatrix().

template<typename T>
int64_t madness::DistributedMatrix< T >::local_rowdim ( ) const
inline

Returns the no. of row elements stored on this processor.

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

Returns the inclusive range of row indices on this processor.

If there is no data on this processor it returns jlow=0 and jhigh=-1

template<typename T>
int64_t madness::DistributedMatrix< T >::local_size ( ) const
inline
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
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
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
template<typename T>
DistributedMatrix<T>& madness::DistributedMatrix< T >::operator= ( const DistributedMatrix< T > &  A)
inline

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

template<typename T>
int64_t madness::DistributedMatrix< T >::process_coldim ( ) const
inline

Returns the no. of processors in the column dimension.

Referenced by madness::DistributedMatrix< double >::get_colrange(), and madness::DistributedMatrix< double >::is_row_distributed().

template<typename T>
int64_t madness::DistributedMatrix< T >::process_rowdim ( ) const
inline
template<typename T>
int64_t madness::DistributedMatrix< T >::rowdim ( ) const
inline
template<typename T>
int64_t madness::DistributedMatrix< T >::rowtile ( ) const
inline

Returns the row tile size.

Referenced by madness::concatenate_columns(), madness::idMatrix(), and madness::interleave_rows().

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

Sets element (i,j) to v if (i,j) is local, otherwise throws MadnessException.

Friends And Related Function Documentation

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

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

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

I.e., c[i,j] = a[i,j] if n<na or b[i,j] 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.

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
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.

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

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