1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
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 "HomogeneousPoolContainer.hxx"
27 using namespace YACS::ENGINE;
29 void Bloc::fitToPlayGround(const PlayGround *pg)
31 static const char MSG[]="Bloc::fitToPlayGround : Not implemented yet for this type of node !";
32 class MyVisitor : public Visitor
35 MyVisitor(ComposedNode *root):Visitor(root),_lev(0),_max_lev(0) { }
36 void visitBloc(Bloc *node) { node->ComposedNode::accept(this); }
37 void visitElementaryNode(ElementaryNode *node) { }
38 void visitForEachLoop(ForEachLoop *node)
40 _max_lev=std::max(_max_lev,_lev);
43 node->ComposedNode::accept(this);
46 node->edGetNbOfBranchesPort()->edInit(1);
49 _fes.push_back(node);// locate all leaves ForEach
54 void visitForEachLoopDyn(ForEachLoopDyn *node) { throw YACS::Exception(MSG); }
55 void visitOptimizerLoop(OptimizerLoop *node) { throw YACS::Exception(MSG); }
56 void visitDynParaLoop(DynParaLoop *node) { throw YACS::Exception(MSG); }
57 void visitForLoop(ForLoop *node) { throw YACS::Exception(MSG); }
58 void visitInlineNode(InlineNode *node)
60 Container *cont(node->getContainer());
61 HomogeneousPoolContainer *cont2(dynamic_cast<HomogeneousPoolContainer *>(cont));
64 _cont.push_back(cont2);
67 void visitInlineFuncNode(InlineFuncNode *node) { throw YACS::Exception(MSG); }
68 void visitLoop(Loop *node) { throw YACS::Exception(MSG); }
69 void visitProc(Proc *node) { node->ComposedNode::accept(this); }
70 void visitServiceNode(ServiceNode *node) { throw YACS::Exception(MSG); }
71 void visitServerNode(ServerNode *node) { throw YACS::Exception(MSG); }
72 void visitServiceInlineNode(ServiceInlineNode *node) { throw YACS::Exception(MSG); }
73 void visitSwitch(Switch *node) { throw YACS::Exception(MSG); }
74 void visitWhileLoop(WhileLoop *node) { throw YACS::Exception(MSG); }
75 void visitPresetNode(DataNode *node) { throw YACS::Exception(MSG); }
76 void visitOutNode(DataNode *node) { throw YACS::Exception(MSG); }
77 void visitStudyInNode(DataNode *node) { throw YACS::Exception(MSG); }
78 void visitStudyOutNode(DataNode *node) { throw YACS::Exception(MSG); }
80 std::list<ForEachLoop *> _fes;
81 std::list< HomogeneousPoolContainer *> _cont;
82 std::set< HomogeneousPoolContainer * > _cont2;
86 YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg));
87 std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> > zeMap;
90 for(std::list<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
91 (*it)->edGetNbOfBranchesPort()->edInit(1);
92 this->removeRecursivelyRedundantCL();
93 if (this->getMaxLevelOfParallelism() > pg->getNumberOfCoresAvailable())
94 throw YACS::Exception("Bloc::fitToPlayGround : Not enough cores available to run the calculation !");
95 this->partitionRegardingDPL(pd,zeMap);
97 for(std::list<ForEachLoop *>::const_iterator it=vis._fes.begin();it!=vis._fes.end();it++)
99 std::map<ComposedNode *,YACS::BASES::AutoRefCnt<PartDefinition> >::iterator it2(zeMap.find(*it));
101 throw YACS::Exception("Bloc::fitToPlayGround : internal error !");
102 int maxLev((*it)->getExecNode()->getMaxLevelOfParallelism());
103 int a((*it2).second->getNumberOfCoresConsumed());
105 (*it)->edGetNbOfBranchesPort()->edInit(res);
107 for(std::set< HomogeneousPoolContainer * >::const_iterator it=vis._cont2.begin();it!=vis._cont2.end();it++)
108 (*it)->setSizeOfPool(pg->getNumberOfWorkers((*it)->getNumberOfCoresPerWorker()));
112 void Bloc::propagePlayGround(const PlayGround *pg)
114 static const char MSG[]="Bloc::propagePlayGround : Not implemented yet for this type of node !";
115 class MyVisitor : public Visitor
118 MyVisitor(ComposedNode *root):Visitor(root) { }
119 void visitBloc(Bloc *node) { node->ComposedNode::accept(this); }
120 void visitElementaryNode(ElementaryNode *node) { }
121 void visitForEachLoop(ForEachLoop *node) { throw YACS::Exception(MSG); }
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 void visitInlineNode(InlineNode *node)
128 Container *cont(node->getContainer());
129 HomogeneousPoolContainer *cont2(dynamic_cast<HomogeneousPoolContainer *>(cont));
132 _cont2.insert(cont2);
134 void visitInlineFuncNode(InlineFuncNode *node) { throw YACS::Exception(MSG); }
135 void visitLoop(Loop *node) { throw YACS::Exception(MSG); }
136 void visitProc(Proc *node) { node->ComposedNode::accept(this); }
137 void visitServiceNode(ServiceNode *node) { throw YACS::Exception(MSG); }
138 void visitServerNode(ServerNode *node) { throw YACS::Exception(MSG); }
139 void visitServiceInlineNode(ServiceInlineNode *node) { throw YACS::Exception(MSG); }
140 void visitSwitch(Switch *node) { throw YACS::Exception(MSG); }
141 void visitWhileLoop(WhileLoop *node) { throw YACS::Exception(MSG); }
142 void visitPresetNode(DataNode *node) { throw YACS::Exception(MSG); }
143 void visitOutNode(DataNode *node) { throw YACS::Exception(MSG); }
144 void visitStudyInNode(DataNode *node) { throw YACS::Exception(MSG); }
145 void visitStudyOutNode(DataNode *node) { throw YACS::Exception(MSG); }
147 std::set< HomogeneousPoolContainer * > _cont2;
151 for(auto cont : vis._cont2)