Greens-code
A modular quantum transport code
supermatrix_MUMPS.hpp
1 #ifndef SUPERMATRIX_MUMPS_HPP
2 #define SUPERMATRIX_MUMPS_HPP
3 
4 #include <memory>
5 #include "parallel.hpp"
6 #include "supermatrix.hpp"
7 #include "my_mkl.hpp"
8 
9 #ifdef USECBLAS
10 namespace mkl{
11  struct sparse_matrix_t{
12  int nnz;
13  int N;
14  int indexbase;
15  const int* irn;
16  const int* jcn;
17  complex* pointer;
18  };
19 
20  const int SPARSE_MATRIX_TYPE_GENERAL = 0;
21  const int SPARSE_OPERATION_NON_TRANSPOSE = 0;
22 
23  struct matrix_descr{
24  int type;
25  };
26 
27  const int SPARSE_INDEX_BASE_ZERO = 0;
28  const int SPARSE_INDEX_BASE_ONE = 1;
29 
30  void mkl_sparse_z_create_coo(sparse_matrix_t*,int,int,int,int,const int*,const int*,complex*);
31  void mkl_sparse_destroy(sparse_matrix_t&);
32  void mkl_sparse_z_mv(int,complex,sparse_matrix_t,const matrix_descr&,const complex*,complex,complex*);
33 }
34 
35 #endif
36 
38  size_t N;
39  size_t nnz;
40  Vector values;
41  std::vector<int> irn;
42  std::vector<int> jcn;
43  mkl::sparse_matrix_t pointer;
44 
46  }
47 
49 // if (pointer)
50  mkl_sparse_destroy(pointer);
51  }
52 };
53 
54 typedef std::vector<std::pair<int,complex> > Multiplier_column_data;
55 
56 typedef std::vector<Multiplier_column_data> Multiplier_data;
57 
59 public:
60  size_t nnz() const{ return 0;};
61 };
62 
64  std::unique_ptr<Multiplier_data> data;
65 
66 public:
68  std::unique_ptr<Multiplier_data>);
70 
71  void Insert(row, column, complex){
72  fail("Insert not valid in Multiplier Phase!\n");};
73  void Add(row, column, complex){
74  fail("Add not valid in Multiplier Phase!\n");};
75  complex Get(row, column) const{
76  fail("Get not valid in Multiplier Phase!\n"); return complex(0.,0.);};
77 
78  void addmyselfto(Matrix&) const{
79  fail("Matrix Add not valid in Multiplier Phase!\n");
80  };
81 
82  void Scale(complex);
83 
84  p_iterator_factory provide_iterator(){
85  return p_iterator_factory(new super_Matrix_opaque_iterator);
86  };
87  p_const_iterator_factory provide_const_iterator() const{
88  return p_const_iterator_factory(new super_Matrix_opaque_iterator);
89  };
90 
91  void Apply(const complex* phi,
92  complex* result) const;
93  void Apply( complex* result) const;
94  void Output(std::ostream& os) const;
95  void obtain_Diagonal(complex* diag);
96 
97  std::unique_ptr<super_Matrix_strategy> deep_copy(
98  STD_TR1::shared_ptr<super_Matrix> new_mat
99  ) const { fail("Multiplier Matrix cannot be cloned");
100  return std::unique_ptr<super_Matrix_strategy>(
101  new super_Matrix_SetUp(&*new_mat));
102  };
103 
104  status my_status() const{return Multiply;};
105 
106 };
107 
108 
110  std::shared_ptr<mklMultiplier_data> data;
111 public:
112  super_Matrix_mklMultiply_iterator(std::shared_ptr<mklMultiplier_data> d):
113  data(d){}
114 
115  size_t nnz() const{ return data->nnz;};
116 
117  const mklMultiplier_data& get_data(){ return *data;};
118 
119  const complex* get_raw_storage() const { return &(data->values[0]);};
120  complex* get_modifiable_raw_storage(){ return &(data->values[0]);};
121 
122  const int* get_row_data() const { return &(data->irn[0]);};
123  const int* get_col_data() const { return &(data->jcn[0]);};
124 
125  int* get_modifiable_row_data() { return &(data->irn[0]);};
126  int* get_modifiable_col_data() { return &(data->jcn[0]);};
127 
128 };
129 
131  std::shared_ptr<const mklMultiplier_data> data;
132 public:
133  super_Matrix_mklMultiply_const_iterator(std::shared_ptr<mklMultiplier_data> d):
134  data(d){}
135 
136  size_t nnz() const{ return data->nnz;};
137 
138  const mklMultiplier_data& get_data(){ return *data;};
139 
140  const complex* get_raw_storage() const { return &(data->values[0]);};
141 
142  const int* get_row_data() const { return &(data->irn[0]);};
143  const int* get_col_data() const { return &(data->jcn[0]);};
144 };
145 
147  std::shared_ptr<mklMultiplier_data> data;
148 
149  complex scalefactor;
150 
151 public:
153  std::unique_ptr<mklMultiplier_data>);
155 
156  void Insert(row, column, complex){
157  fail("Insert not valid in Multiplier Phase!\n");};
158  void Add(row, column, complex){
159  fail("Add not valid in Multiplier Phase!\n");};
160  complex Get(row, column) const{
161  fail("Get not valid in Multiplier Phase!\n"); return complex(0.,0.);};
162 
163  void addmyselfto(Matrix&) const{
164  fail("Matrix Add not valid in Multiplier Phase!\n");
165  };
166 
167  void Scale(complex);
168 
169  p_iterator_factory provide_iterator(){
170  return p_iterator_factory( new super_Matrix_mklMultiply_iterator(data));
171  };
172  p_const_iterator_factory provide_const_iterator() const {
173  return p_const_iterator_factory( new super_Matrix_mklMultiply_const_iterator(data));
174  };
175 
176  void Apply(const complex* phi,
177  complex* result) const;
178  void Apply( complex* result) const;
179  void Output(std::ostream& os) const;
180  void obtain_Diagonal(complex* diag);
181 
182  std::unique_ptr<super_Matrix_strategy> deep_copy(
183  STD_TR1::shared_ptr<super_Matrix> new_mat
184  ) const { fail("Multiplier Matrix cannot be cloned");
185  return std::unique_ptr<super_Matrix_strategy>(
186  new super_Matrix_SetUp(&*new_mat));
187  };
188 
189  status my_status() const{return Multiply;};
190 
191 };
192 
193 struct MUMPS_matrix {
194  size_t N;
195  Vector data;
196  std::vector<int> irn;
197  std::vector<int> jcn;
198 };
199 
201 private:
202  std::unique_ptr<MUMPS_matrix> mp;
203  bool distributed;
204 public:
206  bool,
207  std::unique_ptr<MUMPS_matrix>);
209 
210  bool is_distributed() const { return distributed;};
211 
212  p_iterator_factory provide_iterator(){
213  return p_iterator_factory(new super_Matrix_opaque_iterator);
214  };
215  p_const_iterator_factory provide_const_iterator() const{
216  return p_const_iterator_factory(new super_Matrix_opaque_iterator);
217  };
218 
219  void addmyselfto(Matrix&) const{
220  fail("Matrix Add not valid in Baked Phase!\n");
221  };
222 
223  void Insert(row, column, complex);
224  void Add(row, column, complex);
225  complex Get(row, column) const;
226 
227  void obtain_Diagonal(complex* diag);
228 
229  void Scale(complex);
230 
231  void Apply(const complex* phi,
232  complex* result) const;
233  void Apply( complex* result) const;
234  void Output(std::ostream& os) const;
235 
236  std::unique_ptr<super_Matrix_strategy> deep_copy(
237  STD_TR1::shared_ptr<super_Matrix> new_mat
238  ) const;
239 
240  status my_status() const{return Baked;};
241 
242  std::unique_ptr<MUMPS_matrix> release();
243 };
244 
245 struct MUMPS_pimpl;
246 
248 
249  std::unique_ptr<MUMPS_matrix> mp;
250 
251  std::unique_ptr<MUMPS_pimpl> id;
252 
253  bool distributed;
254 
255 public:
257  bool,
258  std::unique_ptr<MUMPS_matrix>);
260 
261 
262  p_iterator_factory provide_iterator(){
263  return p_iterator_factory(new super_Matrix_opaque_iterator);
264  };
265  p_const_iterator_factory provide_const_iterator() const{
266  return p_const_iterator_factory(new super_Matrix_opaque_iterator);
267  };
268 
269  void Insert(row, column, complex){
270  fail("Insert not valid in Factorized Phase!\n");};
271  void Add(row, column, complex){
272  fail("Add not valid in Factorized Phase!\n");};
273  complex Get(row, column) const{
274  fail("Get not valid in Factorized Phase!\n"); return complex(0.,0.);};
275  void Scale(complex){
276  fail("Scale not valid in Factorized Phase!\n");};
277 
278  void addmyselfto(Matrix&) const{
279  fail("Matrix Add not valid in Factorized Phase!\n");
280  };
281 
282  bool is_distributed() const { return distributed;};
283 
284  void obtain_Diagonal(complex* diag);
285 
286  void SolveDiagonal();
287 
288  void Apply(const complex* phi,
289  complex* result) const;
290  void Apply( complex* result) const;
291  void Output(std::ostream& os) const {
292  fail("Output not valid in Factorized Phase!\n");};
293 
294  status my_status() const{return Factorized_dist;};
295 
296  std::unique_ptr<super_Matrix_strategy> deep_copy(
297  STD_TR1::shared_ptr<super_Matrix> new_mat
298  ) const { fail("Factorized Matrix cannot be cloned");
299  return std::unique_ptr<super_Matrix_strategy>(
300  new super_Matrix_SetUp(&*new_mat));};
301 };
302 
303 class super_Matrix_SetUp;
305 public:
306  static std::unique_ptr<MUMPS_matrix > get_fact(MPI_Comm, const super_Matrix_SetUp&, bool);
307  static std::unique_ptr<Multiplier_data > get_mult(MPI_Comm, const super_Matrix_SetUp&);
308  static std::unique_ptr<mklMultiplier_data > get_mkl_mult(MPI_Comm, const super_Matrix_SetUp&);
309 };
310 
311 #endif
p_iterator_factory provide_iterator()
Return an iterator factory over matrix elements.
Definition: supermatrix_MUMPS.hpp:84
Definition: supermatrix_MUMPS.cpp:63
Definition: supermatrix_MUMPS.hpp:304
Definition: supermatrix.hpp:18
Definition: supermatrix_MUMPS.hpp:146
General interface to inversion of large, sparse Matrices.
Definition: supermatrix.hpp:106
Definition: minimize.hpp:10
Definition: supermatrix_MUMPS.hpp:109
Definition: supermatrix_MUMPS.hpp:247
Definition: supermatrix.hpp:209
Base Matrix class for access to 2D number grids.
Definition: matrix.hpp:82
Definition: supermatrix_MUMPS.hpp:130
p_iterator_factory provide_iterator()
Return an iterator factory over matrix elements.
Definition: supermatrix_MUMPS.hpp:262
Definition: supermatrix_MUMPS.hpp:63
p_iterator_factory provide_iterator()
Return an iterator factory over matrix elements.
Definition: supermatrix_MUMPS.hpp:169
Definition: supermatrix_MUMPS.hpp:37
Definition: supermatrix_MUMPS.hpp:200
Definition: supermatrix_MUMPS.hpp:58
Definition: supermatrix.hpp:23
p_iterator_factory provide_iterator()
Return an iterator factory over matrix elements.
Definition: supermatrix_MUMPS.hpp:212
Definition: supermatrix_MUMPS.hpp:193