explicit_mapmaking
 All Classes Files Pages
matrix.hpp
Go to the documentation of this file.
1 
8 #ifndef EXPLICIT_MAPMAKING_MATRIX_HPP_
9 #define EXPLICIT_MAPMAKING_MATRIX_HPP_
10 
11 #include "grid.hpp"
12 #include "io.hpp"
13 #include <stdio.h>
14 #include <string>
15 #include <boost/filesystem.hpp>
16 
17 namespace fs = boost::filesystem;
18 
19 namespace mapmaking {
20 // Squared matrix
21 // It maximizes the size of the blocks given a processor grid
22 class Matrix {
23  public:
24  Matrix() {}
25  Matrix(Grid* grid, int n_row, int n_col);
26  Matrix Dot(Matrix& right, char trans_left='N', char trans_right='N');
27  std::vector<double>* local_part() { return &local_part_; }
28  int n_row() const { return n_row_; }
29  int n_col() const { return n_col_; }
30  Grid* grid() { return grid_; }
31  std::vector<int>* desc() { return &desc_; }
32  void PrintLocalPart(); // Debugging tools
33  void PrintMatrix(); //
34  void TestAllocation(); //
35  void TestAllocationVector(); //
36  void SaveMatrix(fs::path folder);
37  std::vector<double> GetColumn(int i_col);
38  void LoadMatrix(std::vector<double>& matrix, int root_proc);
39  Matrix& operator+= (const Matrix& matrix);
40  Matrix& operator-= (const Matrix& matrix);
41  Matrix& operator*= (double factor);
42  Matrix& operator/= (double factor);
43  friend Matrix LoadMatrix(fs::path folder, Grid* grid); // TODO turn this into a constructor
44 
45  protected:
46  std::vector<double> local_part_;
47  int block_first_row_ = 0;
48  int n_local_rows_ = 0;
49  int n_local_cols_ = 0;
50  int n_row_;
51  int n_col_;
52  int n_row_block_; // Even by construction
53  int n_col_block_; // Even by construction
54  Grid* grid_ = NULL;
55  std::vector<int> desc_; // Descriptor of the matrix
56  std::vector<double> GatherSubmatrix(int proc, int i_row, int i_col=0, int n_rows=1, int n_cols=1);
57  void ScatterSubmatrix(std::vector<double>& submatrix, int proc, int i_row, int i_col=0, int n_rows=1);
58 };
59 
60  Matrix LoadMatrix(fs::path folder, Grid* grid);
61  Matrix operator+(Matrix m_left, const Matrix& m_right);
62  Matrix operator-(Matrix m_left, const Matrix& m_right);
63  Matrix operator*(Matrix& m_left, Matrix& m_right);
64  Matrix operator*(Matrix m_left, double factor);
65  Matrix operator/(Matrix m_left, double factor);
66 }
67 
68 #endif // EXPLICIT_MAPMAKING_MATRIX_HPP_
Definition: grid.hpp:16
hdf5 and binary io helpers
Definition: atfa.hpp:18
Handle a scalapack grid of processors.
Definition: matrix.hpp:22