Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
crmatrix_mpi.h
1 // -*-C++-*-
2 // ==========================================================================
3 // Module mathlib
4 // File crmatrix_mpi.h
5 // Declaration of template class TCompRowMatrixMPI
6 // Distributed (MPI) version of TCompRowMatrix (template sparse matrix in
7 // compressed row format)
8 // Each MPI process operates on a block of matrix rows (r0 <= r < r1)
9 // ==========================================================================
10 
11 #ifndef __CRMATRIXMPI_H
12 #define __CRMATRIXMPI_H
13 
14 #include "mathlib.h"
15 
16 // ==========================================================================
17 // class TCompRowMatrixMPI
18 // ==========================================================================
33 template<class MT> class TCompRowMatrixMPI: public TGenericSparseMatrix<MT> {
34 
35 public:
40 
48  TCompRowMatrixMPI (int rows, int cols);
49 
50  TCompRowMatrixMPI (int rows, int cols,
51  const int *_rowptr, const int *_colidx,
52  int proc_nrows, const int *proc_rows);
53 
67  TCompRowMatrixMPI (int rows, int cols,
68  const int *_rowptr, const int *_colidx,
69  const MT *_data = 0);
70 
75 
80  { return MATRIX_COMPROW; }
81 
92  void Initialise (const int *_rowptr, const int *_colidx,
93  const MT *_data = 0);
94 
102  void MPIRange (int *_r0, int *_r1) const
103  { *_r0 = r0; *_r1 = r1; }
104 
110  void Zero ();
111 
120  MT Get (int r, int c) const;
121 
129  TVector<MT> Row (int r) const;
130 
144  int SparseRow (int r, int *colidx, MT *val) const;
145 
154  TVector<MT> Col (int c) const;
155 
156  virtual void RowScale (const TVector<MT> &scale);
157  // scales the rows with 'scale'
158 
159  virtual void ColScale (const TVector<MT> &scale);
160  // scales the columns with 'scale'
161 
162  virtual void Unlink ();
163  // removes the matrix' link to its data block and deletes the data
164  // block, if necessary
165 
166  bool Exists (int r, int c) const;
167 
168  MT &operator() (int r, int c);
169 
170  int Get_index (int r, int c) const;
171 
172  MT GetNext (int &r, int &c) const;
173 
180  void Ax (const TVector<MT> &x, TVector<MT> &b) const;
181 
182  void Ax (const TVector<MT> &x, TVector<MT> &b, int i1, int i2) const;
183 
184  void ATx (const TVector<MT> &x, TVector<MT> &b) const
185  { xERROR("Not implemented"); }
186 
187  // ======================================================================
188  // Process-specific functions
189  // These methods are invoked only for the current process
190 
199  void Add_proc (int r, int c, MT val);
200 
201  //private:
202 public:
207  void MPIinit();
208 
209  int rnk;
210  int sze;
211 
220  int *rowptr;
221 
228  int *colidx;
229 
230  int r0;
231  int r1;
232  int my_nr;
233  int *my_r;
234 
235  int *mpi_r0;
236  int *mpi_nr;
237 
238  MPI_Datatype mpitp;
239 };
240 
241 
242 // ==========================================================================
243 // typedefs for specific instances of `TCompRowMatrixMPI'
244 
250 
251 // ==========================================================================
252 // extern declarations of TCompRowMatrix (only required for VS)
253 
254 #ifndef MATHLIB_IMPLEMENTATION
255 extern template class MATHLIB TCompRowMatrixMPI<double>;
256 extern template class MATHLIB TCompRowMatrixMPI<float>;
257 extern template class MATHLIB TCompRowMatrixMPI<toast::complex>;
258 extern template class MATHLIB TCompRowMatrixMPI<scomplex>;
259 extern template class MATHLIB TCompRowMatrixMPI<int>;
260 #endif // MATHLIB_IMPLEMENTATION
261 
262 #endif // !__CRMATRIXMPI_H
void Initialise(const int *_rowptr, const int *_colidx, const MT *_data=0)
Re-allocate fill structure and assign values.
TVector< MT > Row(int r) const
Returns a vector containing a copy of row `r'.
Virtual base class for sparse matrix types.
Definition: gsmatrix.h:47
TVector< MT > Col(int c) const
Returns a vector containing a copy of column 'c'.
MPI_Datatype mpitp
MPI data type corresponding to template type.
Definition: crmatrix_mpi.h:238
int my_nr
Number of rows managed by this process.
Definition: crmatrix_mpi.h:232
~TCompRowMatrixMPI()
Matrix destructor.
MatrixStorage StorageType() const
Storage class identifier.
Definition: crmatrix_mpi.h:79
compressed row storage (sparse)
Definition: matrix.h:25
int r0
Low row index for this process - OBSOLETE.
Definition: crmatrix_mpi.h:230
void Zero()
Zero all elements, but keep fill structure.
int sze
Number of MPI processes (>= 1)
Definition: crmatrix_mpi.h:210
int * mpi_r0
array of row offsets for all processes
Definition: crmatrix_mpi.h:235
void Ax(const TVector< MT > &x, TVector< MT > &b) const
Matrix-vector product.
MatrixStorage
Definition: matrix.h:20
bool Exists(int r, int c) const
Checks allocation of a matrix element.
MT Get(int r, int c) const
Retrieve a matrix element.
Distributed compressed-row sparse matrix class.
Definition: crmatrix_mpi.h:33
int r1
High row index + 1 for this process - OBSOLETE.
Definition: crmatrix_mpi.h:231
int * mpi_nr
array of row numbers for all processes
Definition: crmatrix_mpi.h:236
void MPIRange(int *_r0, int *_r1) const
Returns the row range of the current process.
Definition: crmatrix_mpi.h:102
int * colidx
Array of column indices.
Definition: crmatrix_mpi.h:228
int * my_r
List of rows owned by this process.
Definition: crmatrix_mpi.h:233
int SparseRow(int r, int *colidx, MT *val) const
Returns a row of the matrix in sparse format.
int rnk
MPI process id (0 <= rnk < sze)
Definition: crmatrix_mpi.h:209
void Add_proc(int r, int c, MT val)
Add a value to a matrix element (process-specific)
void MPIinit()
MPI data initialisation.
TCompRowMatrixMPI()
Creates a matrix of dimension 0 x 0.
int * rowptr
Array of row pointers.
Definition: crmatrix_mpi.h:220