]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/ForkBlocPoint.cxx
Salome HOME
Visitor for AbstractPoint
[modules/yacs.git] / src / engine / ForkBlocPoint.cxx
1 // Copyright (C) 2015-2016  CEA/DEN, EDF R&D
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
32 ForkBlocPoint::~ForkBlocPoint()
33 {
34 }
35
36 Node *ForkBlocPoint::getFirstNode()
37 {
38   if(_nodes.empty())
39     throw Exception("ForkBlocPoint::getFirstNode : error no branches !");
40   return _nodes.front()->getFirstNode();
41 }
42
43 Node *ForkBlocPoint::getLastNode()
44 {
45   if(_nodes.empty())
46     throw Exception("ForkBlocPoint::getLastNode : error no branches !");
47   return _nodes.front()->getLastNode();//not a bug - seen from the outside only first branch exists !
48 }
49
50 int ForkBlocPoint::getMaxLevelOfParallelism() const
51 {
52   int ret(0);
53   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
54     ret+=(*it)->getMaxLevelOfParallelism();
55   return ret;
56 }
57
58 void ForkBlocPoint::getWeightRegardingDPL(ComplexWeight *weight)
59 {
60   ComplexWeight localWeight;
61   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
62   {
63     (*it)->getWeightRegardingDPL(&localWeight);
64     weight->addWeight(&localWeight);
65     localWeight.setToZero();
66   }
67 }
68
69 void ForkBlocPoint::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
70 {
71   std::vector< std::pair<const PartDefinition *, const ComplexWeight *> > parts;
72   std::vector< int> nbCoresPerShot;
73   std::vector<std::size_t> v;
74   std::vector<ComplexWeight> nodesWeight(_nodes.size());
75   std::size_t ii(0);
76   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
77     {
78       ComplexWeight *w=&nodesWeight[ii];
79       (*it)->getWeightRegardingDPL(w);
80       parts.push_back(std::pair<const PartDefinition *, const ComplexWeight *>(pd,w));
81       nbCoresPerShot.push_back((*it)->getMaxLevelOfParallelism());
82       v.push_back(ii);
83     }
84   std::vector<AbstractPoint *> nodes2(_nodes.begin(),_nodes.end());
85   if(!parts.empty())
86     {
87       const PlayGround *pg(pd->getPlayGround());
88       std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > pds(pg->partition(parts,nbCoresPerShot));
89       ii=0;
90       for(std::vector<std::size_t>::const_iterator iter=v.begin();iter!=v.end();iter++,ii++)
91         nodes2[*iter]->partitionRegardingDPL(pds[ii],zeMap);
92     }
93 }
94
95 std::string ForkBlocPoint::getRepr() const
96 {
97   std::size_t sz(_nodes.size()),ii(0);
98   std::string ret("[");
99   std::vector<std::string> elts(sz);
100   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
101     elts[ii]=(*it)->getRepr();
102   std::sort(elts.begin(),elts.end());
103   ii=0;
104   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
105     {
106       ret+=elts[ii];
107       if(ii!=sz-1)
108         ret+="*";
109     }
110   ret+="]";
111   return ret;
112 }
113
114 void ForkBlocPoint::accept(PointVisitor *pv)
115 {
116   pv->beginForkBlocPoint(this);
117   for(auto it:_nodes)
118     it->accept(pv);
119   pv->endForkBlocPoint(this);
120 }