Loading...
Searching...
No Matches
StructuredMatrix.hpp
Go to the documentation of this file.
1/*
2 * STRUMPACK -- STRUctured Matrices PACKage, Copyright (c) 2014, The
3 * Regents of the University of California, through Lawrence Berkeley
4 * National Laboratory (subject to receipt of any required approvals
5 * from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * If you have questions about your rights to use or distribute this
8 * software, please contact Berkeley Lab's Technology Transfer
9 * Department at TTD@lbl.gov.
10 *
11 * NOTICE. This software is owned by the U.S. Department of Energy. As
12 * such, the U.S. Government has been granted for itself and others
13 * acting on its behalf a paid-up, nonexclusive, irrevocable,
14 * worldwide license in the Software to reproduce, prepare derivative
15 * works, and perform publicly and display publicly. Beginning five
16 * (5) years after the date permission to assert copyright is obtained
17 * from the U.S. Department of Energy, and subject to any subsequent
18 * five (5) year renewals, the U.S. Government is granted for itself
19 * and others acting on its behalf a paid-up, nonexclusive,
20 * irrevocable, worldwide license in the Software to reproduce,
21 * prepare derivative works, distribute copies to the public, perform
22 * publicly and display publicly, and to permit others to do so.
23 *
24 * Developers: Pieter Ghysels, Francois-Henry Rouet, Xiaoye S. Li.
25 * (Lawrence Berkeley National Lab, Computational Research
26 * Division).
27 *
28 */
32#ifndef STRUCTURED_MATRIX_HPP
33#define STRUCTURED_MATRIX_HPP
34
35#include <vector>
36#include <cassert>
37#include <memory>
38#include <functional>
39#include <algorithm>
40
41#include "StructuredOptions.hpp"
42#include "ClusterTree.hpp"
43#include "dense/DenseMatrix.hpp"
44#if defined(STRUMPACK_USE_MPI)
46#endif
47
48namespace strumpack {
49
55 namespace structured {
56
57
66 template<typename scalar_t>
67 using extract_t = std::function
68 <scalar_t(std::size_t i, std::size_t j)>;
69
79 template<typename scalar_t>
80 using extract_block_t = std::function
81 <void(const std::vector<std::size_t>& I,
82 const std::vector<std::size_t>& J,
84
97 template<typename scalar_t>
98 using mult_t = std::function
99 <void(Trans op,
102
103#if defined(STRUMPACK_USE_MPI)
115 template<typename scalar_t>
116 using extract_dist_block_t = std::function
117 <void(const std::vector<std::size_t>& I,
118 const std::vector<std::size_t>& J,
120
133 template<typename scalar_t>
134 using mult_2d_t = std::function
135 <void(Trans op,
138
157 template<typename scalar_t>
158 using mult_1d_t = std::function
159 <void(Trans op,
162 const std::vector<int>& rdist,
163 const std::vector<int>& cdist)>;
164#endif
165
170
171
172
209 template<typename scalar_t> class StructuredMatrix {
210 using real_t = typename RealType<scalar_t>::value_type;
211
212 public:
213
217 virtual ~StructuredMatrix() = default;
218
222 virtual std::size_t rows() const = 0;
223
227 virtual std::size_t cols() const = 0;
228
236 virtual std::size_t memory() const = 0;
237
244 virtual std::size_t nonzeros() const = 0;
245
252 virtual std::size_t rank() const = 0;
253
262 virtual std::size_t local_rows() const {
263 throw std::invalid_argument
264 ("1d block row distribution not supported for this format.");
265 }
266
274 virtual std::size_t begin_row() const {
275 throw std::invalid_argument
276 ("1d block row distribution not supported for this format.");
277 }
278
286 virtual std::size_t end_row() const {
287 throw std::invalid_argument
288 ("1d block row distribution not supported for this format.");
289 }
290
299 virtual const std::vector<int>& dist() const {
300 static std::vector<int> d = {0, int(rows())};
301 return d;
302 };
310 virtual const std::vector<int>& rdist() const {
311 return dist();
312 };
320 virtual const std::vector<int>& cdist() const {
321 return dist();
322 };
323
332 virtual void mult(Trans op, const DenseMatrix<scalar_t>& x,
333 DenseMatrix<scalar_t>& y) const;
334
347 void mult(Trans op, int m, const scalar_t* x, int ldx,
348 scalar_t* y, int ldy) const;
349
350#if defined(STRUMPACK_USE_MPI)
359 virtual void mult(Trans op, const DistributedMatrix<scalar_t>& x,
361#endif
362
369 virtual void factor();
370
378 virtual void solve(DenseMatrix<scalar_t>& b) const;
379
389 virtual void solve(int nrhs, scalar_t* b, int ldb) const {
390 int lr = rows();
391 try { lr = local_rows(); }
392 catch(...) {}
393 DenseMatrixWrapper<scalar_t> B(lr, nrhs, b, ldb);
394 solve(B);
395 }
396
397#if defined(STRUMPACK_USE_MPI)
405 virtual void solve(DistributedMatrix<scalar_t>& b) const;
406#endif
407
417 virtual void shift(scalar_t s);
418
419 };
420
421
462 template<typename scalar_t>
463 std::unique_ptr<StructuredMatrix<scalar_t>>
465 const StructuredOptions<scalar_t>& opts,
466 const structured::ClusterTree* row_tree=nullptr,
467 const structured::ClusterTree* col_tree=nullptr,
468 const admissibility_t* adm=nullptr);
469
513 template<typename scalar_t>
514 std::unique_ptr<StructuredMatrix<scalar_t>>
515 construct_from_dense(int rows, int cols, const scalar_t* A, int ldA,
516 const StructuredOptions<scalar_t>& opts,
517 const structured::ClusterTree* row_tree=nullptr,
518 const structured::ClusterTree* col_tree=nullptr,
519 const admissibility_t* adm=nullptr);
520
559 template<typename scalar_t,
560 typename real_t = typename RealType<scalar_t>::value_type>
561 std::unique_ptr<StructuredMatrix<scalar_t>>
562 construct_from_elements(int rows, int cols,
563 const extract_t<scalar_t>& A,
564 const StructuredOptions<scalar_t>& opts,
565 const structured::ClusterTree* row_tree=nullptr,
566 const structured::ClusterTree* col_tree=nullptr,
567 const admissibility_t* adm=nullptr,
568 const DenseMatrix<real_t>* p=nullptr);
569
570
609 template<typename scalar_t,
610 typename real_t = typename RealType<scalar_t>::value_type>
611 std::unique_ptr<StructuredMatrix<scalar_t>>
612 construct_from_elements(int rows, int cols,
614 const StructuredOptions<scalar_t>& opts,
615 const structured::ClusterTree* row_tree=nullptr,
616 const structured::ClusterTree* col_tree=nullptr,
617 const admissibility_t* adm=nullptr,
618 const DenseMatrix<real_t>* p=nullptr);
619
654 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
656 const StructuredOptions<scalar_t>& opts,
657 const structured::ClusterTree* row_tree=nullptr,
658 const structured::ClusterTree* col_tree=nullptr,
659 const admissibility_t* adm=nullptr);
660
697 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
699 const extract_t<scalar_t>& A,
700 const StructuredOptions<scalar_t>& opts,
701 const structured::ClusterTree* row_tree=nullptr,
702 const structured::ClusterTree* col_tree=nullptr,
703 const admissibility_t* adm=nullptr);
740 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
743 const StructuredOptions<scalar_t>& opts,
744 const structured::ClusterTree* row_tree=nullptr,
745 const structured::ClusterTree* col_tree=nullptr,
746 const admissibility_t* adm=nullptr);
747
780 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
781 construct_matrix_free(int rows, int cols,
782 const mult_t<scalar_t>& Amult,
783 const StructuredOptions<scalar_t>& opts,
784 const structured::ClusterTree* row_tree=nullptr,
785 const structured::ClusterTree* col_tree=nullptr);
786
821 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
823 const mult_t<scalar_t>& Amult,
824 const extract_block_t<scalar_t>& Aelem,
825 const StructuredOptions<scalar_t>& opts,
826 const structured::ClusterTree* row_tree=nullptr,
827 const structured::ClusterTree* col_tree=nullptr);
828
863 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
865 const mult_t<scalar_t>& Amult,
866 const extract_t<scalar_t>& Aelem,
867 const StructuredOptions<scalar_t>& opts,
868 const structured::ClusterTree* row_tree=nullptr,
869 const structured::ClusterTree* col_tree=nullptr);
870
871
872#if defined(STRUMPACK_USE_MPI)
903 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
905 const StructuredOptions<scalar_t>& opts,
906 const structured::ClusterTree* row_tree=nullptr,
907 const structured::ClusterTree* col_tree=nullptr);
908
943 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
944 construct_from_elements(const MPIComm& comm, const BLACSGrid* grid,
945 int rows, int cols,
946 const extract_t<scalar_t>& A,
947 const StructuredOptions<scalar_t>& opts,
948 const structured::ClusterTree* row_tree=nullptr,
949 const structured::ClusterTree* col_tree=nullptr);
950
985 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
986 construct_from_elements(const MPIComm& comm, const BLACSGrid* grid,
987 int rows, int cols,
989 const StructuredOptions<scalar_t>& opts,
990 const structured::ClusterTree* row_tree=nullptr,
991 const structured::ClusterTree* col_tree=nullptr);
992
1023 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
1025 int rows, int cols,
1026 const mult_2d_t<scalar_t>& Amult,
1027 const StructuredOptions<scalar_t>& opts,
1028 const structured::ClusterTree* row_tree=nullptr,
1029 const structured::ClusterTree* col_tree=nullptr);
1030
1061 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
1062 construct_matrix_free(const MPIComm& comm, int rows, int cols,
1063 const mult_1d_t<scalar_t>& Amult,
1064 const StructuredOptions<scalar_t>& opts,
1065 const structured::ClusterTree* row_tree=nullptr,
1066 const structured::ClusterTree* col_tree=nullptr);
1067
1068
1105 template<typename scalar_t> std::unique_ptr<StructuredMatrix<scalar_t>>
1106 construct_partially_matrix_free(const BLACSGrid* grid, int rows, int cols,
1107 const mult_2d_t<scalar_t>& Amult,
1108 const extract_dist_block_t<scalar_t>& Aelem,
1109 const StructuredOptions<scalar_t>& opts,
1110 const structured::ClusterTree* row_tree=nullptr,
1111 const structured::ClusterTree* col_tree=nullptr);
1112
1113#endif
1114
1115 } // end namespace structured
1116} // end namespace strumpack
1117
1118#endif // STRUCTURED_MATRIX_HPP
This file contains the ClusterTree class definition.
Contains the DenseMatrix and DenseMatrixWrapper classes, simple wrappers around BLAS/LAPACK style den...
Contains the DistributedMatrix and DistributedMatrixWrapper classes, wrappers around ScaLAPACK/PBLAS ...
Contains the class definition for StructuredOptions, as well as some routines to get default options,...
This is a small wrapper class around a BLACS grid and a BLACS context.
Definition BLACSGrid.hpp:66
Like DenseMatrix, this class represents a matrix, stored in column major format, to allow direct use ...
Definition DenseMatrix.hpp:1018
This class represents a matrix, stored in column major format, to allow direct use of BLAS/LAPACK rou...
Definition DenseMatrix.hpp:139
2D block cyclicly distributed matrix, as used by ScaLAPACK.
Definition DistributedMatrix.hpp:84
Wrapper class around an MPI_Comm object.
Definition MPIWrapper.hpp:173
The cluster tree, or partition tree that represents the partitioning of the rows or columns of a hier...
Definition ClusterTree.hpp:67
Class to represent a structured matrix. This is the abstract base class for several types of structur...
Definition StructuredMatrix.hpp:209
virtual const std::vector< int > & rdist() const
Definition StructuredMatrix.hpp:310
virtual const std::vector< int > & dist() const
Definition StructuredMatrix.hpp:299
virtual const std::vector< int > & cdist() const
Definition StructuredMatrix.hpp:320
virtual void mult(Trans op, const DistributedMatrix< scalar_t > &x, DistributedMatrix< scalar_t > &y) const
virtual std::size_t begin_row() const
Definition StructuredMatrix.hpp:274
void mult(Trans op, int m, const scalar_t *x, int ldx, scalar_t *y, int ldy) const
virtual std::size_t rows() const =0
virtual std::size_t memory() const =0
virtual std::size_t cols() const =0
virtual void solve(int nrhs, scalar_t *b, int ldb) const
Definition StructuredMatrix.hpp:389
virtual std::size_t nonzeros() const =0
virtual std::size_t end_row() const
Definition StructuredMatrix.hpp:286
virtual void solve(DistributedMatrix< scalar_t > &b) const
virtual std::size_t rank() const =0
virtual void solve(DenseMatrix< scalar_t > &b) const
virtual std::size_t local_rows() const
Definition StructuredMatrix.hpp:262
virtual void mult(Trans op, const DenseMatrix< scalar_t > &x, DenseMatrix< scalar_t > &y) const
Class containing several options for the StructuredMatrix code and data-structures.
Definition StructuredOptions.hpp:106
std::function< scalar_t(std::size_t i, std::size_t j)> extract_t
Definition StructuredMatrix.hpp:68
std::unique_ptr< StructuredMatrix< scalar_t > > construct_and_factor_from_dense(const DenseMatrix< scalar_t > &A, const StructuredOptions< scalar_t > &opts, const structured::ClusterTree *row_tree=nullptr, const structured::ClusterTree *col_tree=nullptr, const admissibility_t *adm=nullptr)
std::function< void(const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseMatrix< scalar_t > &B)> extract_block_t
Definition StructuredMatrix.hpp:83
std::unique_ptr< StructuredMatrix< scalar_t > > construct_from_elements(int rows, int cols, const extract_t< scalar_t > &A, const StructuredOptions< scalar_t > &opts, const structured::ClusterTree *row_tree=nullptr, const structured::ClusterTree *col_tree=nullptr, const admissibility_t *adm=nullptr, const DenseMatrix< real_t > *p=nullptr)
std::function< void(Trans op, const DistributedMatrix< scalar_t > &R, DistributedMatrix< scalar_t > &S)> mult_2d_t
Definition StructuredMatrix.hpp:137
std::unique_ptr< StructuredMatrix< scalar_t > > construct_matrix_free(int rows, int cols, const mult_t< scalar_t > &Amult, const StructuredOptions< scalar_t > &opts, const structured::ClusterTree *row_tree=nullptr, const structured::ClusterTree *col_tree=nullptr)
std::function< void(Trans op, const DenseMatrix< scalar_t > &R, DenseMatrix< scalar_t > &S, const std::vector< int > &rdist, const std::vector< int > &cdist)> mult_1d_t
Definition StructuredMatrix.hpp:163
std::unique_ptr< StructuredMatrix< scalar_t > > construct_partially_matrix_free(int rows, int cols, const mult_t< scalar_t > &Amult, const extract_block_t< scalar_t > &Aelem, const StructuredOptions< scalar_t > &opts, const structured::ClusterTree *row_tree=nullptr, const structured::ClusterTree *col_tree=nullptr)
std::unique_ptr< StructuredMatrix< scalar_t > > construct_and_factor_from_elements(int rows, int cols, const extract_t< scalar_t > &A, const StructuredOptions< scalar_t > &opts, const structured::ClusterTree *row_tree=nullptr, const structured::ClusterTree *col_tree=nullptr, const admissibility_t *adm=nullptr)
std::function< void(const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DistributedMatrix< scalar_t > &B)> extract_dist_block_t
Definition StructuredMatrix.hpp:119
std::unique_ptr< StructuredMatrix< scalar_t > > construct_from_dense(const DenseMatrix< scalar_t > &A, const StructuredOptions< scalar_t > &opts, const structured::ClusterTree *row_tree=nullptr, const structured::ClusterTree *col_tree=nullptr, const admissibility_t *adm=nullptr)
std::function< void(Trans op, const DenseMatrix< scalar_t > &R, DenseMatrix< scalar_t > &S)> mult_t
Definition StructuredMatrix.hpp:101
Definition StrumpackOptions.hpp:44
Trans
Definition DenseMatrix.hpp:51