28 #ifndef _MATRIX_LAPACK_IMPL_HPP_
29 #define _MATRIX_LAPACK_IMPL_HPP_
38 #include "../complex.hpp"
103 template <
typename C>
108 template <
typename C>
113 template <
typename C>
119 template <
typename C>
125 template <
typename C>
131 template <
typename C>
136 template <
typename C>
141 template <
typename C>
146 template <
typename C>
148 size_t& g_col)
const {
153 template <
typename C>
156 i = g_row + g_col * n_row_;
167 template <
typename C>
169 int& comm_rank,
size_t& lindex)
const {
171 lindex = g_row + g_col * n_row_;
174 template <
typename C>
179 template <
typename C>
184 template <
typename C>
186 return lindex % n_row_;
189 template <
typename C>
191 return lindex / n_row_;
194 template <
typename C>
199 template <
typename C>
204 template <
typename C>
209 V.resize(n_row * n_col);
212 template <
typename C>
214 out <<
"Matrix: local_size= " << local_size() <<
"\n";
217 template <
typename C>
220 for (
size_t i = 0; i < V.size(); ++i) V[i] += rhs[i];
224 template <
typename C>
227 for (
size_t i = 0; i < V.size(); ++i) V[i] -= rhs[i];
231 template <
typename C>
233 for (
size_t i = 0; i < V.size(); ++i) V[i] *= rhs;
237 template <
typename C>
239 for (
size_t i = 0; i < V.size(); ++i) V[i] /= rhs;
243 template <
typename C>
244 template <
typename UnaryOperation>
246 std::transform(V.begin(), V.end(), V.begin(), op);
250 template <
typename C>
253 Matrix<C> M_new(get_comm(), n_col(), n_row());
255 size_t g_col, g_row, i_new;
256 for (
size_t i = 0; i < local_size(); i++) {
257 global_index(i, g_row, g_col);
266 template <
typename C>
271 template <
typename C>
276 template <
typename C>
281 template <
typename C>
282 template <
typename D>
288 template <
typename C>
294 template <
typename C>
299 template <
typename C>
302 fout <<
"local_size= " << local_size() <<
"\n";
303 fout <<
"local_n_row= " << n_row_ <<
"\n";
304 fout <<
"local_n_col= " << n_col_ <<
"\n";
305 fout <<
"[global_row]\n";
306 for (
size_t i = 0; i < n_row_; ++i) {
308 if (i % 10 == 9) fout <<
"\n";
311 fout <<
"[global_col]\n";
312 for (
size_t i = 0; i < n_col_; ++i) {
314 if (i % 10 == 9) fout <<
"\n";
322 template <
typename C>
324 const std::vector<size_t>& local_position,
327 assert(local_position.size() == M.
local_size());
329 const C* mat = M.
head();
330 C* mat_new = M_new.
head();
333 if (dest_rank[i] == 0) {
334 mat_new[local_position[i]] = mat[i];
339 template <
typename C>
341 const std::vector<size_t>& local_position,
343 assert(dest_rank.size() == V.size());
344 assert(local_position.size() == V.size());
346 const C* mat = &(V[0]);
347 C* mat_new = M_new.
head();
349 for (
size_t i = 0; i < V.size(); i++) {
350 if (dest_rank[i] == 0) {
351 mat_new[local_position[i]] = mat[i];
356 template <
typename C>
358 const std::vector<size_t>& local_position,
361 assert(local_position.size() == M.
local_size());
363 const C* mat = M.
head();
364 C* mat_new = M_new.
head();
367 if (dest_rank[i] == 0) {
368 mat_new[local_position[i]] += mat[i];
373 template <
typename C>
379 for (
size_t i = 0; i < n; ++i) {
381 if (g_row == g_col) val += A[i];
387 template <
typename C>
391 for (
size_t i = 0; i < n; ++i) {
392 val =
std::max(val, std::abs(a[i]));
397 template <
typename C>
400 if (n == 0)
return 0.0;
401 double val = std::abs(a[0]);
402 for (
size_t i = 0; i < n; ++i) {
403 val =
std::min(val, std::abs(a[i]));
Non-distributed matrix using LAPACK.
Definition: matrix_lapack.hpp:44
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
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
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
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
Matrix & map(UnaryOperation op)
std::string filename(const std::string &prefix, int proc_size)
Definition: common.hpp:32
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
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
double min_abs(const Matrix< C > &a)
Definition: matrix_lapack_impl.hpp:398
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