Salome HOME
Copyright update 2020
[modules/yacs.git] / src / runtime / SalomeHPContainer.hxx
1 // Copyright (C) 2006-2020  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 __SALOMEHPCONTAINER_HXX__
21 #define __SALOMEHPCONTAINER_HXX__
22
23 #include "YACSRuntimeSALOMEExport.hxx"
24 #include "HomogeneousPoolContainer.hxx"
25 #include "SalomeContainerHelper.hxx"
26 #include "SalomeContainerTools.hxx"
27 #include "SalomeHPContainerTools.hxx"
28 #include "PlayGround.hxx"
29
30 #include "Mutex.hxx"
31 #include "AutoRefCnt.hxx"
32
33 #include <string>
34 #include <vector>
35 #include <map>
36 #include <SALOMEconfig.h>
37 #include CORBA_CLIENT_HEADER(SALOME_Component)
38 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
39
40 namespace YACS
41 {
42   namespace ENGINE
43   {
44     class Task;
45     class SalomeComponent;
46     class SalomeHPContainer;
47     
48     class YACSRUNTIMESALOME_EXPORT SalomeHPContainerBase : public HomogeneousPoolContainer
49     {
50     protected:
51       SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared);
52       SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared, bool isRefEaten);
53       SalomeHPContainerBase(const SalomeHPContainerBase& other);
54       void startInternal(const Task *askingNode, SalomeContainerToolsBase& sct, const std::vector<std::string>& compoNames);
55       SalomeHPContainer *getTheBoss();
56       const SalomeHPContainer *getTheBoss() const;
57     public:
58       void release(const Task *node);
59       //
60       bool isAlreadyStarted(const Task *askingNode) const;
61       void shutdown(int level);
62       //! For thread safety for concurrent load operation on same Container.
63       void lock();
64       //! For thread safety for concurrent load operation on same Container.
65       void unLock();
66       void setSizeOfPool(int sz);
67       int getSizeOfPool() const;
68       void setProperty(const std::string& name,const std::string& value);
69       std::string getProperty(const std::string& name) const;
70       std::map<std::string,std::string> getProperties() const;
71       void clearProperties();
72       std::string getPlacementId(const Task *askingNode) const;
73       std::string getFullPlacementId(const Task *askingNode) const;
74       std::map<std::string,std::string> getResourceProperties(const std::string& name) const;
75       void addComponentName(const std::string& name);
76       void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception);
77       Engines::Container_var getContainerPtr(const Task *askingNode) const;
78       std::vector<std::string> getKernelContainerNames() const;
79     public:
80       int getShutdownLev() const { return _shutdownLevel; }
81       YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> decorate(YACS::BASES::AutoConstRefCnt<PartDefinition> pd);
82 #ifndef SWIG
83       const SalomeHPContainerVectOfHelper *getDirectAccessToVecOfCont() const { return _launchModeType; }
84 #endif
85     protected:
86       int _shutdownLevel;
87       YACS::BASES::AutoRefCnt<SalomeHPContainerVectOfHelper> _launchModeType;
88       std::string _initScript;
89     };
90     
91     class YACSRUNTIMESALOME_EXPORT SalomeHPContainer : public SalomeHPContainerBase
92     {
93     public:
94       SalomeHPContainer();
95       SalomeHPContainer(const SalomeHPContainer& other);
96       //HP specific part
97       std::size_t getNumberOfFreePlace() const;
98       void allocateFor(const std::vector<const Task *>& nodes);
99       //
100       std::string getKind() const;
101       std::string getDiscreminantStrOfThis(const Task *askingNode) const;
102       void start(const Task *askingNode) throw(Exception);
103       Container *clone() const;
104       Container *cloneAlways() const;
105       int getNumberOfCoresPerWorker() const;
106       //! do nothing. because no special actions to do. Only for decorators
107       void prepareMaskForExecution() const { }
108       //
109 #ifndef SWIG
110       void forYourTestsOnly(ForTestOmlyHPContCls *data) const;
111       std::map<std::string,std::string> getResourcePropertiesSpe(const std::string& name) const;
112       void addComponentNameSpe(const std::string& name);
113       void checkCapabilityToDealWithSpe(const ComponentInstance *inst) const throw(YACS::Exception);
114       std::size_t locateTask(const Task *askingNode) const { return _launchModeType->locateTask(askingNode); }
115       const SalomeContainerTools &getContainerInfo() const { return _sct; }
116       SalomeContainerTools &getContainerInfo() { return _sct; }
117       std::vector<std::string> getComponentNames() const { return _componentNames; }
118       SalomeContainerMonoHelper *getHelperOfTask(const Task *node) { return _launchModeType->getHelperOfTask(node); }
119       const SalomeContainerMonoHelper *getHelperOfTask(const Task *node) const { return _launchModeType->getHelperOfTask(node); }
120       //
121       HomogeneousPoolContainer *getDirectFather() { return NULL; }
122       const HomogeneousPoolContainer *getDirectFather() const { return NULL; }
123 #endif
124     public:
125       static const char KIND[];
126     protected:
127 #ifndef SWIG
128       ~SalomeHPContainer();
129 #endif
130     protected:
131       SalomeContainerTools _sct;
132       std::vector<std::string> _componentNames;
133     };
134
135 #ifndef SWIG
136     class YACSRUNTIMESALOME_EXPORT SalomeHPContainerShared : public SalomeHPContainerBase
137     {
138     public:
139       SalomeHPContainerShared(YACS::BASES::AutoConstRefCnt<PartDefinition> pd, SalomeHPContainerVectOfHelper *resShared, SalomeHPContainerBase *directFather);
140       HomogeneousPoolContainer *getDirectFather() { return _directFather; }
141       const HomogeneousPoolContainer *getDirectFather() const { return _directFather; }
142       int getNumberOfCoresPerWorker() const { return _directFather->getNumberOfCoresPerWorker(); }
143       std::string getProperty(const std::string& name) const { return _directFather->getProperty(name); }
144       void prepareMaskForExecution() const;
145       void forYourTestsOnly(ForTestOmlyHPContCls *data) const;
146       std::string getName() const;
147       std::string getDiscreminantStrOfThis(const Task *askingNode) const;
148     public:
149       std::string getKind() const;
150       void start(const Task *askingNode) throw(Exception);
151       Container *clone() const;
152       Container *cloneAlways() const;
153       //
154       void allocateFor(const std::vector<const Task *>& nodes);
155       std::size_t getNumberOfFreePlace() const;
156     private:
157       YACS::BASES::AutoRefCnt<SalomeHPContainerBase> _directFather;
158       YACS::BASES::AutoConstRefCnt<PartDefinition> _pd;
159       //! ids in _launchModeType covered by _pd.
160       mutable std::vector<std::size_t> _idsOfKernelContainers;
161     };
162 #endif
163   }
164 }
165
166 #endif