1 // Copyright (C) 2006-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "Visitor.hxx"
23 #include "ForEachLoop.hxx"
24 #include "InlineNode.hxx"
25 #include "ServiceNode.hxx"
26 #include "ServerNode.hxx"
27 #include "HomogeneousPoolContainer.hxx"
29 using namespace YACS::ENGINE;
31 void Bloc::fitToPlayGround(const PlayGround *pg)
33 static const char MSG[]="Bloc::fitToPlayGround : Not implemented yet for this type of node !";
34 class MyVisitor : public Visitor
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)
42 _max_lev=std::max(_max_lev,_lev);
45 node->ComposedNode::accept(this);
48 node->edGetNbOfBranchesPort()->edInit(1);
51 _fes.push_back(node);// locate all leaves ForEach
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)
62 Container *cont(node->getContainer());
63 HomogeneousPoolContainer *cont2(dynamic_cast<HomogeneousPoolContainer *>(cont));
66 _cont.push_back(cont2);
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); }
82 std::list<ForEachLoop *> _fes;
83 std::list< HomogeneousPoolContainer *> _cont;
84 std::set< HomogeneousPoolContainer * > _cont2;
88 YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg));
89 std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> > zeMap;
92 for(std::list<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
93 (*it)->edGetNbOfBranchesPort()->edInit(1);
94 this->removeRecursivelyRedundantCL();
95 if (this->getMaxLevelOfParallelism() > pg->getNumberOfCoresAvailable())
96 throw YACS::Exception("Bloc::fitToPlayGround : Not enough cores available to run the calculation !");
97 this->partitionRegardingDPL(pd,zeMap);
99 for(std::list<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
101 std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> >::iterator it2(zeMap.find(*it));
103 throw YACS::Exception("Bloc::fitToPlayGround : internal error !");
104 int maxLev((*it)->getExecNode()->getMaxLevelOfParallelism());
105 int a((*it2).second->getNumberOfCoresConsumed());
107 (*it)->edGetNbOfBranchesPort()->edInit(res);
109 for(std::set< HomogeneousPoolContainer * >::const_iterator it=vis._cont2.begin();it!=vis._cont2.end();it++)
110 (*it)->setSizeOfPool(pg->getNumberOfWorkers((*it)->getNumberOfCoresPerWorker()));
114 constexpr char MSG[]="Bloc::propagePlayGround : Not implemented yet for this type of node !";
115 class MyVisitorPropagate : public Visitor
118 MyVisitorPropagate(ComposedNode *root):Visitor(root) { }
119 void visitBloc(Bloc *node) { node->ComposedNode::accept(this); }
120 void visitElementaryNode(ElementaryNode *node) { }
121 void visitForEachLoop(ForEachLoop *node) { node->ComposedNode::accept(this); }
122 void visitForEachLoopDyn(ForEachLoopDyn *node) { node->ComposedNode::accept(this); }
123 void visitOptimizerLoop(OptimizerLoop *node) { throw YACS::Exception(MSG); }
124 void visitDynParaLoop(DynParaLoop *node) { throw YACS::Exception(MSG); }
125 void visitForLoop(ForLoop *node) { throw YACS::Exception(MSG); }
126 template<class NodeClass>
127 void visitNodeWithContainer(NodeClass *node)
129 Container *cont(node->getContainer());
130 HomogeneousPoolContainer *cont2(dynamic_cast<HomogeneousPoolContainer *>(cont));
133 _cont2.insert(cont2);
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); }
141 void visitServiceInlineNode(ServiceInlineNode *node) { throw YACS::Exception(MSG); }
142 void visitSwitch(Switch *node) { throw YACS::Exception(MSG); }
143 void visitWhileLoop(WhileLoop *node) { throw YACS::Exception(MSG); }
144 void visitPresetNode(DataNode *node) { throw YACS::Exception(MSG); }
145 void visitOutNode(DataNode *node) { throw YACS::Exception(MSG); }
146 void visitStudyInNode(DataNode *node) { throw YACS::Exception(MSG); }
147 void visitStudyOutNode(DataNode *node) { throw YACS::Exception(MSG); }
149 std::set< HomogeneousPoolContainer * > _cont2;
152 void Bloc::propagePlayGround(const PlayGround *pg)
154 MyVisitorPropagate vis(this);
156 for(auto cont : vis._cont2)