CEPS  24.01
Cardiac ElectroPhysiology Simulator
PETScVector.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 
32  m_unit ("None" ),
33  m_lo (0 ),
34  m_hi (0 ),
35  m_globalSize (0 ),
36  m_localSize (0 ),
37  m_localData (nullptr),
38  m_mayReadData (false ),
39  m_isAssembled (false ),
40  #ifdef PROFILING_VECTOR
41  m_totalAssembly(0),
42  m_tickAssembly (0),
43  #endif
44  m_initialized (false ),
45  m_vecCreated (false )
46 {
47 }
48 
51 {
53  *this = v;
54 }
55 
58 {
60  setSize(M,m);
61 }
62 
64  std::shared_ptr<DistributedVector> templateVector,
65  CepsBool copyValues,
66  CepsBool isSequential
67 ):
69 {
70  if (not isSequential)
71  {
73  templateVector->duplicate(*this,copyValues);
74  }
75  else
76  {
77  VecScatter context;
78  // VecScatterCreateToZero(templateVector->getVector(), &context, &m_v);
79  VecScatterCreateToAll(templateVector->getVector(),&context,&m_v);
80  VecScatterBegin (context,templateVector->getVector(),m_v,INSERT_VALUES,SCATTER_FORWARD);
81  VecScatterEnd (context,templateVector->getVector(),m_v,INSERT_VALUES,SCATTER_FORWARD);
82  VecScatterDestroy (&context);
83 
84  #ifdef PROFILING_VECTOR
85  m_totalAssembly = m_tickAssembly = 0.0;
86  #endif
87 
88  VecGetOwnershipRange(m_v,&m_lo,&m_hi);
90  m_localSize = m_hi;
91  m_initialized = true;
92  }
93 }
94 
96  DistributedVector& templateVector,
97  CepsBool copyValues,
98  CepsBool isSequential
99 ):
101 {
102  if (not isSequential)
103  {
105  templateVector.duplicate(*this,copyValues);
106  }
107  else
108  {
109  VecScatter context;
110  // VecScatterCreateToZero(templateVector->getVector(), &context, &m_v);
111  VecScatterCreateToAll(templateVector.getVector(),&context,&m_v);
112  VecScatterBegin (context,templateVector.getVector(),m_v,INSERT_VALUES,SCATTER_FORWARD);
113  VecScatterEnd (context,templateVector.getVector(),m_v,INSERT_VALUES,SCATTER_FORWARD);
114  VecScatterDestroy (&context);
115 
116  #ifdef PROFILING_VECTOR
117  m_totalAssembly = m_tickAssembly = 0.0;
118  #endif
119 
120  VecGetOwnershipRange(m_v,&m_lo,&m_hi);
121  m_globalSize = m_hi;
122  m_localSize = m_hi;
123  m_initialized = true;
124  }
125 }
126 
129 {
131  CepsInt M,N;
132  CepsGlobalIndex lo,hi;
133  mat->getLocalRange(&lo,&hi);
134  mat->getSize(&M,&N);
135  setSize(M,hi-lo);
136  CepsBool isOwner = lo <= row and row < hi;
137 
138  CepsInt nbEntries;
139  const CepsInt *columnIndices;
140  const PetscScalar *values;
141 
142  // as we are in constructor, we are sure that data will be exchanged
143  if (isOwner)
144  {
145  MatGetRow(mat->getMatrix(),row,&nbEntries,&columnIndices,&values);
146  VecSetValues(m_v,nbEntries,columnIndices,values,INSERT_VALUES);
147  }
148 
149  // assemble
150  finalize();
151 
152  if(isOwner)
153  MatRestoreRow(mat->getMatrix(),row,&nbEntries,&columnIndices,&values);
154 
155 }
156 
166 {
167  #ifdef PROFILING_VECTOR
168  if (ceps::isMaster())
169  std::cout << "/* PROFILING: Distributed vector - time spent assembling = " << m_totalAssembly
170  << " seconds. *\\" << std::endl;
171  #endif
172  if (m_vecCreated)
173  VecDestroy(&(this->m_v));
174 }
175 
176 const PetscVector&
178 {
179  return m_v;
180 }
181 
184 {
185  CEPS_ABORT_IF(not m_mayReadData, "call getLocalData() before accessing local data.\n");
186  return m_localData;
187 }
188 
189 void
191 {
192  CEPS_ABORT_IF(M < 0 or m < 0, "(M = " << M << ", n = " << m << "): cannot set negative size!");
193  VecSetSizes(m_v,m,M);
194  m_globalSize = M;
195  m_localSize = m;
196  VecGetOwnershipRange(m_v,&m_lo,&m_hi);
197  m_initialized = true;
198 }
199 
200 void
202 {
203  CepsInt s;
204  VecGetSize(m_v, &s);
205  *globalSize = s;
206  return;
207 }
208 
209 CepsInt
211 {
212  CepsInt s;
213  VecGetSize(m_v, &s);
214  return s;
215 }
216 
217 void
219 {
220  CepsInt s;
221  VecGetLocalSize(m_v, &s);
222  *localSize = s;
223  return;
224 }
225 
226 CepsInt
228 {
229  CepsInt s;
230  VecGetLocalSize(m_v,&s);
231  return s;
232 }
233 
234 void
236 {
237  *lo = m_lo;
238  *hi = m_hi;
239  return;
240 }
241 
242 void
244 {
245  VecGetArray(m_v,&m_localData);
246  m_mayReadData = true;
247  return;
248 }
249 
250 void
252 {
253  m_mayReadData = false;
254  VecRestoreArray(m_v,&m_localData);
255  return;
256 }
257 
258 void
260 {
261  VecSetValue(m_v,row,value,INSERT_VALUES);
262  return;
263 }
264 
265 void
267 {
268  VecSetValue(m_v,row,value,ADD_VALUES);
269  return;
270 }
271 
272 void
274 {
275  PetscBool value = flag ? PETSC_TRUE : PETSC_FALSE;
276  VecSetOption(m_v,VEC_IGNORE_OFF_PROC_ENTRIES,value);
277  return;
278 }
279 
280 void
282  const CepsMathScalar *values,
283  CepsInt n,
284  const CepsGlobalIndex *indices
285 )
286 {
287  VecSetValues(m_v,n,indices,values,INSERT_VALUES);
288  return;
289 }
290 
291 void
293  DistributedVector &values,
294  CepsInt n,
295  const CepsGlobalIndex *indices
296 )
297 {
298  // request local access on both vectors
299  getLocalData();
300  values.getLocalData();
301 
302  if (ceps::isValidPtr(indices))
303  for (CepsInt i=0; i<n; i++)
304  m_localData[indices[i]-m_lo] = values[indices[i]];
305  else
306  // contiguous, starting from first owned row
307  for (CepsInt i=0; i<n; i++)
308  m_localData[i] = values.m_localData[i];
309 
310  // done with local data
312  values.releaseLocalData();
313  return;
314 }
315 
316 void
318  const CepsMathScalar *values,
319  CepsInt n,
320  const CepsGlobalIndex *indices
321 )
322 {
323  // request access to local data
324  getLocalData();
325 
326  if (ceps::isValidPtr(indices))
327  for (CepsInt i=0; i<n; i++)
328  m_localData[indices[i]-m_lo] = values[i];
329  else
330  // contiguous, starting from first owned row
331  for (CepsInt i=0; i<n; i++)
332  m_localData[i] = values[i];
333  // done with local data
335  return;
336 }
337 
338 void
340  const CepsVector<CepsMathScalar> &values,
341  const CepsVector<CepsInt> &indices
342 )
343 {
344  CepsUInt N = values.size();
345  CEPS_ABORT_IF(indices.size() != N,
346  "Given arrays of values and row indices have different size."
347  );
348  getLocalData();
349  for (CepsUInt i=0U; i<N; i++)
350  m_localData[indices[i]-m_lo] = values[i];
352  return;
353 }
354 
355 void
357  const CepsMathScalar *values,
358  CepsInt n,
359  const CepsGlobalIndex *indices
360 )
361 {
362  VecSetValues(m_v,n,indices,values,ADD_VALUES);
363  return;
364 }
365 
366 void
368  DistributedVector &values,
369  CepsInt n,
370  const CepsGlobalIndex *indices
371 )
372 {
373  // request local access on both vectors
374  getLocalData();
375  values.getLocalData();
376 
377  if (ceps::isValidPtr(indices))
378  for (CepsInt i=0; i<n; i++)
379  m_localData[indices[i]-m_lo] += values[indices[i]];
380  else
381  {
382  // contiguous, starting from first owned row
383  for (CepsInt i=0; i<n; i++) {
384  m_localData[i] += values.m_localData[i];
385  }
386  }
387 
388  // done with local data
390  values.releaseLocalData();
391  return;
392 }
393 
394 void
396  const CepsMathScalar *values,
397  CepsInt n,
398  const CepsGlobalIndex *indices
399 )
400 {
401  // request access to local data
402  getLocalData();
403  CepsInt i;
404 
405  if (ceps::isValidPtr(indices))
406  for (i=0; i<n; i++)
407  m_localData[indices[i]-m_lo] += values[i];
408  else
409  // contiguous, starting from first owned row
410  for (i=0; i<n; i++)
411  m_localData[i] += values[i];
412  // done with local data
414  return;
415 }
416 
417 void
419 {
421  "invalid access to local data.\nMake sure you called "
422  "getLocalData() beforehand."
423  );
424 
425  // standard non-ghost version
426  for (CepsInt i=0; i<n; i++)
427  values[i] = m_localData[indices[i]-m_lo];
428  return;
429 }
430 
433 {
435  getLocalData();
436  // extract from local data
437  for (CepsInt row : indices)
438  {
439  CEPS_ABORT_IF(row<m_lo or row>=m_hi,
440  "trying to access row " << row << "which is out of local range ("
441  << m_lo << "," << m_hi << ")"
442  );
443  res.push_back(m_localData[row-m_lo]);
444  }
445 
446  // release array
448  return res;
449 }
450 
451 void
453 {
454  VecZeroEntries(m_v);
455  return;
456 }
457 
458 void
460 {
461  VecSet(m_v,value);
462  return;
463 }
464 
465 void
467 {
468  if (not v.m_vecCreated)
469  v.createEmptyVector();
470 
471  if (copyValues)
472  {
474  VecCopy(m_v,v.m_v);
475  }
476  else
477  {
478  VecDuplicate(m_v,&v.m_v);
480  }
481  return;
482 }
483 
484 void
486 {
487 #ifdef PROFILING_VECTOR
488  m_tickAssembly = ceps::tick();
489 #endif
490  m_isAssembled = false;
491  VecAssemblyBegin(m_v);
492  return;
493 }
494 
495 void
497 {
498  VecAssemblyEnd(m_v);
499  m_isAssembled = true;
500 #ifdef PROFILING_VECTOR
501  m_totalAssembly += ceps::tock(m_tickAssembly);
502 #endif
503  return;
504 }
505 
506 void
508 {
509 #ifdef PROFILING_VECTOR
510  m_tickAssembly = ceps::tick();
511 #endif
512  beginAssembly();
513  endAssembly();
514 #ifdef PROFILING_VECTOR
515  m_totalAssembly += ceps::tock(m_tickAssembly);
516 #endif
517  return;
518 }
519 
520 CepsBool
522 {
523  return (m_globalSize == vec.m_globalSize);
524 }
525 
526 CepsBool
528 {
529  if (! this->sameSize(vec))
530  return false;
531 
532  return ((m_lo == vec.m_lo) and (m_hi == vec.m_hi));
533 }
534 
535 CepsBool
537 {
538  CepsInt lo, hi;
539  vec.getLocalRange(&lo, &hi);
540 
541  // check size
542  CEPS_ABORT_IF(not sameSize(vec),
543  "DistributedVector::equals: trying to compare vectors of sizes "
544  << m_globalSize << " and " << vec.m_globalSize
545  );
546  // check ownership range
547  CEPS_ABORT_IF(not sameLocalRange(vec),
548  "DistributedVector:equals: trying to compare two vectors with different data repartition."
549  );
550 
551  // check the values
552  const_cast<DistributedVector *> (this)->getLocalData();
553  const_cast<DistributedVector &> (vec) . getLocalData();
554 
555  CepsUInt myflag = 1U, flag = 0U;
556  for (CepsInt i=0; i<(hi-lo); i++)
557  {
558  if (! ceps::equals(vec.m_localData[i], m_localData[i], errorFactor))
559  {
560  myflag = 0U;
561  break;
562  }
563  }
564 
565  // Share results
566  MPI_Allreduce(&myflag,&flag,1,CEPS_MPI_UINT,MPI_MIN,ceps::getCommunicator());
567 
568  const_cast<DistributedVector *> (this)->releaseLocalData();
569  const_cast<DistributedVector &> (vec) .releaseLocalData();
570 
571  return (CepsBool) flag;
572 }
573 
574 CepsBool
576 {
577  CepsInt lo, hi;
578  vec.getLocalRange (&lo, &hi);
579 
580  // check size
581  CEPS_ABORT_IF(not sameSize(vec),
582  "trying to compare vectors of sizes " << m_globalSize << " and " << vec.m_globalSize
583  );
584  // check ownership range
585  CEPS_ABORT_IF(not sameLocalRange(vec),
586  "trying to compare two vectors with different data repartition."
587  );
588 
589  // check the values
590  const_cast<DistributedVector *> (this)->getLocalData();
591  const_cast<DistributedVector &> (vec) .getLocalData();
592 
593  CepsUInt myflag = 1U, flag = 0U;
594  for (CepsInt i=0; i<(hi-lo); i++)
595  {
596  if (not ceps::approxEquals(vec.m_localData[i],m_localData[i],epsilon))
597  {
598  myflag = false;
599  // break;
600  }
601  }
602  // Share results
603  MPI_Allreduce(&myflag, &flag, 1, CEPS_MPI_UINT, MPI_MIN, ceps::getCommunicator());
604 
605  const_cast<DistributedVector *> (this)->releaseLocalData();
606  const_cast<DistributedVector &> (vec) .releaseLocalData();
607 
608  return (CepsBool) flag;
609 }
610 
611 void
613 {
614  this->addScaled(x,1.0);
615  return;
616 }
617 
618 void
620 {
622  "cannot compute x = x + a.x when using PETSc."
623  );
624 
625  // check sizes and allocate if not initialized
627  "added vector is not properly initialized."
628  );
630  VecAXPY(m_v,alpha,x.getVector());
631  return;
632 }
633 
634 void
636 {
637  VecScale(m_v,alpha);
638 }
639 
640 void
642 {
644  "Trying to multiply vectors with different local ranges"
645  );
646  const CepsMathScalar *src;
647 
648  getLocalData();
649  VecGetArrayRead(v.m_v,&src);
650  if(divide)
651  {
652  for (CepsInt i=0; i<m_hi-m_lo; ++i)
653  m_localData[i] /= src[i];
654  }
655  else
656  {
657  for (CepsInt i=0; i<m_hi-m_lo; ++i)
658  m_localData[i] *= src[i];
659  }
660  VecRestoreArrayRead(v.m_v,&src);
662 
663  return;
664 }
665 
666 void
668 {
669  CEPS_ABORT_IF (ceps::isSamePtr(this, &x),
670  "cannot compute x = A.x when using PETSc."
671  );
672 
673  // check sizes and allocate if not initialized
675  "x vector is not properly initialized."
676  );
678 
679  CepsInt matrixMSize, matrixNSize;
680  A.getSize(&matrixMSize, &matrixNSize);
681  CEPS_ABORT_IF(x.m_globalSize != matrixMSize,
682  "cannot compute A.x as A has size (" << matrixMSize << "," << matrixNSize
683  << ") and vector has size " << x.m_globalSize
684  );
685 
686  // this is not necessary, but keep it here for performance issues
687  CepsGlobalIndex matrixLo, matrixHi;
688  A.getLocalRange(&matrixLo, &matrixHi);
689  CEPS_ABORT_IF((m_lo != matrixLo) or (m_hi != matrixHi),
690  "vector and matrix have different local ranges ("
691  << m_lo << "," << m_hi << ") and (" << matrixLo
692  << "," << matrixHi << ") respectively."
693  );
694 
695  MatMult(const_cast<PetscMatrix>(A.getMatrix()),x.m_v,m_v);
696  m_isAssembled = true;
697  return;
698 }
699 
700 void
702 {
703  VecAbs(m_v);
704  return;
705 }
706 
709 {
710  CepsMathScalar dot_val;
711  VecDot (m_v,x.getVector(), &dot_val);
712  return dot_val;
713 }
714 
717 {
718  CepsMathScalar norm;
719  VecNorm(m_v,NORM_INFINITY,&norm);
720  return norm;
721 }
722 
725 {
726  CepsMathScalar norm;
727  VecNorm (m_v,NORM_1,&norm);
728  return norm;
729 }
730 
733 {
734  CepsMathScalar norm;
735  VecNorm (m_v,NORM_2,&norm);
736  return norm;
737 }
738 
739 void
741 {
742  VecView(m_v,PETSC_VIEWER_STDOUT_WORLD);
743  return;
744 }
745 
746 // Operators
747 
750 {
752  "Trying to add vectors with different local ranges"
753  );
754  const CepsMathScalar *src;
755 
756  getLocalData ();
757  VecGetArrayRead (v.m_v,&src);
758  for (CepsInt i=0; i< m_hi-m_lo; ++i)
759  m_localData[i] += src[i];
760  VecRestoreArrayRead(v.m_v,&src);
762 
763  return *this;
764 }
765 
768 {
769  VecShift(m_v,scalar);
770  return *this;
771 }
772 
775 {
777  "Trying to add vectors with different local ranges"
778  );
779  const CepsMathScalar *src;
780 
781  getLocalData();
782  VecGetArrayRead(v.m_v,&src);
783  for (CepsInt i=0; i<m_hi-m_lo; ++i)
784  m_localData[i] -= src[i];
785 
786  VecRestoreArrayRead(v.m_v,&src);
788 
789  return *this;
790 }
791 
794 {
795  return this->operator+=(-scalar);
796 }
797 
800 {
801  VecScale(m_v,scalar);
802  return *this;
803 }
804 
805 // ---------------------------------------------------------------------------------------------------------==
806 // Private, protected
807 // ---------------------------------------------------------------------------------------------------------==
808 
809 void
811 {
812  if (m_initialized)
813  {
814  CEPS_ABORT_IF (gSize != m_globalSize or lSize != m_localSize,
815  "DistributedVector::checkAndSetSizes(): calling vector is not of proper sizes."
816  );
817  }
818  else
819  {
821  setSize(gSize,lSize);
822  }
823  return;
824 }
825 
826 void
828 {
829  if (not m_vecCreated)
830  {
831  VecCreate(ceps::getCommunicator(),&(this->m_v));
832  VecSetType(m_v,VECSTANDARD);
833  m_vecCreated = true;
834  }
835  return;
836 }
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
CepsScalar CepsMathScalar
Real numbers.
Definition: CepsTypes.hpp:133
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
Definition: CepsTypes.hpp:218
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
#define CEPS_MPI_UINT
Definition: CepsTypes.hpp:325
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
Sparse matrix distributed between process.
const PetscMatrix & getMatrix() const
The underlying matrix.
void getLocalRange(CepsGlobalIndex *lo, CepsGlobalIndex *hi) const
Get the range of rows owned by current process.
void getSize(CepsInt *M, CepsInt *N) const
Get the global size of the matrix.
Structure to hold spatially dependant data and distribute it between process.
CepsMathScalar * m_localData
DistributedVector()
Default Constructor.
Definition: PETScVector.cpp:31
void setValuesLocal(DistributedVector &values, CepsInt n, const CepsGlobalIndex *indices=nullptr)
Sets n multiple local values.
virtual ~DistributedVector()
Destructor.
CepsBool equals(const DistributedVector &vec, CepsMathScalar errorFactor=1.0) const
Whether two vector have the (exact!) same values on all process.
void finalize()
Calls both beginAssembly() and endAssembly()
void view() const
Display vector on standard output.
virtual void getLocalData()
Enables direct access to the stored local values.
CepsBool m_initialized
Whether this vector is ready to be used or not.
CepsBool m_isAssembled
Whether this vector is assembled or not.
virtual void getValues(CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices)
Read values in the vector.
PetscVector m_v
The underlying vector.
CepsGlobalIndex m_lo
Index of first owned row.
CepsBool sameLocalRange(const DistributedVector &vec) const
Compares local ranges.
CepsBool approxEquals(const DistributedVector &vec, CepsMathScalar epsilon) const
Whether two vector have the approximately the same values on all process, with epsilon tolerance.
DistributedVector & operator*=(const CepsMathScalar &scalar)
Short mult by scalar.
CepsMathScalar l1Norm() const
-norm of vector
void setValue(CepsMathScalar value, CepsGlobalIndex i)
Sets or replaces a single value.
void createEmptyVector()
Inits the underlying vector. Use setSize afterwards.
void zero()
Fills vector with zeros.
void add(const DistributedVector &x)
Adds x to current vector.
CepsMathScalar l2Norm() const
-norm of vector
void endAssembly()
Wait for the distributed vector assembly to finish.
DistributedVector & operator+=(const DistributedVector &v)
Short addition with other vector.
DistributedVector & operator-=(const DistributedVector &v)
Short substraction with other vector.
CepsMathScalar lInfNorm() const
-norm of vector
void addValues(const CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices)
Add multiple values to already existing values.
const PetscVector & getVector() const
The underlying vector.
CepsMathScalar dot(DistributedVector &x)
Computes the inner product of current vector by x.
CepsMathScalar * localData()
Point on the local data.
void addValuesLocal(DistributedVector &values, CepsInt n, const CepsGlobalIndex *indices=nullptr)
Add multiple local values to already existing values.
void duplicate(DistributedVector &dest, CepsBool copyValues) const
Shares the non-zero structure, and optionally values.
CepsGlobalIndex m_hi
Index of row right after last owned row.
void ignoreOffProcEntries(CepsBool ignore)
Sets whether the values on rows that are not owned by current process will be ignored or not.
CepsInt getSize() const
Get the global size of the vector.
virtual void releaseLocalData()
Release the pointer on the local data.
void checkAndSetSizes(CepsInt gSize, CepsInt lSize)
Check if calling vector has had its sizes set. If not, set sizes.
CepsVector< CepsMathScalar > getSubVector(const CepsVector< CepsGlobalIndex > &rowIndices)
Get some local data from the distributed vector.
CepsBool m_vecCreated
Underlying vec created.
CepsInt m_globalSize
Global size of vector.
void getLocalRange(CepsGlobalIndex *lo, CepsGlobalIndex *hi) const
Get the range of rows owned by current process.
void fill(CepsMathScalar value)
Fills vector with given value.
virtual void pointWiseScale(const DistributedVector &x, CepsBool divide=false)
Perform a point wise multiplication or division on this vector by another vector.
void setSize(CepsInt M, CepsInt m)
Set distributed vector size.
virtual void abs()
Every component of the vector is replaced by its absolute value.
virtual void mult(const DistributedMatrix &A, const DistributedVector &x)
Sets current vector to result of product A*x.
virtual void scale(CepsMathScalar alpha)
Multiplies self by alpha.
CepsInt m_localSize
Local size of vector.
void beginAssembly()
Start distributed vector assembly.
CepsInt getLocalSize() const
Get the local size of the vector.
void addValue(CepsMathScalar value, CepsGlobalIndex i)
Adds given scalar to the currently existing value or set it if not.
CepsBool sameSize(const DistributedVector &vec) const
Compares global sizes.
void setValues(const CepsMathScalar *values, CepsInt n, const CepsGlobalIndex *indices)
Sets n multiple values.
void addScaled(const DistributedVector &x, CepsMathScalar alpha)
Adds alpha*x to current vector.
MPI_Comm getCommunicator()
Get the communicator.
CepsBool approxEquals(CepsReal a, CepsReal b, CepsReal epsilon)
Approximate equality with epsilon tolerance.
Definition: Precision.hpp:67
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
CepsBool isMaster()
Is calling process the master ?
CepsBool equals(CepsReal a, CepsReal b, CepsReal error=1.0)
CepsReal equality up to machine precision.
Definition: Precision.hpp:54
CepsBool isSamePtr(_Type *xptr, U *yptr)
Tells if two pointers designate the same address.
Definition: CepsMemory.hpp:78