ergo
SizesAndBlocks.h
Go to the documentation of this file.
1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
36 #ifndef MAT_SIZESANDBLOCKS
37 #define MAT_SIZESANDBLOCKS
38 #include "matInclude.h"
39 namespace mat{
40 
45  class SizesAndBlocks {
46  public:
49  :nBlocks(0), nScalars(0), offset(0), nTotalScalars(0) {}
51  SizesAndBlocks(SizesAndBlocks const & other);
56  SizesAndBlocks(std::vector<int> const & blockSizesInp,
57  int const nScalarsInp)
58  : nBlocks(0),
59  nScalars(nScalarsInp), offset(0), nTotalScalars(nScalarsInp) {
60  setup(blockSizesInp);
61  }
63  SizesAndBlocks& operator=
64  (SizesAndBlocks const & other);
65 
66  bool operator==(SizesAndBlocks const & other) const;
67 
69  getSizesAndBlocksForLowerLevel(int const blockNumber) const;
70 
71  inline bool is_empty() const {return blockSizes.empty();}
72  inline int const & getNBlocks() const {return nBlocks;}
73  inline int const & getNScalars() const {return nScalars;}
74  void getBlockSizeVector(std::vector<int> & blockSizesCopy) const;
79  inline int whichBlock(int const globalIndex) const {
80  return (globalIndex - offset) / blockSizes[0]; /* Integer division */
81  }
82 
83  inline int getOffset() const {return offset;}
84  inline int getNTotalScalars() const {return nTotalScalars;}
86  protected:
87  std::vector<int> blockSizes;
95  int nBlocks;
100  int nScalars;
101  int offset;
104  SizesAndBlocks(std::vector<int> const & blockSizesInp,
105  int const nScalarsInp,
106  int const offsetInp,
107  int const nTotalScalarsInp)
108  : nBlocks(0),
109  nScalars(nScalarsInp), offset(offsetInp),
110  nTotalScalars(nTotalScalarsInp) {
111  setup(blockSizesInp);
112  }
113 
114  void setup(std::vector<int> const & blockSizesInp);
115 
116  private:
117  }; /* end of class SizesAndBlocks */
118 
119 } /* end namespace mat */
120 #endif
mat::SizesAndBlocks::is_empty
bool is_empty() const
Definition: SizesAndBlocks.h:71
mat::SizesAndBlocks::getNBlocks
int const & getNBlocks() const
Definition: SizesAndBlocks.h:72
mat::SizesAndBlocks::offset
int offset
Offset in entire system.
Definition: SizesAndBlocks.h:101
mat::SizesAndBlocks::setup
void setup(std::vector< int > const &blockSizesInp)
Definition: SizesAndBlocks.cc:92
mat::SizesAndBlocks::~SizesAndBlocks
~SizesAndBlocks()
Definition: SizesAndBlocks.h:85
mat::SizesAndBlocks::getBlockSizeVector
void getBlockSizeVector(std::vector< int > &blockSizesCopy) const
Definition: SizesAndBlocks.cc:87
mat::SizesAndBlocks::SizesAndBlocks
SizesAndBlocks()
Default constructor.
Definition: SizesAndBlocks.h:48
mat::SizesAndBlocks::getOffset
int getOffset() const
Definition: SizesAndBlocks.h:83
mat::SizesAndBlocks::blockSizes
std::vector< int > blockSizes
This is the number of scalars in each block, (not the number of blocks in each block) for each level ...
Definition: SizesAndBlocks.h:87
mat::SizesAndBlocks::nScalars
int nScalars
Number of scalars in the current block.
Definition: SizesAndBlocks.h:100
mat::SizesAndBlocks::operator==
bool operator==(SizesAndBlocks const &other) const
Definition: SizesAndBlocks.cc:56
mat
Definition: allocate.cc:39
mat::SizesAndBlocks::whichBlock
int whichBlock(int const globalIndex) const
Returns the blocknumber (between 0 and nBlocks-1) that contains elements with the given global index.
Definition: SizesAndBlocks.h:79
mat::SizesAndBlocks::getNScalars
int const & getNScalars() const
Definition: SizesAndBlocks.h:73
mat::SizesAndBlocks::getSizesAndBlocksForLowerLevel
SizesAndBlocks getSizesAndBlocksForLowerLevel(int const blockNumber) const
Definition: SizesAndBlocks.cc:71
mat::SizesAndBlocks::nTotalScalars
int nTotalScalars
Total number of scalars in entire system.
Definition: SizesAndBlocks.h:102
mat::SizesAndBlocks::SizesAndBlocks
SizesAndBlocks(std::vector< int > const &blockSizesInp, int const nScalarsInp, int const offsetInp, int const nTotalScalarsInp)
Definition: SizesAndBlocks.h:104
mat::SizesAndBlocks
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
SizesAndBlocks.h
Class used to keep track of the block sizes used at different levels in the hierarchical matrix data ...
matInclude.h
mat::SizesAndBlocks::SizesAndBlocks
SizesAndBlocks(std::vector< int > const &blockSizesInp, int const nScalarsInp)
Constructor used for explicit calls.
Definition: SizesAndBlocks.h:56
mat::SizesAndBlocks::getNTotalScalars
int getNTotalScalars() const
Definition: SizesAndBlocks.h:84
mat::SizesAndBlocks::nBlocks
int nBlocks
This is the number of blocks in the current block.
Definition: SizesAndBlocks.h:95