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