+ int totalSpace(coreIds.size());
+ int remainingSpace(totalSpace);
+ std::vector<int> nbOfCoresAllocated(sz);
+ std::vector<int> nbCoresPerShot(sz,-1);
+ // first every other branchs take its minimal part of the cake
+ // and remove branch without valid weight
+ int i(0);
+ std::map<int,int> saveOrder;
+ const std::vector< std::pair <const ComplexWeight *, int> > sortedWeights(bigToTiny(weights, saveOrder));
+ for(std::vector<std::pair <const ComplexWeight *, int> >::const_iterator it=sortedWeights.begin();it!=sortedWeights.end();it++,i++)
+ {
+ nbCoresPerShot[i]=(*it).second;
+ if ((*it).first->isUnsetLoopWeight())
+ {
+ nbOfCoresAllocated[i]=nbCoresPerShot[i]; // branch with only elementary nodes
+ }
+ else if (!(*it).first->hasValidLoopWeight())
+ {
+ nbOfCoresAllocated[i]=std::max((int)((double)totalSpace/(double)(sz)), nbCoresPerShot[i]); // branch with undefined weight, takes his part proportionnally to the number of branchs
+ }
+ else
+ {
+ nbOfCoresAllocated[i]=nbCoresPerShot[i];
+ }
+ }
+ remainingSpace-=std::accumulate(nbOfCoresAllocated.begin(), nbOfCoresAllocated.end(), 0);
+ //get critical path (between path with loopWeight)
+ int criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated);
+ if (criticalPathRank!=-1)
+ {
+ // add cores to critical path while enough cores are availables
+ while (remainingSpace >= nbCoresPerShot[criticalPathRank])
+ {
+ nbOfCoresAllocated[criticalPathRank]+=nbCoresPerShot[criticalPathRank];
+ remainingSpace-=nbCoresPerShot[criticalPathRank];
+ criticalPathRank=getCriticalPath(sortedWeights, nbOfCoresAllocated);
+ }
+ //fill other paths with remaining cores (if possible) (reuse fromBigToTiny here?)
+ // and takePlace
+ int coresToAdd;
+ int j(0);
+ for(std::vector<int>::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,j++)
+ {
+ coresToAdd=((int)(remainingSpace/nbCoresPerShot[j]))*nbCoresPerShot[j];
+ *it+=coresToAdd;
+ remainingSpace-=coresToAdd;
+ }
+ }
+ int k(0);
+ for(std::vector<int>::iterator it=nbOfCoresAllocated.begin();it!=nbOfCoresAllocated.end();it++,k++)
+ {
+ disorderRet[k]=takePlace(*it,nbCoresPerShot[k],zeArr,k==(sz-1));
+ }
+ ret=backToOriginalOrder(disorderRet, saveOrder);
+ return ret;
+}
+
+std::vector< std::pair <const ComplexWeight *, int> > PlayGround::bigToTiny(const std::vector< std::pair <const ComplexWeight *, int> > &weights, std::map<int,int> &saveOrder) const
+{
+ int maxCoresPerShot(0), rankMax(0);
+ int i(0);
+ std::vector< std::pair <const ComplexWeight *, int> > ret;
+ std::size_t sz(weights.size());
+ while (ret.size()<sz)