mptensor  v0.3.0
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches
matrix_lapack.hpp
Go to the documentation of this file.
1/*
2 mptensor - Parallel Library for Tensor Network Methods
3
4 Copyright 2016 Satoshi Morita
5
6 mptensor is free software: you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation, either version 3 of the
9 License, or (at your option) any later version.
10
11 mptensor is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with mptensor. If not, see
18 <https://www.gnu.org/licenses/>.
19*/
20
28#ifndef _MATRIX_LAPACK_HPP_
29#define _MATRIX_LAPACK_HPP_
30
31#include <iostream>
32#include <vector>
33#include <string>
34
35#include "../complex.hpp"
36
37namespace mptensor {
38namespace lapack {
39
42
43template <typename C>
44class Matrix {
45 public:
46 typedef C value_type;
47 typedef int comm_type;
48
49 constexpr static size_t matrix_type_tag = MATRIX_TYPE_TAG_LAPACK;
50 constexpr static char* matrix_type_name = (char*)"LAPACK";
51
52 Matrix();
53 explicit Matrix(const comm_type& comm_dummy);
54 Matrix(size_t n_row, size_t n_col);
55 Matrix(const comm_type& comm_dummy, size_t n_row, size_t n_col);
56
57 void init(size_t n_row, size_t n_col);
58
59 const comm_type& get_comm() const;
60 int get_comm_size() const;
61 int get_comm_rank() const;
62
63 void print_info(std::ostream&) const;
64
65 const C& operator[](size_t i) const;
66 C& operator[](size_t i);
67 const C* head() const;
68 C* head();
69
70 size_t local_size() const;
71 void global_index(size_t i, size_t& g_row, size_t& g_col) const;
72 bool local_index(size_t g_row, size_t g_col, size_t& i) const;
73 void local_position(size_t g_row, size_t g_col, int& comm_rank,
74 size_t& lindex) const;
75
76 size_t local_row_size() const;
77 size_t local_col_size() const;
78 size_t local_row_index(size_t lindex) const;
79 size_t local_col_index(size_t lindex) const;
80 size_t global_row_index(size_t lindex_row) const;
81 size_t global_col_index(size_t lindex_col) const;
82
83 Matrix& operator+=(const Matrix& rhs);
84 Matrix& operator-=(const Matrix& rhs);
87
88 template <typename UnaryOperation>
90
91 std::vector<C> flatten();
92
93 void barrier() const;
94 C allreduce_sum(C value) const;
95 template <typename D>
96 void bcast(D* buffer, int count, int root) const;
97
98 void prep_local_to_global() const;
99 void prep_global_to_local() const;
100
101 int n_row() const;
102 int n_col() const;
103
104 const Matrix transpose();
105 void save_index(const std::string &filename) const;
106
107 private:
108 std::vector<C> V;
109 int comm_;
110 int n_row_;
111 int n_col_;
112};
113
116template <typename C>
117void replace_matrix_data(const Matrix<C>& M, const std::vector<int>& dest_rank,
118 const std::vector<size_t>& local_position,
120template <typename C>
121void replace_matrix_data(const std::vector<C>& V,
122 const std::vector<int>& dest_rank,
123 const std::vector<size_t>& local_position,
125template <typename C>
126void sum_matrix_data(const Matrix<C>& M, const std::vector<int>& dest_rank,
127 const std::vector<size_t>& local_position,
129
130template <typename C>
131C matrix_trace(const Matrix<C>& a);
132
133template <typename C>
134double max_abs(const Matrix<C>& a);
135template <typename C>
136double min_abs(const Matrix<C>& a);
137
138// The following functions are defined in matrix_lapack.cc.
139template <typename C>
141
142template <typename C>
143int matrix_svd(Matrix<C>& a, Matrix<C>& u, std::vector<double>& s,
144 Matrix<C>& v);
145
146template <typename C>
147int matrix_svd(Matrix<C>& a, std::vector<double>& s);
148
149template <typename C>
151
152template <typename C>
153int matrix_eigh(Matrix<C>& a, std::vector<double>& s, Matrix<C>& u);
154
155template <typename C>
156int matrix_eigh(Matrix<C>& a, std::vector<double>& s);
157
158template <typename C>
159int matrix_eigh(Matrix<C>& a, Matrix<C>& b, std::vector<double>& s,
160 Matrix<C>& u);
161
162template <typename C>
163int matrix_eig(Matrix<C>& a, std::vector<complex>& s, Matrix<complex>& u);
164
165template <typename C>
166int matrix_eig(Matrix<C>& a, std::vector<complex>& s);
167
168template <typename C>
170
171template <typename C>
172double max(const Matrix<C>& a);
173template <typename C>
174double min(const Matrix<C>& a);
176
178
179} // namespace lapack
180} // namespace mptensor
181
182#include "matrix_lapack_impl.hpp"
183
184#endif // _MATRIX_LAPACK_HPP_
Non-distributed matrix using LAPACK.
Definition matrix_lapack.hpp:44
static constexpr char * matrix_type_name
Definition matrix_lapack.hpp:50
void print_info(std::ostream &) const
Definition matrix_lapack_impl.hpp:213
size_t global_col_index(size_t lindex_col) const
Definition matrix_lapack_impl.hpp:200
Matrix & map(UnaryOperation op)
int n_row() const
Definition matrix_lapack_impl.hpp:137
int get_comm_size() const
Always returns 1.
Definition matrix_lapack_impl.hpp:126
Matrix & operator/=(C rhs)
Definition matrix_lapack_impl.hpp:238
size_t local_row_index(size_t lindex) const
Definition matrix_lapack_impl.hpp:185
C value_type
Definition matrix_lapack.hpp:46
Matrix & operator*=(C rhs)
Definition matrix_lapack_impl.hpp:232
void save_index(const std::string &filename) const
Definition matrix_lapack_impl.hpp:300
Matrix & operator+=(const Matrix &rhs)
Definition matrix_lapack_impl.hpp:218
std::vector< C > flatten()
Definition matrix_lapack_impl.hpp:267
size_t local_size() const
Definition matrix_lapack_impl.hpp:114
int get_comm_rank() const
Always returns 0.
Definition matrix_lapack_impl.hpp:132
const comm_type & get_comm() const
Always returns 0.
Definition matrix_lapack_impl.hpp:120
const Matrix transpose()
Definition matrix_lapack_impl.hpp:251
Matrix & operator-=(const Matrix &rhs)
Definition matrix_lapack_impl.hpp:225
Matrix()
Default constructor.
Definition matrix_lapack_impl.hpp:58
void prep_local_to_global() const
Do nothing.
Definition matrix_lapack_impl.hpp:289
size_t global_row_index(size_t lindex_row) const
Definition matrix_lapack_impl.hpp:195
void global_index(size_t i, size_t &g_row, size_t &g_col) const
Definition matrix_lapack_impl.hpp:147
const C & operator[](size_t i) const
Definition matrix_lapack_impl.hpp:94
void init(size_t n_row, size_t n_col)
Definition matrix_lapack_impl.hpp:205
static constexpr size_t matrix_type_tag
Definition matrix_lapack.hpp:49
size_t local_row_size() const
Definition matrix_lapack_impl.hpp:175
size_t local_col_index(size_t lindex) const
Definition matrix_lapack_impl.hpp:190
int comm_type
Definition matrix_lapack.hpp:47
size_t local_col_size() const
Definition matrix_lapack_impl.hpp:180
void prep_global_to_local() const
Do nothing.
Definition matrix_lapack_impl.hpp:295
void local_position(size_t g_row, size_t g_col, int &comm_rank, size_t &lindex) const
Convert a global index to an index of local storage.
Definition matrix_lapack_impl.hpp:168
void bcast(D *buffer, int count, int root) const
Definition matrix_lapack_impl.hpp:283
const C * head() const
Definition matrix_lapack_impl.hpp:104
C allreduce_sum(C value) const
Definition matrix_lapack_impl.hpp:277
bool local_index(size_t g_row, size_t g_col, size_t &i) const
Definition matrix_lapack_impl.hpp:154
void barrier() const
Definition matrix_lapack_impl.hpp:272
int n_col() const
Definition matrix_lapack_impl.hpp:142
std::string filename(const std::string &prefix, int proc_size)
Definition common.hpp:32
std::complex< double > complex
Definition complex.hpp:38
constexpr size_t MATRIX_TYPE_TAG_LAPACK
Definition matrix.hpp:34
Implemation of mptensor::lapack::Matrix.
int matrix_eig(Matrix< C > &a, std::vector< complex > &s, Matrix< complex > &u)
void matrix_product(const Matrix< C > &a, const Matrix< C > &b, Matrix< C > &c)
double min(const Matrix< C > &a)
double max(const Matrix< C > &a)
C matrix_trace(const Matrix< C > &a)
Definition matrix_lapack_impl.hpp:374
int matrix_solve(Matrix< C > &a, Matrix< C > &b)
int matrix_eigh(Matrix< C > &a, std::vector< double > &s, Matrix< C > &u)
void replace_matrix_data(const Matrix< C > &M, const std::vector< int > &dest_rank, const std::vector< size_t > &local_position, Matrix< C > &M_new)
Definition matrix_lapack_impl.hpp:323
double max_abs(const Matrix< C > &a)
Definition matrix_lapack_impl.hpp:388
int matrix_svd(Matrix< C > &a, Matrix< C > &u, std::vector< double > &s, Matrix< C > &v)
double min_abs(const Matrix< C > &a)
Definition matrix_lapack_impl.hpp:398
int matrix_qr(Matrix< C > &a, Matrix< C > &r)
void sum_matrix_data(const Matrix< C > &M, const std::vector< int > &dest_rank, const std::vector< size_t > &local_position, Matrix< C > &M_new)
Definition matrix_lapack_impl.hpp:357
Definition complex.hpp:34