mptensor v0.4.0
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches
matrix_interface.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_INTERFACE_HPP_
29#define _MATRIX_INTERFACE_HPP_
30
31#include <iostream>
32#include <vector>
33
34namespace mptensor {
35namespace matrix_interface {
36
37template <typename C>
38class Matrix {
39 public:
40 typedef C value_type;
41 typedef int comm_type;
42
43 constexpr static size_t matrix_type_tag = MATRIX_TYPE_TAG_INTERFACE;
44 constexpr static char* matrix_type_name = (char*)"Interface";
45
47 explicit Matrix(const comm_type& comm);
48 Matrix(size_t n_row, size_t n_col);
49 Matrix(const comm_type& comm, size_t n_row, size_t n_col);
50
51 void init(size_t n_row, size_t n_col);
52
53 const comm_type& get_comm() const;
54 int get_comm_size() const;
55 int get_comm_rank() const;
56
57 void print_info(std::ostream&) const;
58
59 const C& operator[](size_t i) const;
60 C& operator[](size_t i);
61 const C* head() const;
62 C* head();
63
64 size_t local_size() const;
65 void global_index(size_t i, size_t& g_row, size_t& g_col) const;
66 bool local_index(size_t g_row, size_t g_col, size_t& i) const;
67 void local_position(size_t g_row, size_t g_col, int& comm_rank,
68 size_t& lindex) const;
69
70 size_t local_row_size() const;
71 size_t local_col_size() const;
72 size_t local_row_index(size_t lindex) const;
73 size_t local_col_index(size_t lindex) const;
74 size_t global_row_index(size_t lindex_row) const;
75 size_t global_col_index(size_t lindex_col) const;
76
81
82 template <typename UnaryOperation>
84
85 std::vector<C> flatten();
86
87 void barrier() const;
89 template <typename D>
90 void bcast(D* buffer, int count, int root) const;
91
94
95 void save_index(const std::string &filename) const;
96};
97
98template <typename C>
99void replace_matrix_data(const Matrix<C>& M, const std::vector<int>& dest_rank,
100 const std::vector<size_t>& local_position,
102template <typename C>
103void replace_matrix_data(const std::vector<C>& V,
104 const std::vector<int>& dest_rank,
105 const std::vector<size_t>& local_position,
107template <typename C>
108void sum_matrix_data(const Matrix<C>& M, const std::vector<int>& dest_rank,
109 const std::vector<size_t>& local_position,
111template <typename C>
113template <typename C>
115template <typename C>
116int matrix_svd(Matrix<C>& a, Matrix<C>& u, std::vector<double>& s,
117 Matrix<C>& v);
118template <typename C>
119int matrix_svd(Matrix<C>& a, std::vector<double>& s);
120template <typename C>
122template <typename C>
123int matrix_eigh(Matrix<C>& a, std::vector<double>& s, Matrix<C>& u);
124template <typename C>
125int matrix_eigh(Matrix<C>& a, std::vector<double>& s);
126template <typename C>
127int matrix_eigh(Matrix<C>& a, Matrix<C>& b, std::vector<double>& s, Matrix<C>& u);
128template <typename C>
129int matrix_eig(Matrix<C>& a, std::vector<complex>& s, Matrix<complex>& u);
130template <typename C>
131int matrix_eig(Matrix<C>& a, std::vector<complex>& s);
132template <typename C>
134
135template <typename C>
136double max(const Matrix<C>& a);
137template <typename C>
138double min(const Matrix<C>& a);
139template <typename C>
140double max_abs(const Matrix<C>& a);
141template <typename C>
142double min_abs(const Matrix<C>& a);
143
144} // namespace matrix_interface
145} // namespace mptensor
146
148
149#endif // _MATRIX_INTERFACE_HPP_
Inteface of Matrix class.
Definition matrix_interface.hpp:38
std::vector< C > flatten()
Return the flattened vector.
size_t local_col_index(size_t lindex) const
size_t local_size() const
Return the number of elements in this process.
static constexpr size_t matrix_type_tag
Definition matrix_interface.hpp:43
Matrix()
Constructor of a size-zero matrix.
C value_type
double or complex
Definition matrix_interface.hpp:40
Matrix & map(UnaryOperation op)
Matrix(const comm_type &comm)
Constructor of a size-zero matrix.
Matrix & operator-=(const Matrix &rhs)
Matrix & operator+=(const Matrix &rhs)
C allreduce_sum(C value) const
Return the summation of a scalar. Every processes returns the same value.
void print_info(std::ostream &) const
static constexpr char * matrix_type_name
Definition matrix_interface.hpp:44
void prep_global_to_local() const
Preprocess for fast conversion from local index to global one.
size_t global_row_index(size_t lindex_row) const
const C & operator[](size_t i) const
Const array subscript operator.
int comm_type
Set MPI_Comm for MPI programm.
Definition matrix_interface.hpp:41
void local_position(size_t g_row, size_t g_col, int &comm_rank, size_t &lindex) const
bool local_index(size_t g_row, size_t g_col, size_t &i) const
size_t global_col_index(size_t lindex_col) const
void init(size_t n_row, size_t n_col)
void prep_local_to_global() const
Preprocess for fast conversion from local index to global one.
void save_index(const std::string &filename) const
C & operator[](size_t i)
Array subscript operator.
void global_index(size_t i, size_t &g_row, size_t &g_col) const
void bcast(D *buffer, int count, int root) const
Wrapper of MPI_Bcast.
int get_comm_size() const
Return the size of the MPI communicator.
const comm_type & get_comm() const
Return the MPI communicator.
int get_comm_rank() const
Return the MPI rank.
size_t local_row_index(size_t lindex) const
Matrix(size_t n_row, size_t n_col)
Constructor of a (n_row, n_col) matrix.
void barrier() const
Wrapper of MPI_Barrier.
Matrix(const comm_type &comm, size_t n_row, size_t n_col)
Constructor of a (n_row, n_col) matrix.
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_INTERFACE
Definition matrix.hpp:33
Documentation of Matrix class interface.
int matrix_eig(Matrix< C > &a, std::vector< complex > &s, Matrix< complex > &u)
double min(const Matrix< C > &a)
Return the minimum element.
int matrix_qr(Matrix< C > &a, Matrix< C > &r)
int matrix_eigh(Matrix< C > &a, std::vector< double > &s, Matrix< C > &u)
double max_abs(const Matrix< C > &a)
Return the maximum of the absolute value of elements.
C matrix_trace(const Matrix< C > &a)
double max(const Matrix< C > &a)
Return the maximum element.
double min_abs(const Matrix< C > &a)
Return the minimum of the absolute value of elements.
int matrix_solve(Matrix< C > &a, Matrix< C > &b)
Solve linear equation .
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)
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)
void matrix_product(const Matrix< C > &a, const Matrix< C > &b, Matrix< C > &c)
int matrix_svd(Matrix< C > &a, Matrix< C > &u, std::vector< double > &s, Matrix< C > &v)
Definition complex.hpp:34