Version: 9.15.0
ForkBlocPoint.cxx
Go to the documentation of this file.
1 // Copyright (C) 2015-2025 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "ForkBlocPoint.hxx"
21 #include "PointVisitor.hxx"
22 #include "Exception.hxx"
23 
24 #include <algorithm>
25 
26 using namespace YACS::ENGINE;
27 
28 ForkBlocPoint::ForkBlocPoint(const std::list<AbstractPoint *>& nodes, AbstractPoint *father):BlocPoint(nodes,father)
29 {
30 }
31 
33 {
34  ForkBlocPoint *ret(new ForkBlocPoint);
35  ret->deepCopyFrom(*this);
36  ret->setFather(father);
37  return ret;
38 }
39 
41 {
42 }
43 
45 {
46  if(_nodes.empty())
47  throw Exception("ForkBlocPoint::getFirstNode : error no branches !");
48  return _nodes.front()->getFirstNode();
49 }
50 
52 {
53  if(_nodes.empty())
54  throw Exception("ForkBlocPoint::getLastNode : error no branches !");
55  return _nodes.front()->getLastNode();//not a bug - seen from the outside only first branch exists !
56 }
57 
59 {
60  int ret(0);
61  for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
62  ret+=(*it)->getMaxLevelOfParallelism();
63  return ret;
64 }
65 
67 {
68  ComplexWeight localWeight;
69  for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
70  {
71  (*it)->getWeightRegardingDPL(&localWeight);
72  weight->addWeight(&localWeight);
73  localWeight.setToZero();
74  }
75 }
76 
78 {
79  std::vector< std::pair<const PartDefinition *, const ComplexWeight *> > parts;
80  std::vector< int> nbCoresPerShot;
81  std::vector<std::size_t> v;
82  std::vector<ComplexWeight> nodesWeight(_nodes.size());
83  std::size_t ii(0);
84  for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
85  {
86  ComplexWeight *w=&nodesWeight[ii];
87  (*it)->getWeightRegardingDPL(w);
88  parts.push_back(std::pair<const PartDefinition *, const ComplexWeight *>(pd,w));
89  nbCoresPerShot.push_back((*it)->getMaxLevelOfParallelism());
90  v.push_back(ii);
91  }
92  std::vector<AbstractPoint *> nodes2(_nodes.begin(),_nodes.end());
93  if(!parts.empty())
94  {
95  const PlayGround *pg(pd->getPlayGround());
96  std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > pds(pg->partition(parts,nbCoresPerShot));
97  ii=0;
98  for(std::vector<std::size_t>::const_iterator iter=v.begin();iter!=v.end();iter++,ii++)
99  nodes2[*iter]->partitionRegardingDPL(pds[ii],zeMap);
100  }
101 }
102 
103 std::string ForkBlocPoint::getRepr() const
104 {
105  std::size_t sz(_nodes.size()),ii(0);
106  std::string ret("[");
107  std::vector<std::string> elts(sz);
108  for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
109  elts[ii]=(*it)->getRepr();
110  std::sort(elts.begin(),elts.end());
111  ii=0;
112  for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
113  {
114  ret+=elts[ii];
115  if(ii!=sz-1)
116  ret+="*";
117  }
118  ret+="]";
119  return ret;
120 }
121 
123 {
124  pv->beginForkBlocPoint(this);
125  for(auto it:_nodes)
126  it->accept(pv);
127  pv->endForkBlocPoint(this);
128 }
129 
130 AbstractPoint *ForkBlocPoint::expandNonSimpleCaseOn(NotSimpleCasePoint *pathologicalPt, const std::set<Node *>& uncatchedNodes)
131 {
132  for(auto& it : _nodes)
133  {
134  AbstractPoint *ret(it->expandNonSimpleCaseOn(pathologicalPt,uncatchedNodes));
135  if(ret!=it)
136  {
137  ret->setFather(this);
138  auto oldIt(it);
139  it = ret;
140  delete oldIt;
141  }
142  }
143  return this;
144 }
145 
void setFather(AbstractPoint *father)
void deepCopyFrom(const BlocPoint &other)
Definition: BlocPoint.cxx:34
std::list< AbstractPoint * > _nodes
Definition: BlocPoint.hxx:35
void addWeight(const ComplexWeight *other)
Base class for all composed nodes.
Node * getFirstNode() override
std::string getRepr() const
void getWeightRegardingDPL(ComplexWeight *weight)
void partitionRegardingDPL(const PartDefinition *pd, std::map< ComposedNode *, YACS::BASES::AutoRefCnt< PartDefinition > > &zeMap) const
AbstractPoint * deepCopy(AbstractPoint *father) const override
AbstractPoint * expandNonSimpleCaseOn(NotSimpleCasePoint *pathologicalPt, const std::set< Node * > &uncatchedNodes) override
void accept(PointVisitor *pv) override
Node * getLastNode() override
Base class for all nodes.
Definition: Node.hxx:70
const PlayGround * getPlayGround() const
Definition: PlayGround.hxx:127
std::vector< YACS::BASES::AutoRefCnt< PartDefinition > > partition(const std::vector< std::pair< const PartDefinition *, const ComplexWeight * > > &parts, const std::vector< int > &nbCoresPerShot) const
Definition: PlayGround.cxx:298
virtual void endForkBlocPoint(ForkBlocPoint *pt)=0
virtual void beginForkBlocPoint(ForkBlocPoint *pt)=0