Loading...
Searching...
No Matches
HODLRMatrix.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 */
33#ifndef STRUMPACK_HODLR_MATRIX_HPP
34#define STRUMPACK_HODLR_MATRIX_HPP
35
36#include <cassert>
37#include <functional>
38
39#include "kernel/Kernel.hpp"
41#include "HODLROptions.hpp"
42#include "sparse/CSRGraph.hpp"
44
45namespace strumpack {
46
52 namespace HODLR {
53
55 std::unique_ptr<int[]> iwork;
56 int Ninter, Nallrows, Nallcols,
57 *allrows, *allcols, *rowids, *colids, *pgids, Npmap, *pmaps;
58 std::int64_t Nalldat_loc;
59 };
60
79 template<typename scalar_t> class HODLRMatrix
80 : public structured::StructuredMatrix<scalar_t> {
86 using Vec_t = std::vector<std::size_t>;
87 using VecVec_t = std::vector<std::vector<std::size_t>>;
88 using F2Cptr = void*;
89
90 public:
91 using real_t = typename RealType<scalar_t>::value_type;
92 using mult_t = typename std::function
93 <void(Trans, const DenseM_t&, DenseM_t&)>;
94 using delem_blocks_t = typename std::function
95 <void(VecVec_t& I, VecVec_t& J, std::vector<DistMW_t>& B,
97 using elem_blocks_t = typename std::function
98 <void(VecVec_t& I, VecVec_t& J, std::vector<DenseMW_t>& B,
100
105
118 const opts_t& opts);
119
138 const std::function<scalar_t(int i, int j)>& Aelem,
139 const opts_t& opts);
140
141
163 const elem_blocks_t& Aelem, const opts_t& opts);
164
165
184 const std::function<
185 void(Trans op, const DenseM_t& R, DenseM_t& S)>& Amult,
186 const opts_t& opts);
187
201 const opts_t& opts);
202
216 template<typename integer_t>
218 const CSRGraph<integer_t>& graph, const opts_t& opts);
219
224
229 HODLRMatrix(HODLRMatrix<scalar_t>&& h) { *this = std::move(h); }
230
234 virtual ~HODLRMatrix();
235
240
246
251 std::size_t rows() const override { return rows_; }
256 std::size_t cols() const override { return cols_; }
261 std::size_t lrows() const { return lrows_; }
266 std::size_t local_rows() const override { return lrows(); }
271 std::size_t begin_row() const override { return dist_[c_->rank()]; }
276 std::size_t end_row() const override { return dist_[c_->rank()+1]; }
283 const std::vector<int>& dist() const override { return dist_; }
284
288 const MPIComm& Comm() const { return *c_; }
289
294 std::size_t memory() const override {
295 return get_stat("Mem_Fill") * 1024 * 1024;
296 }
297
298 std::size_t nonzeros() const override {
299 return memory() / sizeof(scalar_t);
300 }
301
306 std::size_t total_memory() const {
307 return c_->all_reduce(memory(), MPI_SUM);
308 }
309
316 std::size_t factor_memory() const {
317 return get_stat("Mem_Factor") * 1.e6;
318 }
319
327 std::size_t total_factor_memory() const {
328 return c_->all_reduce(factor_memory(), MPI_SUM);
329 }
330
334 std::size_t rank() const override { return get_stat("Rank_max"); }
335
341 std::size_t max_rank() const {
342 return c_->all_reduce(rank(), MPI_MAX);
343 }
344
345
354 double get_stat(const std::string& name) const;
355
356 void print_stats();
357
369 void compress(const std::function
370 <void(Trans op, const DenseM_t& R,
371 DenseM_t& S)>& Amult);
372
385 void compress(const std::function
386 <void(Trans op, const DenseM_t& R,
387 DenseM_t& S)>& Amult,
388 int rank_guess);
389
397 void compress(const delem_blocks_t& Aelem);
398
406 void compress(const elem_blocks_t& Aelem);
407
422 void mult(Trans op, const DenseM_t& X, DenseM_t& Y) const override;
423
436 void mult(Trans op, const DistM_t& X, DistM_t& Y) const override;
437
444 void factor() override;
445
458 long long int solve(const DenseM_t& B, DenseM_t& X) const;
459
472 void solve(DenseM_t& B) const override;
473
487 long long int solve(const DistM_t& B, DistM_t& X) const;
488
501 void solve(DistM_t& B) const override;
502
515 long long int inv_mult(Trans op, const DenseM_t& B, DenseM_t& X) const;
516
517 void extract_elements(const VecVec_t& I, const VecVec_t& J,
518 std::vector<DistM_t>& B);
519 void extract_elements(const VecVec_t& I, const VecVec_t& J,
520 std::vector<DenseM_t>& B);
521
534 void extract_elements(const Vec_t& I, const Vec_t& J, DenseM_t& B);
535
544 DistM_t dense(const BLACSGrid* g) const;
545
546 void set_sampling_parameter(double sample_param);
547 void set_BACA_block(int bsize);
548
549 DenseM_t redistribute_2D_to_1D(const DistM_t& R) const;
550 void redistribute_2D_to_1D(const DistM_t& R2D, DenseM_t& R1D) const;
551 void redistribute_1D_to_2D(const DenseM_t& S1D, DistM_t& S2D) const;
552
553 DenseM_t gather_from_1D(const DenseM_t& A) const;
554 DenseM_t all_gather_from_1D(const DenseM_t& A) const;
555 DenseM_t scatter_to_1D(const DenseM_t& A) const;
556
561 const std::vector<int>& perm() const { return perm_; }
566 const std::vector<int>& iperm() const { return iperm_; }
567
568 private:
569 F2Cptr ho_bf_ = nullptr; // HODLR handle returned by Fortran code
570 F2Cptr options_ = nullptr; // options structure returned by Fortran code
571 F2Cptr stats_ = nullptr; // statistics structure returned by Fortran code
572 F2Cptr msh_ = nullptr; // mesh structure returned by Fortran code
573 F2Cptr kerquant_ = nullptr; // kernel quantities structure returned by Fortran code
574 F2Cptr ptree_ = nullptr; // process tree returned by Fortran code
575 MPI_Fint Fcomm_; // the fortran MPI communicator
576 const MPIComm* c_;
577 int rows_ = 0, cols_ = 0, lrows_ = 0, lvls_ = 0;
578 std::vector<int> perm_, iperm_; // permutation used by the HODLR code
579 std::vector<int> dist_; // begin rows of each rank
580 std::vector<int> leafs_; // leaf sizes of the tree
581
582 void options_init(const opts_t& opts);
583 void perm_init();
584 void dist_init();
585
586 template<typename S> friend class ButterflyMatrix;
587 };
588
589
590 template<typename scalar_t> struct AelemCommPtrs {
591 const typename HODLRMatrix<scalar_t>::delem_blocks_t* Aelem;
592 const MPIComm* c;
593 const BLACSGrid* gl;
594 const BLACSGrid* g0;
595 };
596
597 template<typename scalar_t> void HODLR_block_evaluation
598 (int* Ninter, int* Nallrows, int* Nallcols, std::int64_t* Nalldat_loc,
599 int* allrows, int* allcols, scalar_t* alldat_loc,
600 int* rowids, int* colids, int* pgids, int* Npmap, int* pmaps,
601 void* AC);
602
603 template<typename scalar_t> void HODLR_block_evaluation_seq
604 (int* Ninter, int* Nallrows, int* Nallcols, std::int64_t* Nalldat_loc,
605 int* allrows, int* allcols, scalar_t* alldat_loc,
606 int* rowids, int* colids, int* pgids, int* Npmap, int* pmaps,
607 void* f);
608
609 } // end namespace HODLR
610} // end namespace strumpack
611
612#endif // STRUMPACK_HODLR_MATRIX_HPP
Contains the DistributedMatrix and DistributedMatrixWrapper classes, wrappers around ScaLAPACK/PBLAS ...
Contains the class holding HODLR matrix options.
Definitions of several kernel functions, and helper routines. Also provides driver routines for kerne...
Contains the structured matrix interfaces.
This is a small wrapper class around a BLACS grid and a BLACS context.
Definition BLACSGrid.hpp:66
Definition CompressedSparseMatrix.hpp:49
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
Definition DistributedMatrix.hpp:737
2D block cyclicly distributed matrix, as used by ScaLAPACK.
Definition DistributedMatrix.hpp:84
Butterfly matrix representation, this includes low-rank matrix representation as a special case.
Definition ButterflyMatrix.hpp:63
Hierarchically low-rank matrix representation.
Definition HODLRMatrix.hpp:80
long long int solve(const DistM_t &B, DistM_t &X) const
const MPIComm & Comm() const
Definition HODLRMatrix.hpp:288
void extract_elements(const Vec_t &I, const Vec_t &J, DenseM_t &B)
HODLRMatrix(const MPIComm &c, const structured::ClusterTree &tree, const opts_t &opts)
const std::vector< int > & iperm() const
Definition HODLRMatrix.hpp:566
void compress(const std::function< void(Trans op, const DenseM_t &R, DenseM_t &S)> &Amult)
DistM_t dense(const BLACSGrid *g) const
void mult(Trans op, const DistM_t &X, DistM_t &Y) const override
std::size_t total_memory() const
Definition HODLRMatrix.hpp:306
long long int inv_mult(Trans op, const DenseM_t &B, DenseM_t &X) const
void compress(const std::function< void(Trans op, const DenseM_t &R, DenseM_t &S)> &Amult, int rank_guess)
std::size_t end_row() const override
Definition HODLRMatrix.hpp:276
long long int solve(const DenseM_t &B, DenseM_t &X) const
double get_stat(const std::string &name) const
const std::vector< int > & perm() const
Definition HODLRMatrix.hpp:561
HODLRMatrix(HODLRMatrix< scalar_t > &&h)
Definition HODLRMatrix.hpp:229
std::size_t rows() const override
Definition HODLRMatrix.hpp:251
void solve(DistM_t &B) const override
HODLRMatrix()
Definition HODLRMatrix.hpp:104
HODLRMatrix(const MPIComm &c, const structured::ClusterTree &tree, const std::function< scalar_t(int i, int j)> &Aelem, const opts_t &opts)
const std::vector< int > & dist() const override
Definition HODLRMatrix.hpp:283
std::size_t begin_row() const override
Definition HODLRMatrix.hpp:271
std::size_t lrows() const
Definition HODLRMatrix.hpp:261
HODLRMatrix(const MPIComm &c, const structured::ClusterTree &tree, const CSRGraph< integer_t > &graph, const opts_t &opts)
std::size_t factor_memory() const
Definition HODLRMatrix.hpp:316
HODLRMatrix(const HODLRMatrix< scalar_t > &h)=delete
HODLRMatrix< scalar_t > & operator=(const HODLRMatrix< scalar_t > &h)=delete
HODLRMatrix(const MPIComm &c, const structured::ClusterTree &tree, const std::function< void(Trans op, const DenseM_t &R, DenseM_t &S)> &Amult, const opts_t &opts)
HODLRMatrix(const MPIComm &c, kernel::Kernel< real_t > &K, const opts_t &opts)
std::size_t cols() const override
Definition HODLRMatrix.hpp:256
std::size_t total_factor_memory() const
Definition HODLRMatrix.hpp:327
void mult(Trans op, const DenseM_t &X, DenseM_t &Y) const override
std::size_t local_rows() const override
Definition HODLRMatrix.hpp:266
HODLRMatrix< scalar_t > & operator=(HODLRMatrix< scalar_t > &&h)
HODLRMatrix(const MPIComm &c, const structured::ClusterTree &tree, const elem_blocks_t &Aelem, const opts_t &opts)
std::size_t rank() const override
Definition HODLRMatrix.hpp:334
void compress(const delem_blocks_t &Aelem)
std::size_t max_rank() const
Definition HODLRMatrix.hpp:341
void compress(const elem_blocks_t &Aelem)
std::size_t memory() const override
Definition HODLRMatrix.hpp:294
void solve(DenseM_t &B) const override
std::size_t nonzeros() const override
Definition HODLRMatrix.hpp:298
Class containing several options for the HODLR code and data-structures.
Definition HODLROptions.hpp:117
Wrapper class around an MPI_Comm object.
Definition MPIWrapper.hpp:173
T all_reduce(T t, MPI_Op op) const
Definition MPIWrapper.hpp:514
int rank() const
Definition MPIWrapper.hpp:250
Representation of a kernel matrix.
Definition Kernel.hpp:73
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
Definition StrumpackOptions.hpp:44
Trans
Definition DenseMatrix.hpp:51
Definition HODLRMatrix.hpp:590
Definition HODLRMatrix.hpp:54