1 // Copyright (C) 2006-2016 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;
61 static const char NAME_OF_SPLITTED_SEQ_OUT[];
62 static const char OLD_NAME_OF_SPLITTED_SEQ_OUT[];
63 static const char NAME_OF_NUMBER_OF_BRANCHES[];
65 DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted);
66 virtual ~DynParaLoop();
67 DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
70 Node *edRemoveInitNode();
71 Node *edRemoveFinalizeNode();
72 //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
73 Node *edSetNode(Node *DISOWNnode);
74 Node *edSetInitNode(Node *DISOWNnode);
75 Node *edSetFinalizeNode(Node *DISOWNnode);
76 virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
77 void init(bool start=true);
78 InputPort *edGetNbOfBranchesPort() { return &_nbOfBranches; }
79 int getNumberOfInputPorts() const;
80 int getNumberOfOutputPorts() const;
81 unsigned getNumberOfEltsConsumed() const { return _nbOfEltConsumed; }
82 int getBranchIDOfNode(Node *node) const;
83 std::list<OutputPort *> getSetOfOutputPort() const;
84 std::list<OutputPort *> getLocalOutputPorts() const;
85 OutputPort *edGetSamplePort() { return &_splittedPort; }
86 OutPort *getOutPort(const std::string& name) const throw(Exception);
87 InputPort *getInputPort(const std::string& name) const throw(Exception);
88 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
89 //! For the moment false is returned : impovement about it coming soon.
90 bool isPlacementPredictableB4Run() const;
91 void edRemoveChild(Node *node) throw(Exception);
92 virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
93 std::list<Node *> edGetDirectDescendants() const;
94 std::list<InputPort *> getSetOfInputPort() const;
95 std::list<InputPort *> getLocalInputPorts() const;
96 unsigned getNumberOfBranchesCreatedDyn() const throw(Exception);
97 Node *getChildByShortName(const std::string& name) const throw(Exception);
98 Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
99 std::vector<Node *> getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes
100 bool isMultiplicitySpecified(unsigned& value) const;
101 void forceMultiplicity(unsigned value);
102 virtual void checkBasicConsistency() const throw(Exception);
103 virtual std::string getErrorReport();
104 void accept(Visitor *visitor);
105 Node * getInitNode();
106 Node * getExecNode();
107 Node * getFinalizeNode();
108 int getMaxLevelOfParallelism() const;
110 void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
111 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
112 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
113 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
114 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
115 std::vector<OutPort *>& fwCross,
116 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
117 LinkInfo& info) const;
118 virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
119 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
121 void cleanDynGraph();
122 void prepareInputsFromOutOfScope(int branchNb);
123 void putValueOnBranch(Any *val, unsigned branchId, bool first);
124 TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
125 InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
126 virtual void forwardExecStateToOriginalBody(Node *execNode);
127 virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
128 std::vector<Node *> cloneAndPlaceNodesCoherently(const std::vector<Node *> & origNodes);
129 Node * checkConsistencyAndSetNode(Node* &nodeToReplace, Node* DISOWNnode);
130 Node * removeNode(Node* &nodeToRemove);
131 virtual void shutdown(int level);