1 // Copyright (C) 2006-2021 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 "PlayGround.hxx"
21 #include "Runtime.hxx"
31 using namespace YACS::ENGINE;
33 std::size_t Resource::getNumberOfFreePlace(int nbCoresPerCont) const
35 std::size_t ret(0),pos(0);
36 while( pos < _occupied.size() )
38 bool isChunckFree(true);
40 for( ; ( posInChunck < nbCoresPerCont ) && ( pos < _occupied.size() ) ; ++posInChunck, ++pos)
43 if( isChunckFree && (posInChunck == nbCoresPerCont) )
49 std::vector<std::size_t> Resource::allocateFor(std::size_t& nbOfPlacesToTake, int nbCoresPerCont) const
51 std::vector<std::size_t> ret;
52 std::size_t pos(0),curWorkerId(0);
53 while( ( pos < _occupied.size() ) && ( nbOfPlacesToTake > 0 ) )
55 bool isChunckFree(true);
57 for( ; ( posInChunck < nbCoresPerCont ) && ( pos < _occupied.size() ) ; ++posInChunck, ++pos)
60 if( isChunckFree && (posInChunck == nbCoresPerCont) )
62 for(int i = 0 ; i < nbCoresPerCont ; ++i)
63 _occupied[pos-nbCoresPerCont+i] = true;
64 ret.push_back(curWorkerId);
72 void Resource::release(std::size_t workerId, int nbCoresPerCont) const
74 if(workerId >= this->getNumberOfWorkers(nbCoresPerCont))
75 throw Exception("Resource::release : invalid worker id !");
76 std::size_t pos(workerId*static_cast<std::size_t>(nbCoresPerCont));
77 for(int i = 0 ; i < nbCoresPerCont ; ++i)
79 if(!_occupied[pos + static_cast<std::size_t>(i)])
80 throw Exception("Resource::release : internal error ! A core is expected to be occupied !");
81 _occupied[pos + static_cast<std::size_t>(i)] = false;
85 std::size_t Resource::getNumberOfWorkers(int nbCoresPerCont) const
87 return static_cast<std::size_t>(this->nbCores())/static_cast<std::size_t>(nbCoresPerCont);
90 void Resource::printSelf(std::ostream& oss) const
92 oss << this->name() << " (" << this->nbCores() << ") : ";
93 for(auto it : this->_occupied)
102 std::string PlayGround::printSelf() const
104 std::ostringstream oss;
107 sz=std::max(sz,it.name().length());
110 oss << " - " << std::setw(10) << it.name() << " : " << it.nbCores() << std::endl;
115 void PlayGround::loadFromKernelCatalog()
117 Runtime *r(getRuntime());
119 throw Exception("PlayGround::loadFromKernelCatalog : no runtime !");
120 std::vector< std::pair<std::string,int> > data(r->getCatalogOfComputeNodes());
124 void PlayGround::setData(const std::vector< std::pair<std::string,int> >& defOfRes)
126 _data=std::vector<Resource>(defOfRes.begin(),defOfRes.end());
130 int PlayGround::getNumberOfCoresAvailable() const
138 int PlayGround::getMaxNumberOfContainersCanBeHostedWithoutOverlap(int nbCoresPerCont) const
141 throw Exception("PlayGround::getMaxNumberOfContainersCanBeHostedWithoutOverlap : invalid nbCoresPerCont. Must be >=1 !");
144 ret+=it.nbCores()/nbCoresPerCont;
148 std::vector<int> PlayGround::computeOffsets() const
150 std::size_t sz(_data.size()),i(0);
151 std::vector<int> ret(sz+1); ret[0]=0;
152 for(auto it=_data.begin();it!=_data.end();it++,i++)
153 ret[i+1]=ret[i]+it->nbCores();
157 void PlayGround::checkCoherentInfo() const
159 std::set<std::string> s;
164 throw Exception("Presence of negative int value !");
166 if(s.size()!=_data.size())
167 throw Exception("host names entries must be different each other !");
170 std::vector<int> PlayGround::GetIdsMatching(const std::vector<bool>& bigArr, const std::vector<bool>& pat)
172 std::vector<int> ret;
173 std::size_t szp(pat.size());
174 std::size_t sz(bigArr.size()/szp);
175 for(std::size_t i=0;i<sz;i++)
177 std::vector<bool> t(bigArr.begin()+i*szp,bigArr.begin()+(i+1)*szp);
184 std::size_t PlayGround::getNumberOfFreePlace(int nbCoresPerCont) const
187 for(auto res : _data)
189 ret += res.getNumberOfFreePlace(nbCoresPerCont);
194 std::vector<std::size_t> PlayGround::allocateFor(std::size_t nbOfPlacesToTake, int nbCoresPerCont) const
196 std::vector<std::size_t> ret;
197 std::size_t nbOfPlacesToTakeCpy(nbOfPlacesToTake),offset(0);
198 for(const auto& res : _data)
200 std::vector<std::size_t> contIdsInRes(res.allocateFor(nbOfPlacesToTakeCpy,nbCoresPerCont));
201 std::for_each(contIdsInRes.begin(),contIdsInRes.end(),[offset](std::size_t& val) { val += offset; });
202 ret.insert(ret.end(),contIdsInRes.begin(),contIdsInRes.end());
203 offset += static_cast<std::size_t>(res.nbCores()/nbCoresPerCont);
205 if( ( nbOfPlacesToTakeCpy!=0 ) || ( ret.size()!=nbOfPlacesToTake ) )
206 throw Exception("PlayGround::allocateFor : internal error ! Promised place is not existing !");
210 void PlayGround::release(std::size_t workerId, int nbCoresPerCont) const
212 std::size_t offset(0);
213 for(const auto& res : _data)
215 std::size_t nbOfWorker(static_cast<std::size_t>(res.nbCores()/nbCoresPerCont));
216 std::size_t minId(offset),maxId(offset+nbOfWorker);
217 if(workerId>=minId && workerId<maxId)
219 res.release(workerId-minId,nbCoresPerCont);
225 void PlayGround::printMe() const
229 it.printSelf(std::cout);
230 std::cout << std::endl;
234 std::vector<int> PlayGround::BuildVectOfIdsFromVecBool(const std::vector<bool>& v)
236 std::size_t sz(std::count(v.begin(),v.end(),true)),i(0);
237 std::vector<int> ret(sz);
238 std::vector<bool>::const_iterator it(v.begin());
241 it=std::find(it,v.end(),true);
242 ret[i++]=std::distance(v.begin(),it);
248 void PlayGround::highlightOnIds(const std::vector<int>& coreIds, std::vector<bool>& v) const
250 if(v.size()!=getNumberOfCoresAvailable())
251 throw Exception("PlayGround::highlightOnIds : oops ! invalid size !");
252 for(std::vector<int>::const_iterator it=coreIds.begin();it!=coreIds.end();it++)
257 * you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, and PartDefinition::computeWorkerIdsCovered
259 // std::vector<bool> PlayGround::getFetchedCores(int nbCoresPerWorker) const
261 // int nbCores(getNumberOfCoresAvailable());
262 // std::vector<bool> ret(nbCores,false);
263 // if(nbCoresPerWorker==1)
264 // std::fill(ret.begin(),ret.end(),true);
267 // std::size_t posBg(0);
268 // for(std::vector< std::pair<std::string,int> >::const_iterator it=_data.begin();it!=_data.end();it++)
270 // int nbElemsToPutOn(((*it).second/nbCoresPerWorker)*nbCoresPerWorker);
271 // std::fill(ret.begin()+posBg,ret.begin()+posBg+nbElemsToPutOn,true);
272 // posBg+=(*it).second;
278 * follow getMaxNumberOfContainersCanBeHostedWithoutOverlap method
280 std::vector<std::size_t> PlayGround::getWorkerIdsFullyFetchedBy(int nbCoresPerComp, const std::vector<bool>& coreFlags) const
282 std::size_t posBg(0),posWorker(0);
283 std::vector<std::size_t> ret;
286 int nbWorker(it.nbCores()/nbCoresPerComp);
287 for(int j=0;j<nbWorker;j++,posWorker++)
289 std::vector<bool>::const_iterator it2(std::find(coreFlags.begin()+posBg+j*nbCoresPerComp,coreFlags.begin()+posBg+(j+1)*nbCoresPerComp,false));
290 if(it2==coreFlags.begin()+posBg+(j+1)*nbCoresPerComp)
291 ret.push_back(posWorker);
298 std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > PlayGround::partition(const std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >& parts, const std::vector< int>& nbCoresPerShot) const
300 std::size_t sz(parts.size()),szs(getNumberOfCoresAvailable());
301 if (sz!=nbCoresPerShot.size())
302 throw Exception("PlayGround::partition : incoherent vector size !");
304 return std::vector< YACS::BASES::AutoRefCnt<PartDefinition> >();
307 const PartDefinition *pd(parts[0].first);
309 throw Exception("Presence of null pointer as part def 0 !");
310 YACS::BASES::AutoRefCnt<PartDefinition> ret(pd->copy());
311 std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > ret2(1,ret);
315 throw Exception("PlayGround::partition : not implemented yet for more than 31 ! You need to pay for it :)");
316 std::vector<bool> zeArr(szs*sz,false);
318 for(std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >::const_iterator it=parts.begin();it!=parts.end();it++,i++)
320 const PartDefinition *pd((*it).first);
322 throw Exception("Presence of null pointer as part def !");
323 if(pd->getPlayGround()!=this)
324 throw Exception("Presence of non homogeneous playground !");
325 std::vector<bool> bs(pd->getCoresOn()); // tab of length nbCores, with True or False for each Core
326 for(std::size_t j=0;j<szs;j++)
327 zeArr[j*sz+i]=bs[j]; // remplis une table avec les valeurs de bs. La table est [nb part] * [nb cores]
329 std::vector< std::vector<int> > retIds(sz);
330 for(std::size_t i=0;i<szs;i++)
332 std::vector<bool> code(zeArr.begin()+i*sz,zeArr.begin()+(i+1)*sz);// vecteur contenant le true/false d'un coeur pour ttes les partitions
333 std::vector<int> locIds(GetIdsMatching(zeArr,code)); // liste des coeurs qui peuvent correspondre au pattern code
334 std::vector<int> partsIds(BuildVectOfIdsFromVecBool(code));// pour chaque partition retourne l'id de la premiere partition à true
337 std::vector<std::pair <const ComplexWeight *, int> > wg;
338 for(std::vector<int>::const_iterator it=partsIds.begin();it!=partsIds.end();it++)
340 wg.push_back(std::pair <const ComplexWeight *, int> (parts[*it].second, nbCoresPerShot[*it]));
342 std::vector< std::vector<int> > ress(splitIntoParts(locIds,wg));
344 for(std::vector<int>::const_iterator it=partsIds.begin();it!=partsIds.end();it++,k++)
346 retIds[*it].insert(retIds[*it].end(),ress[k].begin(),ress[k].end());
350 std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > ret(sz);
351 for(std::size_t i=0;i<sz;i++)
353 std::set<int> s(retIds[i].begin(),retIds[i].end());
354 std::vector<int> v(s.begin(),s.end());
355 ret[i]=PartDefinition::BuildFrom(this,v);
360 std::vector< std::vector<int> > PlayGround::splitIntoParts(const std::vector<int>& coreIds, const std::vector< std::pair <const ComplexWeight *, int> >& weights) const
362 std::size_t sz(weights.size());
364 return std::vector< std::vector<int> >();
365 std::vector< std::vector<int> > ret;
366 std::vector< std::vector<int> > disorderRet(sz);
367 std::vector<bool> zeArr(getNumberOfCoresAvailable(),false);
368 highlightOnIds(coreIds,zeArr);
369 int nbOfCoresToSplit(coreIds.size());
370 int totalSpace(coreIds.size());
371 int remainingSpace(totalSpace);
372 std::vector<int> nbOfCoresAllocated(sz);
373 std::vector<int> nbCoresPerShot(sz,-1);
374 // first every other branchs take its minimal part of the cake
375 // and remove branch without valid weight
377 std::map<int,int> saveOrder;
378 const std::vector< std::pair <const ComplexWeight *, int> > sortedWeights(bigToTiny(weights, saveOrder));
379 for(std::vector<std::pair <const ComplexWeight *, int> >::const_iterator it=sortedWeights.begin();it!=sortedWeights.end();it++,i++)
381 nbCoresPerShot[i]=(*it).second;
382 if ((*it).first->isUnsetLoopWeight())
384 nbOfCoresAllocated[i]=nbCoresPerShot[i]; // branch with only elementary nodes
386 else if (!(*it).first->hasValidLoopWeight())
388 nbOfCoresAllocated[i]=std::max((int)((double)totalSpace/(double)(sz)), nbCoresPerShot[i]); // branch with undefined weight, takes his part proportionnally to the number of branchs
392 nbOfCoresAllocated[i]=nbCoresPerShot[i];
395 remainingSpace-=std::accumulate(nbOfCoresAllocated.begin(), nbOfCoresAllocated.end(), 0);
396 //get critical path (between path with loopWeight)
397 int criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated);
398 if (criticalPathRank!=-1)
400 // add cores to critical path while enough cores are availables
401 while (remainingSpace >= nbCoresPerShot[criticalPathRank])
403 nbOfCoresAllocated[criticalPathRank]+=nbCoresPerShot[criticalPathRank];
404 remainingSpace-=nbCoresPerShot[criticalPathRank];
405 criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated);
407 //fill other paths with remaining cores (if possible) (reuse fromBigToTiny here?)
411 for(std::vector<int>::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,j++)
413 coresToAdd=((int)(remainingSpace/nbCoresPerShot[j]))*nbCoresPerShot[j];
415 remainingSpace-=coresToAdd;
419 for(std::vector<int>::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,k++)
421 disorderRet[k]=takePlace(*it,nbCoresPerShot[k],zeArr,k==(sz-1));
423 ret=backToOriginalOrder(disorderRet, saveOrder);
427 std::vector< std::pair <const ComplexWeight *, int> > PlayGround::bigToTiny(const std::vector< std::pair <const ComplexWeight *, int> > &weights, std::map<int,int> &saveOrder) const
429 int maxCoresPerShot(0), rankMax(0);
431 std::vector< std::pair <const ComplexWeight *, int> > ret;
432 std::size_t sz(weights.size());
433 while (ret.size()<sz)
435 for(std::vector<std::pair <const ComplexWeight *, int> >::const_iterator it=weights.begin();it!=weights.end();it++,i++)
437 if ((maxCoresPerShot<(*it).second) && (saveOrder.find(i)==saveOrder.end()))
439 maxCoresPerShot=(*it).second;
443 ret.push_back(std::pair <const ComplexWeight *, int>(weights[rankMax].first,weights[rankMax].second));
444 saveOrder[rankMax]=ret.size()-1;
451 std::vector< std::vector<int> > PlayGround::backToOriginalOrder(const std::vector< std::vector<int> > &disorderVec, const std::map<int,int> &saveOrder) const
453 std::vector< std::vector<int> > ret;
454 std::size_t sz(disorderVec.size());
455 if (disorderVec.size()!=saveOrder.size())
456 throw Exception("PlayGround::backToOriginalOrder : incoherent vector size !");
457 for (int i=0; i<sz; i++)
458 ret.push_back(disorderVec[saveOrder.at(i)]);
462 int PlayGround::getCriticalPath(const std::vector<std::pair <const ComplexWeight *, int > >& weights, const std::vector<int>& nbOfCoresAllocated) const
464 double maxWeight(0.);
465 double pathWeight(0.);
467 if ((weights.size()!=nbOfCoresAllocated.size()) || (weights.size()==0))
468 throw Exception("PlayGround::getCriticalPath : internal error !");
470 for(std::vector<std::pair <const ComplexWeight *, int> >::const_iterator it=weights.begin();it!=weights.end();it++,i++)
472 if (nbOfCoresAllocated[i]==0)
473 throw Exception("PlayGround::getCriticalPath : nbOfCoresAllocated is null! error !");
474 if (!(*it).first->isDefaultValue())
476 pathWeight=(*it).first->calculateTotalLength(nbOfCoresAllocated[i]);
477 if (pathWeight > maxWeight)
479 maxWeight=pathWeight;
487 std::vector<int> PlayGround::takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector<bool>& distributionOfCores, bool lastOne) const
489 if(maxNbOfCoresToAlloc<1)
490 throw Exception("PlayGround::takePlace : internal error ! no space to alloc !");
491 int tmpMaxNbOfCoresToAlloc(maxNbOfCoresToAlloc);
493 tmpMaxNbOfCoresToAlloc=std::max(tmpMaxNbOfCoresToAlloc,(int)std::count(distributionOfCores.begin(),distributionOfCores.end(),true));
494 std::vector<int> ret;
495 std::vector<int> offsets(computeOffsets());
497 std::size_t sz(offsets.size()-1);
498 for(std::size_t i=0;i<sz && tmpMaxNbOfCoresToAlloc>=nbCoresPerShot;i++)
500 int d(offsets[i+1]-offsets[i]);
503 std::vector<bool> target(nbCoresPerShot,true);
504 for(int j=0;j<=d-nbCoresPerShot && tmpMaxNbOfCoresToAlloc>=nbCoresPerShot;)
506 std::vector<bool> t(distributionOfCores.begin()+offsets[i]+j,distributionOfCores.begin()+offsets[i]+j+nbCoresPerShot);
510 tmpMaxNbOfCoresToAlloc-=nbCoresPerShot;
511 std::fill(distributionOfCores.begin()+offsets[i]+j,distributionOfCores.begin()+offsets[i]+j+nbCoresPerShot,false);
512 for(int k=offsets[i]+j;k<offsets[i]+j+nbCoresPerShot;k++)
522 if(nbCoresPerShot<=1)
523 throw Exception("PlayGround::takePlace : internal error !");
524 // not enough contiguous place. Find the first wider contiguous place
525 for(int kk=std::min(nbCoresPerShot-1,tmpMaxNbOfCoresToAlloc);kk>=1;kk--)
527 for(std::size_t i=0;i<sz && tmpMaxNbOfCoresToAlloc>=kk;i++)
529 int d(offsets[i+1]-offsets[i]);
532 std::vector<bool> target(kk,true);
533 for(int j=0;j<=d-kk && tmpMaxNbOfCoresToAlloc>=kk;)
535 std::vector<bool> t(distributionOfCores.begin()+offsets[i]+j,distributionOfCores.begin()+offsets[i]+j+kk);
539 tmpMaxNbOfCoresToAlloc-=kk;
540 std::fill(distributionOfCores.begin()+offsets[i]+j,distributionOfCores.begin()+offsets[i]+j+kk,false);
541 for(int k=offsets[i]+j;k<offsets[i]+j+kk;k++)
550 throw Exception("PlayGround::takePlace : internal error ! All cores are occupied !");
553 int PlayGround::fromWorkerIdToResId(int workerId, int nbProcPerNode) const
555 std::size_t sz2(_data.size());
556 std::vector<int> deltas(sz2+1); deltas[0]=0;
557 for(std::size_t i=0;i<sz2;i++)
558 deltas[i+1]=deltas[i]+(_data[i].nbCores())/nbProcPerNode;
560 while(zePos<sz2 && (workerId<deltas[zePos] || workerId>=deltas[zePos+1]))
568 * you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, and PartDefinition::computeWorkerIdsCovered
570 std::string PlayGround::deduceMachineFrom(int workerId, int nbProcPerNode) const
572 int zePos(fromWorkerIdToResId(workerId,nbProcPerNode));
573 return _data[zePos].name();
577 * you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, PlayGround::getFetchedCores and PartDefinition::computeWorkerIdsCovered
579 int PlayGround::getNumberOfWorkers(int nbCoresPerWorker) const
581 return getMaxNumberOfContainersCanBeHostedWithoutOverlap(nbCoresPerWorker);
584 PlayGround::~PlayGround()
588 //////////////////////
590 PartDefinition::PartDefinition(const PlayGround *pg)
595 PartDefinition::PartDefinition(const PartDefinition& other):_pg(other._pg)
599 PartDefinition::~PartDefinition()
603 // std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > PartDefinition::partition(const std::vector< const ComplexWeight *>& wgs) const
605 // std::size_t sz(wgs.size());
606 // std::vector< std::pair<const PartDefinition *, const ComplexWeight *> > elts(sz);
607 // for(std::size_t i=0;i<sz;i++)
608 // elts[i]=std::pair<const PartDefinition *, const ComplexWeight *>(this,wgs[i]);
609 // return getPlayGround()->partition(elts);
612 YACS::BASES::AutoRefCnt<PartDefinition> PartDefinition::BuildFrom(const PlayGround *pg, const std::vector<int>& coreIds)
614 int spaceSz(pg->getNumberOfCoresAvailable()),sz(coreIds.size());
616 throw Exception("PartDefinition::BuildFrom : error 1 !");
618 throw Exception("PartDefinition::BuildFrom : error 2 !");
619 int zeStart(coreIds.front()),zeEnd(coreIds.back());
620 if(zeStart<0 || zeEnd<zeStart)
621 throw Exception("PartDefinition::BuildFrom : error ! The content of core Ids is not OK !");
622 for(std::size_t i=0;i<sz-1;i++)
623 if(coreIds[i+1]<coreIds[i])
624 throw Exception("PartDefinition::BuildFrom : error ! The content of core Ids is not OK 2 !");
625 if(zeEnd-zeStart+1!=sz)
627 YACS::BASES::AutoRefCnt<PartDefinition> pd(new NonContigPartDefinition(pg,coreIds));
632 YACS::BASES::AutoRefCnt<PartDefinition> pd(new AllPartDefinition(pg));
635 YACS::BASES::AutoRefCnt<PartDefinition> pd(new ContigPartDefinition(pg,zeStart,zeEnd+1));
639 void PartDefinition::stashPart(int nbCoresStashed, double weightOfRemain, YACS::BASES::AutoRefCnt<PartDefinition>& pdStashed, YACS::BASES::AutoRefCnt<PartDefinition>& pdRemain) const
641 if(nbCoresStashed<=0)
642 throw Exception("stashPart : Invalid nbCoresStashed value !");
643 if(weightOfRemain<=0.)
644 throw Exception("stashPart : Invalid weight !");
645 std::vector<bool> coresOn(getCoresOn());
646 int nbCoresAvailable(std::count(coresOn.begin(),coresOn.end(),true));
647 std::vector<int> ids(PlayGround::BuildVectOfIdsFromVecBool(coresOn));
648 if(nbCoresAvailable==0)
649 throw Exception("PartDefinition::stashPart : no available cores !");
650 if(nbCoresAvailable<=nbCoresStashed)
652 int n0((int)(1./(1.+weightOfRemain)*nbCoresAvailable)); n0=std::max(n0,1);
653 int n1(nbCoresAvailable-n0);
656 pdStashed=PartDefinition::BuildFrom(getPlayGround(),ids);
657 pdRemain=PartDefinition::BuildFrom(getPlayGround(),ids);
661 std::vector<int> ids0(ids.begin(),ids.begin()+n0),ids1(ids.begin()+n0,ids.end());
662 pdStashed=PartDefinition::BuildFrom(getPlayGround(),ids0);
663 pdRemain=PartDefinition::BuildFrom(getPlayGround(),ids1);
668 std::vector<int> ids0(ids.begin(),ids.begin()+nbCoresStashed),ids1(ids.begin()+nbCoresStashed,ids.end());
669 pdStashed=PartDefinition::BuildFrom(getPlayGround(),ids0);
670 pdRemain=PartDefinition::BuildFrom(getPlayGround(),ids1);
675 * you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, and PartDefinition::computeWorkerIdsCovered
677 std::vector<std::size_t> PartDefinition::computeWorkerIdsCovered(int nbCoresPerComp) const
679 std::vector<bool> coresOn(getCoresOn());
680 return _pg->getWorkerIdsFullyFetchedBy(nbCoresPerComp,coresOn);
683 //////////////////////
685 ContigPartDefinition::ContigPartDefinition(const PlayGround *pg, int zeStart, int zeStop):PartDefinition(pg),_start(zeStart),_stop(zeStop)
687 if(_start<0 || _stop<_start || _stop>getSpaceSize())
688 throw Exception("ContigPartDefinition constructor : Invalid input values");
691 ContigPartDefinition::ContigPartDefinition(const ContigPartDefinition& other):PartDefinition(other),_start(other._start),_stop(other._stop)
695 std::string ContigPartDefinition::printSelf() const
697 std::ostringstream oss;
698 oss << "Contiguous : start=" << _start << " stop=" << _stop;
702 std::vector<bool> ContigPartDefinition::getCoresOn() const
704 std::vector<bool> ret(getSpaceSize(),false);
705 for(int i=_start;i<_stop;i++)
710 ContigPartDefinition *ContigPartDefinition::copy() const
712 return new ContigPartDefinition(*this);
715 int ContigPartDefinition::getNumberOfCoresConsumed() const
720 //////////////////////
722 NonContigPartDefinition::NonContigPartDefinition(const PlayGround *pg, const std::vector<int>& ids):PartDefinition(pg),_ids(ids)
727 NonContigPartDefinition::NonContigPartDefinition(const ContigPartDefinition& other):PartDefinition(other)
731 std::string NonContigPartDefinition::printSelf() const
733 std::ostringstream oss;
734 oss << "Non contiguous : ";
735 for(std::vector<int>::const_iterator it=_ids.begin();it!=_ids.end();it++)
740 std::vector<bool> NonContigPartDefinition::getCoresOn() const
742 std::vector<bool> ret(getSpaceSize(),false);
743 for(std::vector<int>::const_iterator it=_ids.begin();it!=_ids.end();it++)
748 NonContigPartDefinition *NonContigPartDefinition::copy() const
750 return new NonContigPartDefinition(*this);
753 int NonContigPartDefinition::getNumberOfCoresConsumed() const
758 void NonContigPartDefinition::checkOKIds() const
760 int maxVal(getSpaceSize());
763 int val(_ids.front());
764 if(val<0 || val>=maxVal)
765 throw Exception("checkOKIds : error 2 !");
766 std::size_t sz(_ids.size());
767 for(std::size_t i=0;i<sz-1;i++)
769 if(_ids[i+1]<=_ids[i])
770 throw Exception("checkOKIds : error 1 !");
771 if(_ids[i+1]>=maxVal)
772 throw Exception("checkOKIds : error 3 !");
776 //////////////////////
778 AllPartDefinition::AllPartDefinition(const AllPartDefinition& other):PartDefinition(other)
782 std::string AllPartDefinition::printSelf() const
784 std::ostringstream oss;
789 std::vector<bool> AllPartDefinition::getCoresOn() const
791 std::vector<bool> ret(getSpaceSize(),true);
795 AllPartDefinition *AllPartDefinition::copy() const
797 return new AllPartDefinition(*this);
800 int AllPartDefinition::getNumberOfCoresConsumed() const
802 return getSpaceSize();
805 //////////////////////
807 std::vector<int> ForTestOmlyHPContCls::getIDS() const
809 std::size_t sz(_ids.size());
810 std::vector<int> ret(sz);
811 for(std::size_t i=0;i<sz;i++)