HomogeneousPoolContainer::~HomogeneousPoolContainer()
{
}
+
+const PlayGround *HomogeneousPoolContainer::getPG() const
+{
+ if(_pg.isNull())
+ throw Exception("HomogeneousPoolContainer::getPG : PlayGround is nullptr !");
+ return _pg;
+}
void dettachOnCloning() const;
bool isAttachedOnCloning() const;
void setAttachOnCloningStatus(bool val) const;
- void assignPG(const PlayGround *pg);
+ virtual void assignPG(const PlayGround *pg);
//
virtual void setSizeOfPool(int sz) = 0;
virtual int getSizeOfPool() const = 0;
#ifndef SWIG
virtual ~HomogeneousPoolContainer();
#endif
+ protected:
+ const PlayGround *getPG() const;
private:
YACS::BASES::AutoConstRefCnt<PlayGround> _pg;
};
using namespace YACS::ENGINE;
+std::size_t Resource::getNumberOfFreePlace(int nbCoresPerCont) const
+{
+ std::size_t ret(0),pos(0);
+ while( pos < _occupied.size() )
+ {
+ bool isChunckFree(true);
+ int posInChunck(0);
+ for( ; ( posInChunck < nbCoresPerCont ) && ( pos < _occupied.size() ) ; ++posInChunck, ++pos)
+ if(_occupied[pos])
+ isChunckFree = false;
+ if( isChunckFree && (posInChunck == nbCoresPerCont) )
+ ret++;
+ }
+ return ret;
+}
+
+std::vector<std::size_t> Resource::allocateFor(std::size_t& nbOfPlacesToTake, int nbCoresPerCont) const
+{
+ std::vector<std::size_t> ret;
+ std::size_t pos(0),curWorkerId(0);
+ while( ( pos < _occupied.size() ) && ( nbOfPlacesToTake > 0 ) )
+ {
+ bool isChunckFree(true);
+ int posInChunck(0);
+ for( ; ( posInChunck < nbCoresPerCont ) && ( pos < _occupied.size() ) ; ++posInChunck, ++pos)
+ if(_occupied[pos])
+ isChunckFree = false;
+ if( isChunckFree && (posInChunck == nbCoresPerCont) )
+ {
+ for(int i = 0 ; i < nbCoresPerCont ; ++i)
+ _occupied[pos-nbCoresPerCont+i] = true;
+ ret.push_back(curWorkerId);
+ --nbOfPlacesToTake;
+ }
+ ++curWorkerId;
+ }
+ return ret;
+}
std::string PlayGround::printSelf() const
{
return ret;
}
+std::size_t PlayGround::getNumberOfFreePlace(int nbCoresPerCont) const
+{
+ std::size_t ret(0);
+ for(auto res : _data)
+ {
+ ret += res.getNumberOfFreePlace(nbCoresPerCont);
+ }
+ return ret;
+}
+
+std::vector<std::size_t> PlayGround::allocateFor(std::size_t nbOfPlacesToTake, int nbCoresPerCont) const
+{
+ std::vector<std::size_t> ret;
+ std::size_t nbOfPlacesToTakeCpy(nbOfPlacesToTake),offset(0);
+ for(auto res : _data)
+ {
+ std::vector<std::size_t> contIdsInRes(res.allocateFor(nbOfPlacesToTakeCpy,nbCoresPerCont));
+ std::for_each(contIdsInRes.begin(),contIdsInRes.end(),[offset](std::size_t& val) { val += offset; });
+ ret.insert(ret.end(),contIdsInRes.begin(),contIdsInRes.end());
+ offset += static_cast<std::size_t>(res.nbCores()/nbCoresPerCont);
+ }
+ if( ( nbOfPlacesToTakeCpy!=0 ) || ( ret.size()!=nbOfPlacesToTake ) )
+ throw Exception("PlayGround::allocateFor : internal error ! Promised place is not existing !");
+ return ret;
+}
+
std::vector<int> PlayGround::BuildVectOfIdsFromVecBool(const std::vector<bool>& v)
{
std::size_t sz(std::count(v.begin(),v.end(),true)),i(0);
std::pair<std::string,int> toPair() const { return {_name,_nbCores}; }
int nbCores() const { return _nbCores; }
std::string name() const { return _name; }
+ std::size_t getNumberOfFreePlace(int nbCoresPerCont) const;
+ std::vector<std::size_t> allocateFor(std::size_t& nbOfPlacesToTake, int nbCoresPerCont) const;
private:
std::string _name;
int _nbCores;
- std::vector<bool> _occupied;
+ mutable std::vector<bool> _occupied;
};
std::vector<std::size_t> getWorkerIdsFullyFetchedBy(int nbCoresPerComp, const std::vector<bool>& coreFlags) const;
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);
+ public:// critical section part
+ std::size_t getNumberOfFreePlace(int nbCoresPerCont) const;
+ std::vector<std::size_t> allocateFor(std::size_t nbOfPlacesToTake, int nbCoresPerCont) const;
private:
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;
#include "AutoLocker.hxx"
#include <algorithm>
+#include <utility>
using namespace YACS::ENGINE;
{
}
+void SalomeHPContainer::assignPG(const PlayGround *pg)
+{
+ HomogeneousPoolContainer::assignPG(pg);
+ int nbOfWorkers(getPG()->getNumberOfWorkers(this->getNumberOfCoresPerWorker()));
+ this->setSizeOfPool(nbOfWorkers);
+}
+
void SalomeHPContainer::setSizeOfPool(int sz)
{
_launchModeType.resize(sz);
std::size_t SalomeHPContainer::getNumberOfFreePlace() const
{
- return _launchModeType.getNumberOfFreePlace();
+ return getPG()->getNumberOfFreePlace(this->getNumberOfCoresPerWorker());
}
+class PairVecIterator : public std::iterator<
+ std::input_iterator_tag, // iterator_category
+ std::pair<const Task *,std::size_t>, // value_type
+ long, // difference_type
+ const std::pair<const Task *,std::size_t>*, // pointer
+ std::pair<const Task *,std::size_t> > // reference
+{
+ const std::vector< const Task *> *_v0;
+ const std::vector<std::size_t> *_v1;
+ std::size_t _num;
+public:
+ explicit PairVecIterator(const std::vector< const Task * > *v0, const std::vector<std::size_t> *v1, const std::size_t num) : _v0(v0),_v1(v1),_num(num) { }
+ PairVecIterator& operator++() { _num++; return *this; }
+ bool operator==(PairVecIterator other) const { return _num == other._num; }
+ bool operator!=(PairVecIterator other) const { return !(*this == other); }
+ reference operator*() const { return std::pair<const Task *,std::size_t>((*_v0)[_num],(*_v1)[_num]); }
+};
+
void SalomeHPContainer::allocateFor(const std::vector<const Task *>& nodes)
{
- _launchModeType.allocateFor(nodes);
+ std::vector<std::size_t> workerIdsAllocated(getPG()->allocateFor(nodes.size(),this->getNumberOfCoresPerWorker()));
+ std::vector<std::pair<const Task *,std::size_t>> nodesAndIds(PairVecIterator(&nodes,&workerIdsAllocated,0),PairVecIterator(&nodes,&workerIdsAllocated,nodes.size()));
+ _launchModeType.allocateForCrude(nodesAndIds);
}
void SalomeHPContainer::release(const Task *node)
SalomeHPContainer();
SalomeHPContainer(const SalomeHPContainer& other);
//HP specific part
+ void assignPG(const PlayGround *pg) override;
void setSizeOfPool(int sz);
int getSizeOfPool() const;
std::size_t getNumberOfFreePlace() const;
}
}
+void SalomeHPContainerVectOfHelper::allocateForCrude(const std::vector<std::pair<const Task *,std::size_t>>& nodes)
+{
+ for(auto it : nodes)
+ {
+ std::size_t workerId(it.second);
+ if(workerId>=size())
+ throw Exception("SalomeHPContainerVectOfHelper::allocateForCrude : Internal error ! WorkerId is greater or equal to size of HPCont !");
+ if(_whichOccupied[workerId])
+ throw Exception("SalomeHPContainerVectOfHelper::allocateForCrude : Mismatch between Playground info and HPContainer info !");
+ }
+ for(auto it : nodes)
+ {
+ const Task *task(it.first);
+ std::size_t workerId(it.second);
+ _currentlyWorking[task]=workerId;
+ _whichOccupied[workerId]=true;
+ }
+}
+
void SalomeHPContainerVectOfHelper::release(const Task *node)
{
if(!node)
void resize(std::size_t sz);
std::size_t getNumberOfFreePlace() const;
void allocateFor(const std::vector<const Task *>& nodes);
+ void allocateForCrude(const std::vector<std::pair<const Task *,std::size_t>>& nodes);
void release(const Task *node);
std::size_t locateTask(const Task *node) const;
const SalomeContainerMonoHelper *at(std::size_t pos) const { checkPosInVec(pos); return _launchModeType[pos]; }