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