Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
dnsmatrix_mpi.h
1 // -*-C++-*-
2 // ==========================================================================
3 // General dense matrix class
4 // Distributed (MPI) version
5 // Each MPI process operates on a block of matrix rows (r0 <= r < r1)
6 // ==========================================================================
7 
8 #ifndef __DNSMATRIXMPI_H
9 #define __DNSMATRIXMPI_H
10 
11 #include "mathlib.h"
12 
13 // ==========================================================================
14 // Nonmember declarations
15 // ==========================================================================
16 
17 // ==========================================================================
18 // class TDenseMatrixMPI
19 // ==========================================================================
32 template<class MT> class TDenseMatrixMPI: public TMatrix<MT> {
33 
34 public:
38  TDenseMatrixMPI ();
39 
48  TDenseMatrixMPI (int r, int c);
49 
54 
55  inline MatrixStorage StorageType () const { return MATRIX_DENSE; }
56  // Matrix element storage method
57 
66  void New (int r, int c);
67 
75  void MPIRange (int *_r0, int *_r1) const { *_r0 = r0; *_r1 = r1; }
76 
77  MT Get (int r, int c) const;
78 
79  MT &operator() (int r, int c);
80 
90  TVector<MT> Row (int r) const;
91 
92  TVector<MT> Col (int c) const;
93 
94  int SparseRow (int r, int *ci, MT *rv) const;
95 
105  void SetRow (int r, const TVector<MT> &rval);
106 
107  void ColScale (const TVector<MT> &scale);
108 
109  void RowScale (const TVector<MT> &scale);
110 
118  TVector<MT> RowSum() const;
119 
128  TVector<MT> RowSumSq() const;
129 
137  TVector<MT> ColSum() const;
138 
147  TVector<MT> ColSumSq() const;
148 
159  void Ax (const TVector<MT> &x, TVector<MT> &b) const;
160 
171  void ATx (const TVector<MT> &x, TVector<MT> &b) const;
172 
176  MPI_Datatype MPIType () const;
177 
178 private:
179  void Unlink ();
180  void Alloc (int r, int c);
181 
182  MT *val; // data array (only contains relevant sub-block)
183  int r0, r1; // row index range
184  int nr; // number of rows for process
185  int nr_max; // max number of rows for any process
186  int rnk, sze; // MPI rank of process, MPI size
187 };
188 
189 
190 // ==========================================================================
191 // typedefs for specific instances of `TDenseMatrixMPI'
192 
193 typedef TDenseMatrixMPI<double> RDenseMatrixMPI; // 'double real'
194 typedef TDenseMatrixMPI<float> FDenseMatrixMPI; // 'single real'
196 typedef TDenseMatrixMPI<scomplex> SCDenseMatrixMPI; // 'single complex'
197 typedef TDenseMatrixMPI<int> IDenseMatrixMPI; // 'integer'
198 
199 #ifndef MATHLIB_IMPLEMENTATION
200 extern template class MATHLIB TDenseMatrixMPI<double>;
201 extern template class MATHLIB TDenseMatrixMPI<float>;
202 extern template class MATHLIB TDenseMatrixMPI<toast::complex>;
203 extern template class MATHLIB TDenseMatrixMPI<scomplex>;
204 extern template class MATHLIB TDenseMatrixMPI<int>;
205 #endif // MATHLIB_IMPLEMENTATION
206 
207 #endif // !__DNSMATRIXMPI_H
TVector< MT > RowSumSq() const
Returns a vector of sum of squares for each row.
TVector< MT > Row(int r) const
Returns a row of the matrix.
int SparseRow(int r, int *ci, MT *rv) const
Returns a row of the matrix in sparse format.
TVector< MT > Col(int c) const
Returns a vector containing a copy of column 'c'.
void ATx(const TVector< MT > &x, TVector< MT > &b) const
Matrix-transpose x vector product.
TVector< MT > ColSumSq() const
Returns a vector of sum of squares for each column.
TVector< MT > ColSum() const
Returns a vector of column sums.
MatrixStorage
Definition: matrix.h:20
TDenseMatrixMPI()
Defines a matrix of size 0 x 0.
void SetRow(int r, const TVector< MT > &rval)
Replace entries in row r with the values provided in rval.
dense matrix storage
Definition: matrix.h:21
MatrixStorage StorageType() const
Matrix storage class.
Definition: dnsmatrix_mpi.h:55
MT Get(int r, int c) const
Retrieve a matrix element.
TVector< MT > RowSum() const
Returns a vector of row sums.
void New(int r, int c)
Resize matrix to new dimensions.
Virtual base class for all matrix types (dense and sparse)
Definition: matrix.h:43
void Ax(const TVector< MT > &x, TVector< MT > &b) const
Matrix x vector product.
void MPIRange(int *_r0, int *_r1) const
Returns the row range of the current process.
Definition: dnsmatrix_mpi.h:75
MPI_Datatype MPIType() const
Returns MPI type compatible with template type.
Distributed dense matrix class.
Definition: dnsmatrix_mpi.h:32