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 #include "SalomeHPContainer.hxx"
21 #include "SalomeHPComponent.hxx"
22 #include "SalomeContainerTmpForHP.hxx"
23 #include "AutoLocker.hxx"
24 #include "AutoRefCnt.hxx"
28 using namespace YACS::ENGINE;
30 const char SalomeHPContainer::KIND[]="HPSalome";
32 SalomeHPContainerBase::SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared):_launchModeType(resShared),_shutdownLevel(999)
36 SalomeHPContainerBase::SalomeHPContainerBase(const SalomeHPContainerBase& other):_shutdownLevel(999),_launchModeType(new SalomeHPContainerVectOfHelper),_initScript(other._initScript)
40 SalomeHPContainer *SalomeHPContainerBase::getTheBoss()
42 HomogeneousPoolContainer *ret(this);
43 while(ret->getDirectFather())
44 ret=ret->getDirectFather();
45 SalomeHPContainer *retC(dynamic_cast<SalomeHPContainer *>(ret));
47 throw Exception("SalomeHPContainerBase::getTheBoss : unexpected type of object !");
51 const SalomeHPContainer *SalomeHPContainerBase::getTheBoss() const
53 const HomogeneousPoolContainer *ret(this);
54 while(ret->getDirectFather())
55 ret=ret->getDirectFather();
56 const SalomeHPContainer *retC(dynamic_cast<const SalomeHPContainer *>(ret));
58 throw Exception("SalomeHPContainerBase::getTheBoss : unexpected type of object !");
62 void SalomeHPContainerBase::startInternal(const Task *askingNode, SalomeContainerToolsBase& sct, const std::vector<std::string>& compoNames)
64 SalomeContainerMonoHelper *helper(_launchModeType->getHelperOfTaskThreadSafe(askingNode));
65 SalomeContainerTools::Start(compoNames,helper,sct,_shutdownLevel,this,askingNode);
68 void SalomeHPContainerBase::shutdown(int level)
70 if(level < _shutdownLevel)
73 _launchModeType->shutdown();
76 SalomeHPContainerBase::SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared, bool isRefEaten):_launchModeType(resShared)
79 if(_launchModeType.isNotNull())
80 _launchModeType->incrRef();
83 bool SalomeHPContainerBase::isAlreadyStarted(const Task *askingNode) const
85 const SalomeContainerMonoHelper *helper(_launchModeType->getHelperOfTaskThreadSafe(askingNode));
86 return helper->isAlreadyStarted(askingNode);
89 void SalomeHPContainerBase::release(const Task *node)
91 _launchModeType->release(node);
94 void SalomeHPContainerBase::lock()
96 _launchModeType->lock();
99 void SalomeHPContainerBase::unLock()
101 _launchModeType->unLock();
104 void SalomeHPContainerBase::setSizeOfPool(int sz)
106 _launchModeType->resize(sz);
109 int SalomeHPContainerBase::getSizeOfPool() const
111 return _launchModeType->size();
114 void SalomeHPContainerBase::setProperty(const std::string& name,const std::string& value)
116 if(name==AOC_ENTRY)//no sense to set it ! It is always true ! ignore it !
118 else if(name==SIZE_OF_POOL_KEY)
120 std::istringstream iss(value);
125 else if(name==INITIALIZE_SCRIPT_KEY)
130 getTheBoss()->getContainerInfo().setProperty(name,value);
133 std::string SalomeHPContainerBase::getProperty(const std::string& name) const
137 return std::string("1");
139 else if(name==SIZE_OF_POOL_KEY)
141 std::ostringstream oss; oss << getSizeOfPool();
144 else if(name==INITIALIZE_SCRIPT_KEY)
149 return getTheBoss()->getContainerInfo().getProperty(name);
152 std::map<std::string,std::string> SalomeHPContainerBase::getProperties() const
154 std::map<std::string,std::string> ret(getTheBoss()->getContainerInfo().getProperties());
155 std::ostringstream oss; oss << getSizeOfPool();
156 ret[SIZE_OF_POOL_KEY]=oss.str();
157 if(!_initScript.empty())
158 ret[INITIALIZE_SCRIPT_KEY]=_initScript;
162 void SalomeHPContainerBase::clearProperties()
165 getTheBoss()->getContainerInfo().clearProperties();
168 std::string SalomeHPContainerBase::getPlacementId(const Task *askingNode) const
170 const SalomeContainerMonoHelper *helper(0);
172 YACS::BASES::AutoLocker<Container> alckCont(const_cast<SalomeHPContainerBase *>(this));
173 helper=_launchModeType->getHelperOfTask(askingNode);
175 return SalomeContainerTools::GetPlacementId(helper,this,askingNode);
178 std::string SalomeHPContainerBase::getFullPlacementId(const Task *askingNode) const
180 const SalomeContainerMonoHelper *helper(0);
182 YACS::BASES::AutoLocker<Container> alckCont(const_cast<SalomeHPContainerBase *>(this));
183 helper=_launchModeType->getHelperOfTask(askingNode);
185 return SalomeContainerTools::GetFullPlacementId(helper,this,askingNode);
188 std::map<std::string,std::string> SalomeHPContainerBase::getResourceProperties(const std::string& name) const
190 return getTheBoss()->getResourceProperties(name);
193 void SalomeHPContainerBase::addComponentName(const std::string& name)
195 getTheBoss()->addComponentNameSpe(name);
198 void SalomeHPContainerBase::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
200 getTheBoss()->checkCapabilityToDealWith(inst);
203 YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> SalomeHPContainerBase::decorate(YACS::BASES::AutoConstRefCnt<PartDefinition> pd)
205 YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> ret(new SalomeHPContainerShared(pd,_launchModeType,this));
209 Engines::Container_var SalomeHPContainerBase::getContainerPtr(const Task *askingNode) const
211 const SalomeContainerMonoHelper *helper(0);
213 YACS::BASES::AutoLocker<SalomeHPContainerBase> alck(const_cast<SalomeHPContainerBase *>(this));
214 helper=_launchModeType->getHelperOfTask(askingNode);
216 return helper->getContainer(NULL);
219 std::vector<std::string> SalomeHPContainerBase::getKernelContainerNames() const
221 return _launchModeType->getKernelContainerNames();
226 SalomeHPContainer::SalomeHPContainer():SalomeHPContainerBase(new SalomeHPContainerVectOfHelper)
230 SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):SalomeHPContainerBase(other),_sct(other._sct),_componentNames(other._componentNames)
234 std::size_t SalomeHPContainer::getNumberOfFreePlace() const
236 return _launchModeType->getNumberOfFreePlace();
239 void SalomeHPContainer::allocateFor(const std::vector<const Task *>& nodes)
241 _launchModeType->allocateFor(nodes);
244 SalomeHPContainer::~SalomeHPContainer()
248 std::string SalomeHPContainer::getKind() const
253 std::string SalomeHPContainer::getDiscreminantStrOfThis(const Task *askingNode) const
255 YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(this,askingNode));
256 return tmpCont->getDiscreminantStrOfThis(askingNode);
259 void SalomeHPContainer::start(const Task *askingNode) throw(YACS::Exception)
261 startInternal(askingNode,_sct,_componentNames);
265 * It is not a bug here ! clone for homogeneous container is not supposed to be copied !
267 Container *SalomeHPContainer::clone() const
270 return const_cast<SalomeHPContainer*>(this);
273 Container *SalomeHPContainer::cloneAlways() const
275 return new SalomeHPContainer(*this);
278 int SalomeHPContainer::getNumberOfCoresPerWorker() const
280 return _sct.getNumberOfCoresPerWorker();
283 std::map<std::string,std::string> SalomeHPContainer::getResourcePropertiesSpe(const std::string& name) const
285 return _sct.getResourceProperties(name);
288 void SalomeHPContainer::addComponentNameSpe(const std::string& name)
290 _componentNames.push_back(name);
293 void SalomeHPContainer::checkCapabilityToDealWithSpe(const ComponentInstance *inst) const throw(YACS::Exception)
295 if(inst->getKind()!=SalomeHPComponent::KIND)
296 throw Exception("SalomeHPContainer::checkCapabilityToDealWithSpe : SalomeContainer is not able to deal with this type of ComponentInstance.");
299 void SalomeHPContainer::forYourTestsOnly(ForTestOmlyHPContCls *data) const
301 data->setContainerType("HPContainer");
304 //////////////////////////////////
306 SalomeHPContainerShared::SalomeHPContainerShared(YACS::BASES::AutoConstRefCnt<PartDefinition> pd, SalomeHPContainerVectOfHelper *resShared, SalomeHPContainerBase *directFather):SalomeHPContainerBase(resShared,false),_pd(pd)
309 throw Exception("SalomeHPContainerShared : NULL pointer not allowed !");
310 _directFather.takeRef(directFather);
313 std::string SalomeHPContainerShared::getKind() const
315 return SalomeHPContainer::KIND;
318 void SalomeHPContainerShared::prepareMaskForExecution() const
320 _idsOfKernelContainers=_pd->computeWorkerIdsCovered(getNumberOfCoresPerWorker());
324 * It is not a bug here ! clone for homogeneous container is not supposed to be copied !
326 Container *SalomeHPContainerShared::clone() const
329 return const_cast<SalomeHPContainerShared*>(this);
332 Container *SalomeHPContainerShared::cloneAlways() const
334 throw Exception("SalomeHPContainerShared::cloneAlways : you are not supposed to be in this situation ! This type of container has only existence during execution !");
337 std::string SalomeHPContainerShared::getName() const
339 return getTheBoss()->getName();
342 std::string SalomeHPContainerShared::getDiscreminantStrOfThis(const Task *askingNode) const
344 return getTheBoss()->getDiscreminantStrOfThis(askingNode);
347 void SalomeHPContainerShared::start(const Task *askingNode) throw(YACS::Exception)
349 SalomeContainerToolsSpreadOverTheResDecorator sct(&getTheBoss()->getContainerInfo(),_pd->getPlayGround(),_launchModeType,askingNode);
350 startInternal(askingNode,sct,getTheBoss()->getComponentNames());
353 void SalomeHPContainerShared::allocateFor(const std::vector<const Task *>& nodes)
355 _launchModeType->allocateForAmong(_idsOfKernelContainers,nodes);
358 std::size_t SalomeHPContainerShared::getNumberOfFreePlace() const
360 return _launchModeType->getNumberOfFreePlaceAmong(_idsOfKernelContainers);
363 void SalomeHPContainerShared::forYourTestsOnly(ForTestOmlyHPContCls *data) const
365 data->setContainerType("HPContainerShared");
367 data->setIDS(_idsOfKernelContainers);
371 * SalomeHPContainerVectOfHelper is an holder of vector of SalomeContainerMonoHelper (holding itself a Kernel Container)
372 * SalomeContainerTools is a Engines::ContainerParameters holder. It is the data keeper for GiveContainer invokation.