CEPS  24.01
Cardiac ElectroPhysiology Simulator
HoldsProcIds.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
34 
36  m_procIds({owner}), m_isShared(false)
37 {
38  for (CepsProcId pid : halosPid)
39  setAsHaloFor(pid);
40 }
41 
44 {
45  return m_isShared or m_procIds.size()>1;
46 }
47 
48 void
50 {
51  m_isShared = flag;
52  return;
53 }
54 
55 void
57 {
58  if (m_procIds.size() == 0)
59  m_procIds = {pid};
60  else
61  m_procIds.at (0) = pid;
62  return;
63 }
64 
65 const CepsProcId&
67 {
68  return m_procIds.at(0);
69 }
70 
71 void
73 {
74  CEPS_ABORT_IF(getOwner() == pid,
75  "can not set as halo for the processus \"" << pid << "\", because it is the owner"
76  );
77  ceps::insertUnique(m_procIds,pid);
78  m_isShared = true;
79  return;
80 }
81 
84 {
85  return (m_procIds[0] == pid ? false : ceps::contains(m_procIds,pid));
86 }
87 
88 void
90 {
91  m_procIds = {ceps::getRank()};
92  m_isShared = false;
93  return;
94 }
#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
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsUInt CepsProcId
For CPU indices.
Definition: CepsTypes.hpp:123
CepsBool isHaloFor(const CepsProcId &pid) const
Detect if this entity is in the halo of.
const CepsProcId & getOwner() const
Get owner (processus id) of this entity.
void setShared(CepsBool flag)
Tells if there are halo CPUs.
CepsBool isShared() const
Tells if there are halo CPUs.
void setAsHaloFor(const CepsProcId &pid)
Adds pid to the set of halo CPUs
HoldsProcIds()=default
Default constructor.
void setOwner(const CepsProcId &pid)
Set shared between several processes ?
void reset()
Gives ownership to rank(), removes halos.
CepsBool contains(const CepsVector< _Type, _Alloc > &vec, const _Type &item)
Tells if vectors contains a given item.
Definition: CepsVector.hpp:56
CepsUInt getRank()
Returns current processor rank.
void insertUnique(CepsVector< _Type, _Alloc > &vec, InputIt first, InputIt last)
Set behaviour: insert if elements does not exist in vector.
Definition: CepsVector.hpp:114