1 // Copyright (C) 2006-2020 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
20 #ifndef __DYNPARALOOP_HXX__
21 #define __DYNPARALOOP_HXX__
23 #include "YACSlibEngineExport.hxx"
24 #include "ComposedNode.hxx"
25 #include "AnyInputPort.hxx"
26 #include "AnyOutputPort.hxx"
27 #include "OutputPort.hxx"
34 * \brief Base class for dynamically (fully or semifully) built graphs.
37 class YACSLIBENGINE_EXPORT DynParaLoop : public ComposedNode
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;
60 ComplexWeight _weight;
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[];
67 DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted);
68 virtual ~DynParaLoop();
69 DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
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 bool isLoop() const override { return true; }
95 virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
96 std::list<Node *> edGetDirectDescendants() const;
97 std::list<InputPort *> getSetOfInputPort() const;
98 std::list<InputPort *> getLocalInputPorts() const;
99 unsigned getNumberOfBranchesCreatedDyn() const throw(Exception);
100 Node *getChildByShortName(const std::string& name) const throw(Exception);
101 Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
102 std::vector<Node *> getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes
103 ComplexWeight * getWeight();
104 void setWeight(double loopWeight);
105 void getWeightRegardingDPL(ComplexWeight *weight) {weight->addWeight(getWeight());}
106 bool isMultiplicitySpecified(unsigned& value) const;
107 void forceMultiplicity(unsigned value);
108 virtual void checkBasicConsistency() const throw(Exception);
109 virtual std::string getErrorReport();
110 void accept(Visitor *visitor);
111 Node * getInitNode();
112 Node * getExecNode();
113 Node * getFinalizeNode();
114 int getMaxLevelOfParallelism() const;
115 void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
116 virtual void cleanDynGraph();
118 void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
119 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
120 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
121 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
122 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
123 std::vector<OutPort *>& fwCross,
124 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
125 LinkInfo& info) const;
126 virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
127 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
129 void prepareInputsFromOutOfScope(int branchNb);
130 void putValueOnBranch(Any *val, unsigned branchId, bool first);
131 TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
132 InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
133 virtual void forwardExecStateToOriginalBody(Node *execNode);
134 virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
135 std::vector<Node *> cloneAndPlaceNodesCoherently(const std::vector<Node *> & origNodes);
136 Node * checkConsistencyAndSetNode(Node* &nodeToReplace, Node* DISOWNnode);
137 Node * removeNode(Node* &nodeToRemove);
138 virtual void shutdown(int level);