monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
monolish_dense.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 #include "monolish_matrix.hpp"
10 
11 namespace monolish {
12 template <typename Float> class vector;
13 template <typename TYPE, typename Float> class view1D;
14 namespace matrix {
21 template <typename Float> class Dense {
22 private:
26  size_t rowN;
27 
31  size_t colN;
32 
36  size_t nnz;
37 
41  mutable bool gpu_status = false;
42 
43 public:
47  std::vector<Float> val;
48 
49  Dense() {}
50 
59  void convert(const COO<Float> &coo);
60 
69  void convert(const Dense<Float> &dense);
70 
79  Dense(const COO<Float> &coo) { convert(coo); }
80 
93  Dense(const Dense<Float> &dense);
94 
104  Dense(const size_t M, const size_t N);
105 
116  Dense(const size_t M, const size_t N, const Float *value);
117 
128  Dense(const size_t M, const size_t N, const std::vector<Float> &value);
129 
140  Dense(const size_t M, const size_t N, const vector<Float> &value);
141 
152  Dense(const size_t M, const size_t N,
153  const std::initializer_list<Float> &list);
154 
166  Dense(const size_t M, const size_t N, const Float min, const Float max);
167 
178  Dense(const size_t M, const size_t N, const Float value);
179 
190  void set_ptr(const size_t M, const size_t N, const std::vector<Float> &value);
191 
199  size_t get_row() const { return rowN; }
200 
208  size_t get_col() const { return colN; }
209 
217  size_t get_nnz() const { return get_row() * get_col(); }
218 
226  void set_row(const size_t N) { rowN = N; };
227 
235  void set_col(const size_t M) { colN = M; };
236 
244  void set_nnz(const size_t NZ) { nnz = NZ; };
245 
253  std::string type() const { return "Dense"; }
254 
265  Dense &transpose();
266 
275  void transpose(const Dense &B);
276 
284  double get_data_size() const { return get_nnz() * sizeof(Float) / 1.0e+9; }
285 
296  Float at(const size_t i, const size_t j) const;
297 
308  Float at(const size_t i, const size_t j) {
309  return static_cast<const Dense *>(this)->at(i, j);
310  };
311 
323  void insert(const size_t i, const size_t j, const Float Val);
324 
333  void print_all(bool force_cpu = false) const;
334 
335  // communication
336  // ///////////////////////////////////////////////////////////////////////////
344  void send() const;
345 
353  void recv();
354 
362  void nonfree_recv();
363 
371  void device_free() const;
372 
377  bool get_device_mem_stat() const { return gpu_status; }
378 
386  ~Dense() {
387  if (get_device_mem_stat()) {
388  device_free();
389  }
390  }
391 
393 
401  void diag(vector<Float> &vec) const;
402  void diag(view1D<vector<Float>, Float> &vec) const;
403  void diag(view1D<matrix::Dense<Float>, Float> &vec) const;
404 
414  void row(const size_t r, vector<Float> &vec) const;
415  void row(const size_t r, view1D<vector<Float>, Float> &vec) const;
416  void row(const size_t r, view1D<matrix::Dense<Float>, Float> &vec) const;
417 
427  void col(const size_t c, vector<Float> &vec) const;
428  void col(const size_t c, view1D<vector<Float>, Float> &vec) const;
429  void col(const size_t c, view1D<matrix::Dense<Float>, Float> &vec) const;
430 
432 
441  void fill(Float value);
442 
454  void operator=(const Dense<Float> &mat);
455 
466  bool equal(const Dense<Float> &mat,
467  bool compare_cpu_and_device = false) const;
468 
480  bool operator==(const Dense<Float> &mat) const;
481 
493  bool operator!=(const Dense<Float> &mat) const;
494 
496 
505  void diag_add(const Float alpha);
506 
515  void diag_sub(const Float alpha);
516 
525  void diag_mul(const Float alpha);
526 
535  void diag_div(const Float alpha);
536 
545  void diag_add(const vector<Float> &vec);
546  void diag_add(const view1D<vector<Float>, Float> &vec);
547  void diag_add(const view1D<matrix::Dense<Float>, Float> &vec);
548 
557  void diag_sub(const vector<Float> &vec);
558  void diag_sub(const view1D<vector<Float>, Float> &vec);
559  void diag_sub(const view1D<matrix::Dense<Float>, Float> &vec);
560 
569  void diag_mul(const vector<Float> &vec);
570  void diag_mul(const view1D<vector<Float>, Float> &vec);
571  void diag_mul(const view1D<matrix::Dense<Float>, Float> &vec);
572 
581  void diag_div(const vector<Float> &vec);
582  void diag_div(const view1D<vector<Float>, Float> &vec);
583  void diag_div(const view1D<matrix::Dense<Float>, Float> &vec);
584 };
585 } // namespace matrix
586 } // namespace monolish
monolish::matrix::Dense::Dense
Dense()
Definition: monolish_dense.hpp:49
monolish::vml::min
void min(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with smallest elements of two matrices (C[0:nnz] = min(A[0:nnz],...
Definition: matrix_vml.cpp:390
monolish::matrix::Dense::diag_div
void diag_div(const Float alpha)
Scalar and diag. vector of dense matrix div.
monolish::matrix::Dense::~Dense
~Dense()
destructor of CRS matrix, free GPU memory
Definition: monolish_dense.hpp:386
monolish::matrix::Dense::get_device_mem_stat
bool get_device_mem_stat() const
true: sended, false: not send
Definition: monolish_dense.hpp:377
monolish::vml::max
void max(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with greatest elements of two matrices (C[0:nnz] = max(A[0:nnz],...
Definition: matrix_vml.cpp:382
monolish::matrix::Dense::set_ptr
void set_ptr(const size_t M, const size_t N, const std::vector< Float > &value)
Set Dense array from std::vector.
Definition: copy_dense.cpp:32
monolish::matrix::Dense::get_row
size_t get_row() const
get # of row
Definition: monolish_dense.hpp:199
monolish::matrix::Dense::val
std::vector< Float > val
Dense format value(size M x N)
Definition: monolish_dense.hpp:47
monolish_matrix.hpp
declare matrix class
monolish::matrix::Dense
Dense format Matrix.
Definition: monolish_coo.hpp:28
monolish::matrix::Dense::transpose
Dense & transpose()
get transposed matrix (A^T)
Definition: transpose_dense.cpp:9
monolish::matrix::Dense::get_data_size
double get_data_size() const
Memory data space required by the matrix.
Definition: monolish_dense.hpp:284
monolish::matrix::Dense::nonfree_recv
void nonfree_recv()
recv. data to GPU (w/o free)
Definition: gpu_comm.cpp:222
monolish::matrix::Dense::set_col
void set_col(const size_t M)
Set column number.
Definition: monolish_dense.hpp:235
monolish::matrix::Dense::convert
void convert(const COO< Float > &coo)
Create Dense matrix from COO matrix.
monolish::matrix::Dense::col
void col(const size_t c, vector< Float > &vec) const
get column vector
monolish::matrix::Dense::diag_add
void diag_add(const Float alpha)
Scalar and diag. vector of dense matrix add.
monolish::matrix::Dense::insert
void insert(const size_t i, const size_t j, const Float Val)
get element A[i][j]
Definition: at_insert_sort_dense.cpp:25
monolish::matrix::Dense::operator==
bool operator==(const Dense< Float > &mat) const
Comparing matricies (A == mat)
Definition: compare_dense.cpp:43
monolish::matrix::Dense::diag_sub
void diag_sub(const Float alpha)
Scalar and diag. vector of dense matrix sub.
monolish::matrix::Dense::nnz
size_t nnz
# of non-zero element (M * N)
Definition: monolish_dense.hpp:36
monolish::matrix::Dense::gpu_status
bool gpu_status
true: sended, false: not send
Definition: monolish_dense.hpp:41
monolish::matrix::Dense::colN
size_t colN
# of col
Definition: monolish_dense.hpp:31
monolish::matrix::Dense::recv
void recv()
recv. data to GPU, and free data on GPU
Definition: gpu_comm.cpp:205
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::Dense::rowN
size_t rowN
# of row
Definition: monolish_dense.hpp:26
monolish::matrix::Dense::diag_mul
void diag_mul(const Float alpha)
Scalar and diag. vector of dense matrix mul.
monolish::matrix::Dense::equal
bool equal(const Dense< Float > &mat, bool compare_cpu_and_device=false) const
Comparing matricies (A == mat)
Definition: compare_dense.cpp:10
monolish::matrix::Dense::set_nnz
void set_nnz(const size_t NZ)
Set # of non-zero elements.
Definition: monolish_dense.hpp:244
monolish::matrix::Dense::type
std::string type() const
get format name "Dense"
Definition: monolish_dense.hpp:253
monolish::matrix::COO
Coodinate (COO) format Matrix (need to sort)
Definition: monolish_coo.hpp:38
monolish::matrix::Dense::device_free
void device_free() const
free data on GPU
Definition: gpu_comm.cpp:238
monolish::view1D
1D view class
Definition: monolish_coo.hpp:26
monolish::matrix::Dense::fill
void fill(Float value)
fill matrix elements with a scalar value
Definition: fill_dense.cpp:9
monolish::matrix::Dense::get_col
size_t get_col() const
get # of col
Definition: monolish_dense.hpp:208
monolish::matrix::Dense::operator=
void operator=(const Dense< Float > &mat)
matrix copy
Definition: copy_dense.cpp:10
monolish::vector
vector class
Definition: monolish_coo.hpp:25
monolish::matrix::Dense::get_nnz
size_t get_nnz() const
get # of non-zeros
Definition: monolish_dense.hpp:217
monolish::matrix::Dense::at
Float at(const size_t i, const size_t j)
get element A[i][j] (only CPU)
Definition: monolish_dense.hpp:308
monolish::matrix::Dense::at
Float at(const size_t i, const size_t j) const
get element A[i][j]
Definition: at_insert_sort_dense.cpp:9
monolish::matrix::Dense::Dense
Dense(const COO< Float > &coo)
Create dense matrix from COO matrix.
Definition: monolish_dense.hpp:79
monolish::matrix::Dense::print_all
void print_all(bool force_cpu=false) const
print all elements to standard I/O
Definition: IO_dense.cpp:17
monolish::matrix::Dense::row
void row(const size_t r, vector< Float > &vec) const
get row vector
monolish::matrix::Dense::send
void send() const
send data to GPU
Definition: gpu_comm.cpp:186
monolish::matrix::Dense::set_row
void set_row(const size_t N)
Set row number.
Definition: monolish_dense.hpp:226
monolish::matrix::Dense::diag
void diag(vector< Float > &vec) const
get diag. vector
monolish::matrix::Dense::operator!=
bool operator!=(const Dense< Float > &mat) const
Comparing matricies (A != mat)
Definition: compare_dense.cpp:55