CEPS  24.01
Cardiac ElectroPhysiology Simulator
DistributedFactory.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 
33 
35 {
36  initialize ();
37 }
38 
40  CepsUInt globalRows, CepsUInt globalCols,
41  CepsUInt localRows, CepsUInt localCols,
42  const CepsVector<CepsInt>& diagBlockNnz,
43  const CepsVector<CepsInt>& offdiagBlockNnz
44 )
45 {
46  initialize();
47 
48  setGlobalSizes(globalRows,globalCols);
49  setLocalSizes ( localRows, localCols);
50 
51  CepsUInt dLength = diagBlockNnz .size();
52  CepsUInt oLength = offdiagBlockNnz.size();
53  CEPS_ABORT_IF(dLength!=oLength or dLength==0,
54  "provided non zero structure is ill-formed"
55  );
56 
57  setNonZeroTemplate(diagBlockNnz.data(), offdiagBlockNnz.data(),dLength);
58 }
59 
61  CepsUInt localRows, CepsUInt localCols,
62  CepsUInt diagBlockNz,
63  CepsUInt offdiagBlockNz)
64 {
65  initialize();
66 
67  setGlobalSizes(globalRows,globalCols);
68  setLocalSizes ( localRows, localCols);
69 
70  setNonZeroTemplate(diagBlockNz,offdiagBlockNz);
71 }
72 
74 {
79 }
80 
81 void
83 {
84  m_globalRows = globalRows;
85  m_globalCols = globalCols;
86  return;
87 }
88 
89 void
91 {
92  m_localRows = localRows;
93  m_localCols = localCols;
94  return;
95 }
96 
97 void
99  CepsIndex *haloRows,
100  CepsUInt nHaloRows,
101  CepsIndex *haloCols,
102  CepsUInt nHaloCols
103 )
104 {
106  m_nHaloRows = nHaloRows;
108  memcpy (m_haloRows, haloRows, m_nHaloRows * sizeof (CepsIndex));
109 
111  m_nHaloCols = nHaloCols;
113  memcpy (m_haloCols, haloCols, m_nHaloCols * sizeof (CepsIndex));
114 
115  return;
116 }
117 
118 void
120  const CepsIndex *d_nnz,
121  const CepsIndex *o_nnz,
122  CepsInt nbLocalRows
123 )
124 {
125  CEPS_ABORT_IF (nbLocalRows != m_localRows,
126  "when setting non zero template, provided number of local rows (" << nbLocalRows <<
127  ")\ndoes not match number of rows of the factory (" << m_localRows << ")"
128  );
129 
132 
133  m_d_nnz = ceps::newCopyArray (const_cast<CepsIndex *> (d_nnz), nbLocalRows);
134  m_o_nnz = ceps::newCopyArray (const_cast<CepsIndex *> (o_nnz), nbLocalRows);
135 
136  return;
137 }
138 
139 void
141 {
142  m_d_nz = d_nz;
143  m_o_nz = o_nz;
144  return;
145 }
146 
147 DVecPtr
149 {
150  return DVecPtr (ceps::getNew<DistributedVector>(m_globalRows, m_localRows));
151 }
152 
153 DHVecPtr
155 {
156  return DHVecPtr (ceps::getNew<DistributedHaloVector>(m_globalRows, m_localRows, m_nHaloRows, m_haloRows));
157 }
158 
159 DMatPtr
161 {
162  DistributedMatrix *mat = ceps::getNew<DistributedMatrix>(
164  );
165 
168  else
170  return DMatPtr (mat);
171 }
172 
173 void
175 {
176  m_globalRows = 0;
177  m_globalCols = 0;
178 
179  m_localRows = 0;
180  m_localCols = 0;
181 
182  m_haloRows = nullptr;
183  m_nHaloRows = 0;
184  m_haloCols = nullptr;
185  m_nHaloCols = 0;
186 
187  m_d_nnz = nullptr;
188  m_o_nnz = nullptr;
189  m_d_nz = 0;
190  m_o_nz = 0;
191  return;
192 }
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
CepsInt CepsIndex
Index rowid etc.
Definition: CepsTypes.hpp:111
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
std::shared_ptr< DistributedVector > DVecPtr
Short typedef for pointer on distributed vector.
void setHaloIndices(CepsIndex *haloRows, CepsUInt nHaloRows, CepsIndex *haloCols, CepsUInt nHaloCols)
Local halo rows and columns.
CepsIndex m_nHaloCols
local number of halo cols
~DistributedFactory()
Destructor.
CepsIndex * m_haloRows
global indices of halo rows on this proc
void setGlobalSizes(CepsUInt globalRows, CepsUInt globalCols)
Total number of rows and columns.
CepsInt m_o_nz
number of non-zero values on each local row on off-diagonal
CepsInt m_d_nz
number of non-zero values on each local row on diagonal
CepsIndex m_globalRows
global number of rows
DVecPtr getDistributedVector() const
Pointer to created distributed vector.
CepsIndex m_globalCols
global number of columns
DHVecPtr getDistributedHaloVector() const
Pointer on a created distributed vector that has additional memory allocated to enable the exchange o...
void setLocalSizes(CepsUInt localRows, CepsUInt localCols)
Local number of rows and columns.
DMatPtr getDistributedMatrix() const
Pointer to created distributed matrix.
CepsInt * m_o_nnz
number of non-zero values specified for each local row on off-diagonal
CepsInt * m_d_nnz
number of non-zero values specified for each local row on diagonal
void initialize()
Sets some variables.
CepsIndex * m_haloCols
global indices of halo cols on this proc
DistributedFactory()
Default constructor.
CepsIndex m_localRows
local number of rows
CepsIndex m_localCols
local number of columns
void setNonZeroTemplate(const CepsIndex *d_nnz, const CepsIndex *o_nnz, CepsInt nbLocalRows)
Set the non-zero structure of the matrices to create.
CepsIndex m_nHaloRows
local number of halo rows
Sparse matrix distributed between process.
void setNonZeroStructure(const CepsInt d_nnz[], const CepsInt o_nnz[])
Set the matrix non-zero structure.
void destroyTabular(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:149
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
_Type * newCopyArray(_Type *src, long unsigned int n)
Generates a C-style copy of a C-style array.
Definition: CepsMemory.hpp:197