Version: 9.15.0
YACS::ENGINE::PlayGround Class Reference

#include <PlayGround.hxx>

Inheritance diagram for YACS::ENGINE::PlayGround:
Collaboration diagram for YACS::ENGINE::PlayGround:

Public Member Functions

 PlayGround (const std::vector< std::pair< std::string, int > > &defOfRes)
 
 PlayGround ()
 
std::string printSelf () const
 
void loadFromKernelCatalog ()
 
std::vector< std::pair< std::string, int > > getData () const
 
void setData (const std::vector< std::pair< std::string, int > > &defOfRes)
 
int getNumberOfCoresAvailable () const
 
int getMaxNumberOfContainersCanBeHostedWithoutOverlap (int nbCoresPerCont) const
 
std::vector< int > computeOffsets () const
 
std::vector< YACS::BASES::AutoRefCnt< PartDefinition > > partition (const std::vector< std::pair< const PartDefinition *, const ComplexWeight * > > &parts, const std::vector< int > &nbCoresPerShot) const
 
int fromWorkerIdToResId (int workerId, int nbProcPerNode) const
 
std::string deduceMachineFrom (int workerId, int nbProcPerNode) const
 
int getNumberOfWorkers (int nbCoresPerWorker) const
 
void highlightOnIds (const std::vector< int > &coreIds, std::vector< bool > &v) const
 
std::vector< bool > getFetchedCores (int nbCoresPerWorker) const
 
std::vector< std::size_t > getWorkerIdsFullyFetchedBy (int nbCoresPerComp, const std::vector< bool > &coreFlags) const
 
std::size_t getNumberOfFreePlace (int nbCoresPerCont) const
 
std::vector< std::size_t > allocateFor (std::size_t nbOfPlacesToTake, int nbCoresPerCont) const
 
void release (std::size_t workerId, int nbCoresPerCont) const
 
std::mutex & getLocker () const
 
void printMe () const
 
- Public Member Functions inherited from YACS::ENGINE::RefCounter
unsigned int getRefCnt () const
 
void incrRef () const
 
bool decrRef () const
 

Static Public Member Functions

static std::vector< int > BuildVectOfIdsFromVecBool (const std::vector< bool > &v)
 
static std::vector< int > GetIdsMatching (const std::vector< bool > &bigArr, const std::vector< bool > &pat)
 

Private Member Functions

std::vector< std::pair< const ComplexWeight *, int > > bigToTiny (const std::vector< std::pair< const ComplexWeight *, int > > &weights, std::map< int, int > &saveOrder) const
 
std::vector< std::vector< int > > backToOriginalOrder (const std::vector< std::vector< int > > &disorderVec, const std::map< int, int > &saveOrder) const
 
int getCriticalPath (const std::vector< std::pair< const ComplexWeight *, int > > &weights, const std::vector< int > &maxNbOfCores) const
 
std::vector< std::vector< int > > splitIntoParts (const std::vector< int > &coreIds, const std::vector< std::pair< const ComplexWeight *, int > > &weights) const
 
std::vector< int > takePlace (int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector< bool > &distributionOfCores, bool lastOne=false) const
 
void checkCoherentInfo () const
 
 ~PlayGround ()
 

Private Attributes

std::mutex _locker
 
std::vector< Resource_data
 

Additional Inherited Members

- Static Public Attributes inherited from YACS::ENGINE::RefCounter
static unsigned int _totalCnt =0
 
- Protected Member Functions inherited from YACS::ENGINE::RefCounter
 RefCounter ()
 
 RefCounter (const RefCounter &other)
 
virtual ~RefCounter ()
 
- Protected Attributes inherited from YACS::ENGINE::RefCounter
unsigned int _cnt
 

Detailed Description

Definition at line 76 of file PlayGround.hxx.

Constructor & Destructor Documentation

◆ PlayGround() [1/2]

YACS::ENGINE::PlayGround::PlayGround ( const std::vector< std::pair< std::string, int > > &  defOfRes)
inline

Definition at line 79 of file PlayGround.hxx.

79 :_data(defOfRes.begin(),defOfRes.end()) { checkCoherentInfo(); }
void checkCoherentInfo() const
Definition: PlayGround.cxx:157
std::vector< Resource > _data
Definition: PlayGround.hxx:115

◆ PlayGround() [2/2]

YACS::ENGINE::PlayGround::PlayGround ( )
inline

Definition at line 80 of file PlayGround.hxx.

80 { }

◆ ~PlayGround()

PlayGround::~PlayGround ( )
private

Definition at line 584 of file PlayGround.cxx.

585 {
586 }

Member Function Documentation

◆ allocateFor()

std::vector< std::size_t > PlayGround::allocateFor ( std::size_t  nbOfPlacesToTake,
int  nbCoresPerCont 
) const

Definition at line 194 of file PlayGround.cxx.

195 {
196  std::vector<std::size_t> ret;
197  std::size_t nbOfPlacesToTakeCpy(nbOfPlacesToTake),offset(0);
198  for(const auto& res : _data)
199  {
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);
204  }
205  if( ( nbOfPlacesToTakeCpy!=0 ) || ( ret.size()!=nbOfPlacesToTake ) )
206  throw Exception("PlayGround::allocateFor : internal error ! Promised place is not existing !");
207  return ret;
208 }

References _data.

◆ backToOriginalOrder()

std::vector< std::vector< int > > PlayGround::backToOriginalOrder ( const std::vector< std::vector< int > > &  disorderVec,
const std::map< int, int > &  saveOrder 
) const
private

Definition at line 451 of file PlayGround.cxx.

452 {
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)]);
459  return ret;
460 }

References yacsorb.CORBAEngineTest::i.

Referenced by splitIntoParts().

◆ bigToTiny()

std::vector< std::pair< const ComplexWeight *, int > > PlayGround::bigToTiny ( const std::vector< std::pair< const ComplexWeight *, int > > &  weights,
std::map< int, int > &  saveOrder 
) const
private

Definition at line 427 of file PlayGround.cxx.

428 {
429  int maxCoresPerShot(0), rankMax(0);
430  int i(0);
431  std::vector< std::pair <const ComplexWeight *, int> > ret;
432  std::size_t sz(weights.size());
433  while (ret.size()<sz)
434  {
435  for(std::vector<std::pair <const ComplexWeight *, int> >::const_iterator it=weights.begin();it!=weights.end();it++,i++)
436  {
437  if ((maxCoresPerShot<(*it).second) && (saveOrder.find(i)==saveOrder.end()))
438  {
439  maxCoresPerShot=(*it).second;
440  rankMax=i;
441  }
442  }
443  ret.push_back(std::pair <const ComplexWeight *, int>(weights[rankMax].first,weights[rankMax].second));
444  saveOrder[rankMax]=ret.size()-1;
445  maxCoresPerShot=0;
446  i=0;
447  }
448  return ret;
449 }

References yacsorb.CORBAEngineTest::i.

Referenced by splitIntoParts().

◆ BuildVectOfIdsFromVecBool()

std::vector< int > PlayGround::BuildVectOfIdsFromVecBool ( const std::vector< bool > &  v)
static

Definition at line 234 of file PlayGround.cxx.

235 {
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());
239  while(i<sz)
240  {
241  it=std::find(it,v.end(),true);
242  ret[i++]=std::distance(v.begin(),it);
243  it++;
244  }
245  return ret;
246 }
def distance(node, new_node)
Definition: graph.py:275

References gui.graph::distance(), and yacsorb.CORBAEngineTest::i.

Referenced by partition(), and YACS::ENGINE::PartDefinition::stashPart().

◆ checkCoherentInfo()

void PlayGround::checkCoherentInfo ( ) const
private

Definition at line 157 of file PlayGround.cxx.

158 {
159  std::set<std::string> s;
160  for(auto it : _data)
161  {
162  s.insert(it.name());
163  if(it.nbCores()<0)
164  throw Exception("Presence of negative int value !");
165  }
166  if(s.size()!=_data.size())
167  throw Exception("host names entries must be different each other !");
168 }

References _data.

Referenced by setData().

◆ computeOffsets()

std::vector< int > PlayGround::computeOffsets ( ) const

Definition at line 148 of file PlayGround.cxx.

149 {
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();
154  return ret;
155 }

References _data, and yacsorb.CORBAEngineTest::i.

Referenced by takePlace().

◆ deduceMachineFrom()

std::string PlayGround::deduceMachineFrom ( int  workerId,
int  nbProcPerNode 
) const

you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, and PartDefinition::computeWorkerIdsCovered

Definition at line 570 of file PlayGround.cxx.

571 {
572  int zePos(fromWorkerIdToResId(workerId,nbProcPerNode));
573  return _data[zePos].name();
574 }
int fromWorkerIdToResId(int workerId, int nbProcPerNode) const
Definition: PlayGround.cxx:553

References _data, and fromWorkerIdToResId().

Referenced by YACS::ENGINE::SalomeContainerToolsDecorator::getParameters().

◆ fromWorkerIdToResId()

int PlayGround::fromWorkerIdToResId ( int  workerId,
int  nbProcPerNode 
) const

Definition at line 553 of file PlayGround.cxx.

554 {
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;
559  int zePos(0);
560  while(zePos<sz2 && (workerId<deltas[zePos] || workerId>=deltas[zePos+1]))
561  zePos++;
562  if(zePos==sz2)
563  zePos=workerId%sz2;
564  return zePos;
565 }

References _data, and yacsorb.CORBAEngineTest::i.

Referenced by deduceMachineFrom().

◆ getCriticalPath()

int PlayGround::getCriticalPath ( const std::vector< std::pair< const ComplexWeight *, int > > &  weights,
const std::vector< int > &  maxNbOfCores 
) const
private

Definition at line 462 of file PlayGround.cxx.

463 {
464  double maxWeight(0.);
465  double pathWeight(0.);
466  int rankMaxPath(-1);
467  if ((weights.size()!=nbOfCoresAllocated.size()) || (weights.size()==0))
468  throw Exception("PlayGround::getCriticalPath : internal error !");
469  int i=0;
470  for(std::vector<std::pair <const ComplexWeight *, int> >::const_iterator it=weights.begin();it!=weights.end();it++,i++)
471  {
472  if (nbOfCoresAllocated[i]==0)
473  throw Exception("PlayGround::getCriticalPath : nbOfCoresAllocated is null! error !");
474  if (!(*it).first->isDefaultValue())
475  {
476  pathWeight=(*it).first->calculateTotalLength(nbOfCoresAllocated[i]);
477  if (pathWeight > maxWeight)
478  {
479  maxWeight=pathWeight;
480  rankMaxPath=i;
481  }
482  }
483  }
484  return rankMaxPath;
485 }

References yacsorb.CORBAEngineTest::i.

Referenced by splitIntoParts().

◆ getData()

std::vector< std::pair<std::string,int> > YACS::ENGINE::PlayGround::getData ( ) const
inline

Definition at line 83 of file PlayGround.hxx.

83 { return std::vector< std::pair<std::string,int> >(ResourceIterator(&_data,0),ResourceIterator(&_data,_data.size())); }

◆ getFetchedCores()

std::vector<bool> YACS::ENGINE::PlayGround::getFetchedCores ( int  nbCoresPerWorker) const

◆ GetIdsMatching()

std::vector< int > PlayGround::GetIdsMatching ( const std::vector< bool > &  bigArr,
const std::vector< bool > &  pat 
)
static

Definition at line 170 of file PlayGround.cxx.

171 {
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++)
176  {
177  std::vector<bool> t(bigArr.begin()+i*szp,bigArr.begin()+(i+1)*szp);
178  if(t==pat)
179  ret.push_back(i);
180  }
181  return ret;
182 }

References yacsorb.CORBAEngineTest::i, and gui.Appli::t.

Referenced by partition().

◆ getLocker()

std::mutex& YACS::ENGINE::PlayGround::getLocker ( ) const
inline

Definition at line 101 of file PlayGround.hxx.

101 { return _locker; }

◆ getMaxNumberOfContainersCanBeHostedWithoutOverlap()

int PlayGround::getMaxNumberOfContainersCanBeHostedWithoutOverlap ( int  nbCoresPerCont) const

Definition at line 138 of file PlayGround.cxx.

139 {
140  if(nbCoresPerCont<1)
141  throw Exception("PlayGround::getMaxNumberOfContainersCanBeHostedWithoutOverlap : invalid nbCoresPerCont. Must be >=1 !");
142  int ret(0);
143  for(auto it : _data)
144  ret+=it.nbCores()/nbCoresPerCont;
145  return ret;
146 }

References _data.

Referenced by getNumberOfWorkers().

◆ getNumberOfCoresAvailable()

int PlayGround::getNumberOfCoresAvailable ( ) const

Definition at line 130 of file PlayGround.cxx.

131 {
132  int ret(0);
133  for(auto it : _data)
134  ret+=it.nbCores();
135  return ret;
136 }

References _data.

Referenced by YACS::ENGINE::PartDefinition::BuildFrom(), YACS::ENGINE::Bloc::fitToPlayGround(), highlightOnIds(), partition(), and splitIntoParts().

◆ getNumberOfFreePlace()

std::size_t PlayGround::getNumberOfFreePlace ( int  nbCoresPerCont) const

Definition at line 184 of file PlayGround.cxx.

185 {
186  std::size_t ret(0);
187  for(auto res : _data)
188  {
189  ret += res.getNumberOfFreePlace(nbCoresPerCont);
190  }
191  return ret;
192 }

References _data.

Referenced by YACS::ENGINE::SalomeHPContainer::getNumberOfFreePlace().

◆ getNumberOfWorkers()

int PlayGround::getNumberOfWorkers ( int  nbCoresPerWorker) const

◆ getWorkerIdsFullyFetchedBy()

std::vector< std::size_t > PlayGround::getWorkerIdsFullyFetchedBy ( int  nbCoresPerComp,
const std::vector< bool > &  coreFlags 
) const

you must garantee coherence between PlayGround::deduceMachineFrom, PlayGround::getNumberOfWorkers, and PartDefinition::computeWorkerIdsCovered

follow getMaxNumberOfContainersCanBeHostedWithoutOverlap method

Definition at line 280 of file PlayGround.cxx.

281 {
282  std::size_t posBg(0),posWorker(0);
283  std::vector<std::size_t> ret;
284  for(auto it : _data)
285  {
286  int nbWorker(it.nbCores()/nbCoresPerComp);
287  for(int j=0;j<nbWorker;j++,posWorker++)
288  {
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);
292  }
293  posBg+=it.nbCores();
294  }
295  return ret;
296 }

References _data.

◆ highlightOnIds()

void PlayGround::highlightOnIds ( const std::vector< int > &  coreIds,
std::vector< bool > &  v 
) const

Definition at line 248 of file PlayGround.cxx.

249 {
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++)
253  v[*it]=true;
254 }
int getNumberOfCoresAvailable() const
Definition: PlayGround.cxx:130

References getNumberOfCoresAvailable().

Referenced by splitIntoParts().

◆ loadFromKernelCatalog()

void PlayGround::loadFromKernelCatalog ( )

Definition at line 115 of file PlayGround.cxx.

116 {
117  Runtime *r(getRuntime());
118  if(!r)
119  throw Exception("PlayGround::loadFromKernelCatalog : no runtime !");
120  std::vector< std::pair<std::string,int> > data(r->getCatalogOfComputeNodes());
121  setData(data);
122 }
void setData(const std::vector< std::pair< std::string, int > > &defOfRes)
Definition: PlayGround.cxx:124
YACSLIBENGINE_EXPORT Runtime * getRuntime()
Definition: Runtime.cxx:61

References YACS::ENGINE::getRuntime(), testCppPluginInvokation::r, and setData().

◆ partition()

std::vector< YACS::BASES::AutoRefCnt< PartDefinition > > PlayGround::partition ( const std::vector< std::pair< const PartDefinition *, const ComplexWeight * > > &  parts,
const std::vector< int > &  nbCoresPerShot 
) const

Definition at line 298 of file PlayGround.cxx.

299 {
300  std::size_t sz(parts.size()),szs(getNumberOfCoresAvailable());
301  if (sz!=nbCoresPerShot.size())
302  throw Exception("PlayGround::partition : incoherent vector size !");
303  if(sz==0)
304  return std::vector< YACS::BASES::AutoRefCnt<PartDefinition> >();
305  if(sz==1)
306  {
307  const PartDefinition *pd(parts[0].first);
308  if(!pd)
309  throw Exception("Presence of null pointer as part def 0 !");
311  std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > ret2(1,ret);
312  return ret2;
313  }
314  if(sz>31)
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);
317  std::size_t i(0);
318  for(std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >::const_iterator it=parts.begin();it!=parts.end();it++,i++)
319  {
320  const PartDefinition *pd((*it).first);
321  if(!pd)
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]
328  }
329  std::vector< std::vector<int> > retIds(sz);
330  for(std::size_t i=0;i<szs;i++)
331  {
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
335  if(partsIds.empty())
336  continue;
337  std::vector<std::pair <const ComplexWeight *, int> > wg;
338  for(std::vector<int>::const_iterator it=partsIds.begin();it!=partsIds.end();it++)
339  {
340  wg.push_back(std::pair <const ComplexWeight *, int> (parts[*it].second, nbCoresPerShot[*it]));
341  }
342  std::vector< std::vector<int> > ress(splitIntoParts(locIds,wg));
343  std::size_t k(0);
344  for(std::vector<int>::const_iterator it=partsIds.begin();it!=partsIds.end();it++,k++)
345  {
346  retIds[*it].insert(retIds[*it].end(),ress[k].begin(),ress[k].end());
347  }
348  }
349  //
350  std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > ret(sz);
351  for(std::size_t i=0;i<sz;i++)
352  {
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);
356  }
357  return ret;
358 }
static YACS::BASES::AutoRefCnt< PartDefinition > BuildFrom(const PlayGround *pg, const std::vector< int > &coreIds)
Definition: PlayGround.cxx:612
static std::vector< int > GetIdsMatching(const std::vector< bool > &bigArr, const std::vector< bool > &pat)
Definition: PlayGround.cxx:170
static std::vector< int > BuildVectOfIdsFromVecBool(const std::vector< bool > &v)
Definition: PlayGround.cxx:234
std::vector< std::vector< int > > splitIntoParts(const std::vector< int > &coreIds, const std::vector< std::pair< const ComplexWeight *, int > > &weights) const
Definition: PlayGround.cxx:360

References YACS::ENGINE::PartDefinition::BuildFrom(), BuildVectOfIdsFromVecBool(), YACS::ENGINE::PartDefinition::copy(), YACS::ENGINE::PartDefinition::getCoresOn(), GetIdsMatching(), getNumberOfCoresAvailable(), YACS::ENGINE::PartDefinition::getPlayGround(), yacsorb.CORBAEngineTest::i, and splitIntoParts().

Referenced by YACS::ENGINE::ForkBlocPoint::partitionRegardingDPL().

◆ printMe()

void PlayGround::printMe ( ) const

Definition at line 225 of file PlayGround.cxx.

226 {
227  for(auto it : _data)
228  {
229  it.printSelf(std::cout);
230  std::cout << std::endl;
231  }
232 }

References _data.

◆ printSelf()

std::string PlayGround::printSelf ( ) const

Definition at line 102 of file PlayGround.cxx.

103 {
104  std::ostringstream oss;
105  std::size_t sz(0);
106  for(auto it : _data)
107  sz=std::max(sz,it.name().length());
108  for(auto it : _data)
109  {
110  oss << " - " << std::setw(10) << it.name() << " : " << it.nbCores() << std::endl;
111  }
112  return oss.str();
113 }

References _data.

◆ release()

void PlayGround::release ( std::size_t  workerId,
int  nbCoresPerCont 
) const

Definition at line 210 of file PlayGround.cxx.

211 {
212  std::size_t offset(0);
213  for(const auto& res : _data)
214  {
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)
218  {
219  res.release(workerId-minId,nbCoresPerCont);
220  break;
221  }
222  }
223 }

References _data.

Referenced by YACS::ENGINE::SalomeHPContainer::release().

◆ setData()

void PlayGround::setData ( const std::vector< std::pair< std::string, int > > &  defOfRes)

Definition at line 124 of file PlayGround.cxx.

125 {
126  _data=std::vector<Resource>(defOfRes.begin(),defOfRes.end());
128 }

References _data, and checkCoherentInfo().

Referenced by loadFromKernelCatalog().

◆ splitIntoParts()

std::vector< std::vector< int > > PlayGround::splitIntoParts ( const std::vector< int > &  coreIds,
const std::vector< std::pair< const ComplexWeight *, int > > &  weights 
) const
private

Definition at line 360 of file PlayGround.cxx.

361 {
362  std::size_t sz(weights.size());
363  if(sz==0)
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
376  int i(0);
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++)
380  {
381  nbCoresPerShot[i]=(*it).second;
382  if ((*it).first->isUnsetLoopWeight())
383  {
384  nbOfCoresAllocated[i]=nbCoresPerShot[i]; // branch with only elementary nodes
385  }
386  else if (!(*it).first->hasValidLoopWeight())
387  {
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
389  }
390  else
391  {
392  nbOfCoresAllocated[i]=nbCoresPerShot[i];
393  }
394  }
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)
399  {
400  // add cores to critical path while enough cores are availables
401  while (remainingSpace >= nbCoresPerShot[criticalPathRank])
402  {
403  nbOfCoresAllocated[criticalPathRank]+=nbCoresPerShot[criticalPathRank];
404  remainingSpace-=nbCoresPerShot[criticalPathRank];
405  criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated);
406  }
407  //fill other paths with remaining cores (if possible) (reuse fromBigToTiny here?)
408  // and takePlace
409  int coresToAdd;
410  int j(0);
411  for(std::vector<int>::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,j++)
412  {
413  coresToAdd=((int)(remainingSpace/nbCoresPerShot[j]))*nbCoresPerShot[j];
414  *it+=coresToAdd;
415  remainingSpace-=coresToAdd;
416  }
417  }
418  int k(0);
419  for(std::vector<int>::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,k++)
420  {
421  disorderRet[k]=takePlace(*it,nbCoresPerShot[k],zeArr,k==(sz-1));
422  }
423  ret=backToOriginalOrder(disorderRet, saveOrder);
424  return ret;
425 }
int getCriticalPath(const std::vector< std::pair< const ComplexWeight *, int > > &weights, const std::vector< int > &maxNbOfCores) const
Definition: PlayGround.cxx:462
std::vector< std::pair< const ComplexWeight *, int > > bigToTiny(const std::vector< std::pair< const ComplexWeight *, int > > &weights, std::map< int, int > &saveOrder) const
Definition: PlayGround.cxx:427
void highlightOnIds(const std::vector< int > &coreIds, std::vector< bool > &v) const
Definition: PlayGround.cxx:248
std::vector< int > takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector< bool > &distributionOfCores, bool lastOne=false) const
Definition: PlayGround.cxx:487
std::vector< std::vector< int > > backToOriginalOrder(const std::vector< std::vector< int > > &disorderVec, const std::map< int, int > &saveOrder) const
Definition: PlayGround.cxx:451

References backToOriginalOrder(), bigToTiny(), getCriticalPath(), getNumberOfCoresAvailable(), highlightOnIds(), yacsorb.CORBAEngineTest::i, and takePlace().

Referenced by partition().

◆ takePlace()

std::vector< int > PlayGround::takePlace ( int  maxNbOfCoresToAlloc,
int  nbCoresPerShot,
std::vector< bool > &  distributionOfCores,
bool  lastOne = false 
) const
private

Definition at line 487 of file PlayGround.cxx.

488 {
489  if(maxNbOfCoresToAlloc<1)
490  throw Exception("PlayGround::takePlace : internal error ! no space to alloc !");
491  int tmpMaxNbOfCoresToAlloc(maxNbOfCoresToAlloc);
492  if(lastOne)
493  tmpMaxNbOfCoresToAlloc=std::max(tmpMaxNbOfCoresToAlloc,(int)std::count(distributionOfCores.begin(),distributionOfCores.end(),true));
494  std::vector<int> ret;
495  std::vector<int> offsets(computeOffsets());
496  int nbFullItem(0);
497  std::size_t sz(offsets.size()-1);
498  for(std::size_t i=0;i<sz && tmpMaxNbOfCoresToAlloc>=nbCoresPerShot;i++)
499  {
500  int d(offsets[i+1]-offsets[i]);
501  if(nbCoresPerShot>d)
502  continue;
503  std::vector<bool> target(nbCoresPerShot,true);
504  for(int j=0;j<=d-nbCoresPerShot && tmpMaxNbOfCoresToAlloc>=nbCoresPerShot;)
505  {
506  std::vector<bool> t(distributionOfCores.begin()+offsets[i]+j,distributionOfCores.begin()+offsets[i]+j+nbCoresPerShot);
507  if(t==target)
508  {
509  nbFullItem++;
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++)
513  ret.push_back(k);
514  j+=nbCoresPerShot;
515  }
516  else
517  j++;
518  }
519  }
520  if(nbFullItem>0)
521  return ret;
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--)
526  {
527  for(std::size_t i=0;i<sz && tmpMaxNbOfCoresToAlloc>=kk;i++)
528  {
529  int d(offsets[i+1]-offsets[i]);
530  if(kk>d)
531  continue;
532  std::vector<bool> target(kk,true);
533  for(int j=0;j<=d-kk && tmpMaxNbOfCoresToAlloc>=kk;)
534  {
535  std::vector<bool> t(distributionOfCores.begin()+offsets[i]+j,distributionOfCores.begin()+offsets[i]+j+kk);
536  if(t==target)
537  {
538  nbFullItem++;
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++)
542  ret.push_back(k);
543  return ret;
544  }
545  else
546  j++;
547  }
548  }
549  }
550  throw Exception("PlayGround::takePlace : internal error ! All cores are occupied !");
551 }
std::vector< int > computeOffsets() const
Definition: PlayGround.cxx:148

References computeOffsets(), yacsorb.CORBAEngineTest::i, and gui.Appli::t.

Referenced by splitIntoParts().

Member Data Documentation

◆ _data

◆ _locker

std::mutex YACS::ENGINE::PlayGround::_locker
mutableprivate

Definition at line 114 of file PlayGround.hxx.


The documentation for this class was generated from the following files: