Version: 9.16.0
Bloc_impl.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 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 "Bloc.hxx"
21#include "Proc.hxx"
22#include "Visitor.hxx"
23#include "ForEachLoop.hxx"
24#include "InlineNode.hxx"
25#include "ServiceNode.hxx"
26#include "ServerNode.hxx"
28
29using namespace YACS::ENGINE;
30
31void Bloc::fitToPlayGround(const PlayGround *pg)
32{
33 static const char MSG[]="Bloc::fitToPlayGround : Not implemented yet for this type of node !";
34 class MyVisitor : public Visitor
35 {
36 public:
37 MyVisitor(ComposedNode *root):Visitor(root),_lev(0),_max_lev(0) { }
38 void visitBloc(Bloc *node) { node->ComposedNode::accept(this); }
39 void visitElementaryNode(ElementaryNode *node) { }
40 void visitForEachLoop(ForEachLoop *node)
41 {
42 _max_lev=std::max(_max_lev,_lev);
43 {
44 _lev++;
45 node->ComposedNode::accept(this);
46 _lev--;
47 }
48 node->edGetNbOfBranchesPort()->edInit(1);
49 if(_lev==_max_lev)
50 {
51 _fes.push_back(node);// locate all leaves ForEach
52 }
53 if(_lev==0)
54 _max_lev=0;
55 }
56 void visitForEachLoopDyn(ForEachLoopDyn *node) { throw YACS::Exception(MSG); }
57 void visitOptimizerLoop(OptimizerLoop *node) { throw YACS::Exception(MSG); }
58 void visitDynParaLoop(DynParaLoop *node) { throw YACS::Exception(MSG); }
59 void visitForLoop(ForLoop *node) { throw YACS::Exception(MSG); }
60 void visitInlineNode(InlineNode *node)
61 {
62 Container *cont(node->getContainer());
63 HomogeneousPoolContainer *cont2(dynamic_cast<HomogeneousPoolContainer *>(cont));
64 if(!cont2)
65 return ;
66 _cont.push_back(cont2);
67 _cont2.insert(cont2);
68 }
69 void visitInlineFuncNode(InlineFuncNode *node) { throw YACS::Exception(MSG); }
70 void visitLoop(Loop *node) { throw YACS::Exception(MSG); }
71 void visitProc(Proc *node) { node->ComposedNode::accept(this); }
72 void visitServiceNode(ServiceNode *node) { throw YACS::Exception(MSG); }
73 void visitServerNode(ServerNode *node) { throw YACS::Exception(MSG); }
74 void visitServiceInlineNode(ServiceInlineNode *node) { throw YACS::Exception(MSG); }
75 void visitSwitch(Switch *node) { throw YACS::Exception(MSG); }
76 void visitWhileLoop(WhileLoop *node) { throw YACS::Exception(MSG); }
77 void visitPresetNode(DataNode *node) { throw YACS::Exception(MSG); }
78 void visitOutNode(DataNode *node) { throw YACS::Exception(MSG); }
79 void visitStudyInNode(DataNode *node) { throw YACS::Exception(MSG); }
80 void visitStudyOutNode(DataNode *node) { throw YACS::Exception(MSG); }
81 public:
82 std::list<ForEachLoop *> _fes;
83 std::list< HomogeneousPoolContainer *> _cont;
84 std::set< HomogeneousPoolContainer * > _cont2;
85 int _lev;
86 int _max_lev;
87 };
89 std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> > zeMap;
90 MyVisitor vis(this);
91 this->accept(&vis);
92 for(std::list<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
93 (*it)->edGetNbOfBranchesPort()->edInit(1);
96 throw YACS::Exception("Bloc::fitToPlayGround : Not enough cores available to run the calculation !");
97 this->partitionRegardingDPL(pd,zeMap);
98 this->accept(&vis);
99 for(std::list<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
100 {
101 std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> >::iterator it2(zeMap.find(*it));
102 if(it2==zeMap.end())
103 throw YACS::Exception("Bloc::fitToPlayGround : internal error !");
104 int maxLev((*it)->getExecNode()->getMaxLevelOfParallelism());
105 int a((*it2).second->getNumberOfCoresConsumed());
106 int res(a/maxLev);
107 (*it)->edGetNbOfBranchesPort()->edInit(res);
108 }
109 for(std::set< HomogeneousPoolContainer * >::const_iterator it=vis._cont2.begin();it!=vis._cont2.end();it++)
110 (*it)->setSizeOfPool(pg->getNumberOfWorkers((*it)->getNumberOfCoresPerWorker()));
111 //FIXME
112}
113
114constexpr char MSG[]="Bloc::propagePlayGround : Not implemented yet for this type of node !";
116 {
117 public:
119 void visitBloc(Bloc *node) { node->ComposedNode::accept(this); }
121 void visitForEachLoop(ForEachLoop *node) { node->ComposedNode::accept(this); }
122 void visitForEachLoopDyn(ForEachLoopDyn *node) { node->ComposedNode::accept(this); }
125 void visitForLoop(ForLoop *node) { throw YACS::Exception(MSG); }
126 template<class NodeClass>
127 void visitNodeWithContainer(NodeClass *node)
128 {
129 Container *cont(node->getContainer());
130 HomogeneousPoolContainer *cont2(dynamic_cast<HomogeneousPoolContainer *>(cont));
131 if(!cont2)
132 return ;
133 _cont2.insert(cont2);
134 }
135 void visitInlineNode(InlineNode *node) { this->visitNodeWithContainer<InlineNode>(node); }
136 void visitInlineFuncNode(InlineFuncNode *node) { visitInlineNode(node); }
137 void visitLoop(Loop *node) { throw YACS::Exception(MSG); }
138 void visitProc(Proc *node) { node->ComposedNode::accept(this); }
139 void visitServiceNode(ServiceNode *node) { this->visitNodeWithContainer<ServiceNode>(node); }
140 void visitServerNode(ServerNode *node) { visitInlineNode(node); }
142 void visitSwitch(Switch *node) { throw YACS::Exception(MSG); }
145 void visitOutNode(DataNode *node) { throw YACS::Exception(MSG); }
148 public:
149 std::set< HomogeneousPoolContainer * > _cont2;
150};
151
153{
154 MyVisitorPropagate vis(this);
155 this->accept(&vis);
156 for(auto cont : vis._cont2)
157 cont->assignPG(pg);
158}
constexpr char MSG[]
Definition: Bloc_impl.cxx:114
void visitServiceInlineNode(ServiceInlineNode *node)
Definition: Bloc_impl.cxx:141
void visitDynParaLoop(DynParaLoop *node)
Definition: Bloc_impl.cxx:124
void visitServiceNode(ServiceNode *node)
Definition: Bloc_impl.cxx:139
void visitStudyOutNode(DataNode *node)
Definition: Bloc_impl.cxx:147
void visitNodeWithContainer(NodeClass *node)
Definition: Bloc_impl.cxx:127
void visitBloc(Bloc *node)
Definition: Bloc_impl.cxx:119
void visitSwitch(Switch *node)
Definition: Bloc_impl.cxx:142
void visitLoop(Loop *node)
Definition: Bloc_impl.cxx:137
void visitInlineNode(InlineNode *node)
Definition: Bloc_impl.cxx:135
void visitOutNode(DataNode *node)
Definition: Bloc_impl.cxx:145
void visitPresetNode(DataNode *node)
Definition: Bloc_impl.cxx:144
std::set< HomogeneousPoolContainer * > _cont2
Definition: Bloc_impl.cxx:149
void visitStudyInNode(DataNode *node)
Definition: Bloc_impl.cxx:146
void visitForLoop(ForLoop *node)
Definition: Bloc_impl.cxx:125
void visitElementaryNode(ElementaryNode *node)
Definition: Bloc_impl.cxx:120
void visitOptimizerLoop(OptimizerLoop *node)
Definition: Bloc_impl.cxx:123
void visitInlineFuncNode(InlineFuncNode *node)
Definition: Bloc_impl.cxx:136
void visitForEachLoop(ForEachLoop *node)
Definition: Bloc_impl.cxx:121
void visitWhileLoop(WhileLoop *node)
Definition: Bloc_impl.cxx:143
void visitProc(Proc *node)
Definition: Bloc_impl.cxx:138
void visitServerNode(ServerNode *node)
Definition: Bloc_impl.cxx:140
MyVisitorPropagate(ComposedNode *root)
Definition: Bloc_impl.cxx:118
void visitForEachLoopDyn(ForEachLoopDyn *node)
Definition: Bloc_impl.cxx:122
Composed node to group elementary and composed nodes.
Definition: Bloc.hxx:36
void removeRecursivelyRedundantCL()
Definition: Bloc.cxx:483
void accept(Visitor *visitor)
Definition: Bloc.cxx:447
void propagePlayGround(const PlayGround *pg)
Definition: Bloc_impl.cxx:152
void partitionRegardingDPL(const PartDefinition *pd, std::map< ComposedNode *, YACS::BASES::AutoRefCnt< PartDefinition > > &zeMap)
Definition: Bloc.cxx:495
int getMaxLevelOfParallelism() const
Definition: Bloc.cxx:456
Base class for all composed nodes.
Class for data parameters specification.
Definition: DataNode.hxx:38
Base class for dynamically (fully or semifully) built graphs.
Definition: DynParaLoop.hxx:41
InputPort * edGetNbOfBranchesPort()
Definition: DynParaLoop.hxx:83
Base class for all calculation nodes.
Loop node for parametric calculation.
Class for for loop node.
Definition: ForLoop.hxx:33
Class for calculation node (function) inlined (and executed) in the schema.
Definition: InlineNode.hxx:93
Class for calculation node (script) inlined (and executed) in the schema.
Definition: InlineNode.hxx:44
virtual Container * getContainer()
Definition: InlineNode.cxx:100
void edInit(T value)
Definition: InputPort.hxx:129
Base class for loop node.
Definition: Loop.hxx:147
friend class Visitor
Definition: Node.hxx:81
class to build optimization loops
int getNumberOfCoresAvailable() const
Definition: PlayGround.cxx:130
int getNumberOfWorkers(int nbCoresPerWorker) const
Definition: PlayGround.cxx:579
Base class for all schema objects.
Definition: Proc.hxx:44
Class for calculation node associated with a component service.
Definition: ServiceNode.hxx:35
Control node that emulates the C switch.
Definition: Switch.hxx:85
Class for a while loop.
Definition: WhileLoop.hxx:39