Salome HOME
Merge branch 'omu/testpy3' into agy/optim_fe_0_2
[modules/yacs.git] / src / engine / DynParaLoop.hxx
1 // Copyright (C) 2006-2019  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 #ifndef __DYNPARALOOP_HXX__
21 #define __DYNPARALOOP_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "ComposedNode.hxx"
25 #include "AnyInputPort.hxx"
26 #include "AnyOutputPort.hxx"
27 #include "OutputPort.hxx"
28 #include "NbBranches.hxx"
29
30 #include <memory>
31
32 namespace YACS
33 {
34   namespace ENGINE
35   { 
36     /*!
37      * \brief Base class for dynamically (fully or semifully) built graphs.
38      * \ingroup Nodes
39      */
40     class YACSLIBENGINE_EXPORT DynParaLoop : public ComposedNode
41     {
42     protected:
43       typedef enum
44         {
45           INIT_NODE = 5,
46           WORK_NODE = 6,
47           FINALIZE_NODE = 7
48       } TypeOfNode;
49     protected:
50       Node *_node;
51       Node *_initNode;
52       Node *_finalizeNode;
53       unsigned _nbOfEltConsumed;
54       std::vector<int> _execIds;
55       //NbBranches _nbOfBranches2;
56       std::unique_ptr<NbBranchesAbstract> _nbOfBranches;
57       AnyOutputPort _splittedPort;
58       std::vector<Node *> _execNodes;
59       std::vector<Node *> _execInitNodes;
60       std::vector<Node *> _execFinalizeNodes;
61       int _initializingCounter;
62       int _unfinishedCounter;
63       int _failedCounter;
64       ComplexWeight _weight;
65       double _loopWeight;
66     protected:
67       static const char NAME_OF_SPLITTED_SEQ_OUT[];
68       static const char OLD_NAME_OF_SPLITTED_SEQ_OUT[];
69     protected:
70       DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted, std::unique_ptr<NbBranchesAbstract>&& branchManager);
71       virtual ~DynParaLoop();
72       DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
73     public:
74       Node *edRemoveNode();
75       Node *edRemoveInitNode();
76       Node *edRemoveFinalizeNode();
77       //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
78       Node *edSetNode(Node *DISOWNnode);
79       Node *edSetInitNode(Node *DISOWNnode);
80       Node *edSetFinalizeNode(Node *DISOWNnode);
81       virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
82       void init(bool start=true);
83       InputPort *edGetNbOfBranchesPort() { return _nbOfBranches->getPort(); }
84       int getNumberOfInputPorts() const;
85       int getNumberOfOutputPorts() const;
86       unsigned getNumberOfEltsConsumed() const { return _nbOfEltConsumed; }
87       int getBranchIDOfNode(Node *node) const;
88       std::list<OutputPort *> getSetOfOutputPort() const;
89       std::list<OutputPort *> getLocalOutputPorts() const;
90       OutputPort *edGetSamplePort() { return &_splittedPort; }
91       OutPort *getOutPort(const std::string& name) const throw(Exception);
92       InputPort *getInputPort(const std::string& name) const throw(Exception);
93       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
94       //! For the moment false is returned : impovement about it coming soon.
95       bool isPlacementPredictableB4Run() const;
96       void edRemoveChild(Node *node) throw(Exception);
97       bool isLoop() const override { return true; }
98       virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
99       std::list<Node *> edGetDirectDescendants() const;
100       std::list<InputPort *> getSetOfInputPort() const;
101       std::list<InputPort *> getLocalInputPorts() const;
102       unsigned getNumberOfBranchesCreatedDyn() const throw(Exception);
103       Node *getChildByShortName(const std::string& name) const throw(Exception);
104       Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
105       std::vector<Node *> getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes
106       ComplexWeight * getWeight();
107       void setWeight(double loopWeight);
108       void getWeightRegardingDPL(ComplexWeight *weight) {weight->addWeight(getWeight());}
109       bool isMultiplicitySpecified(unsigned& value) const;
110       void forceMultiplicity(unsigned value);
111       virtual void checkBasicConsistency() const throw(Exception);
112       virtual std::string getErrorReport();
113       void accept(Visitor *visitor);
114       Node * getInitNode();
115       Node * getExecNode();
116       Node * getFinalizeNode();
117       int getMaxLevelOfParallelism() const;
118       void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
119       virtual void cleanDynGraph();
120     protected:
121       void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
122       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
123       void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
124       void checkControlDependancy(OutPort *start, InPort *end, bool cross,
125                                   std::map < ComposedNode *,  std::list < OutPort * >, SortHierarc >& fw,
126                                   std::vector<OutPort *>& fwCross,
127                                   std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
128                                   LinkInfo& info) const;
129       virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
130                                        InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
131     protected:
132       void prepareInputsFromOutOfScope(int branchNb);
133       void putValueOnBranch(Any *val, unsigned branchId, bool first);
134       TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
135       InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
136       virtual void forwardExecStateToOriginalBody(Node *execNode);
137       virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
138       std::vector<Node *> cloneAndPlaceNodesCoherently(const std::vector<Node *> & origNodes);
139       Node * checkConsistencyAndSetNode(Node* &nodeToReplace, Node* DISOWNnode);
140       Node * removeNode(Node* &nodeToRemove);
141       virtual void shutdown(int level);
142     };
143   }
144 }
145
146 #endif