1 // Copyright (C) 2006-2017 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 #ifndef __PLAYGROUND_HXX__
21 #define __PLAYGROUND_HXX__
23 #include "YACSlibEngineExport.hxx"
24 #include "RefCounter.hxx"
25 #include "AutoRefCnt.hxx"
36 class YACSLIBENGINE_EXPORT PlayGround : public RefCounter
39 PlayGround(const std::vector< std::pair<std::string,int> >& defOfRes):_data(defOfRes) { checkCoherentInfo(); }
41 std::string printSelf() const;
42 void loadFromKernelCatalog();
43 std::vector< std::pair<std::string,int> > getData() const { return _data; }
44 void setData(const std::vector< std::pair<std::string,int> >& defOfRes);
45 int getNumberOfCoresAvailable() const;
46 int getMaxNumberOfContainersCanBeHostedWithoutOverlap(int nbCoresPerCont) const;
47 std::vector<int> computeOffsets() const;
48 std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< std::pair<const PartDefinition *,double> >& parts) const;
49 int fromWorkerIdToResId(int workerId, int nbProcPerNode) const;
50 std::string deduceMachineFrom(int workerId, int nbProcPerNode) const;
51 int getNumberOfWorkers(int nbCoresPerWorker) const;
52 void highlightOnIds(const std::vector<int>& coreIds, std::vector<bool>& v) const;
53 std::vector<bool> getFetchedCores(int nbCoresPerWorker) const;
54 std::vector<std::size_t> getWorkerIdsFullyFetchedBy(int nbCoresPerComp, const std::vector<bool>& coreFlags) const;
55 static std::vector<int> BuildVectOfIdsFromVecBool(const std::vector<bool>& v);
56 static std::vector<int> GetIdsMatching(const std::vector<bool>& bigArr, const std::vector<bool>& pat);
58 std::vector< std::vector<int> > splitIntoParts(const std::vector<int>& coreIds, const std::vector<int>& nbCoresConso, const std::vector<double>& weights) const;
59 std::vector<int> takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector<bool>& distributionOfCores, bool lastOne=false) const;
61 void checkCoherentInfo() const;
65 std::vector< std::pair<std::string,int> > _data;
68 class YACSLIBENGINE_EXPORT PartDefinition : public RefCounter
71 PartDefinition(const PlayGround *pg, int nbOfCoresPerComp);
72 PartDefinition(const PartDefinition& other);
73 virtual ~PartDefinition();
75 std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< double >& wgs) const;
76 static YACS::BASES::AutoRefCnt<PartDefinition> BuildFrom(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& coreIds);
77 const PlayGround *getPlayGround() const { return _pg; }
78 int getNbCoresPerCompo() const { return _nbOfCoresPerComp; }
79 void setNbCoresPerCompo(int newNbCores) { _nbOfCoresPerComp=newNbCores; }
80 int getSpaceSize() const { return _pg->getNumberOfCoresAvailable(); }
81 void stashPart(int nbCoresStashed, double weightOfRemain, YACS::BASES::AutoRefCnt<PartDefinition>& pdStashed, YACS::BASES::AutoRefCnt<PartDefinition>& pdRemain) const;
82 std::vector<std::size_t> computeWorkerIdsCovered(int nbCoresPerComp) const;
83 virtual std::string printSelf() const = 0;
84 virtual std::vector<bool> getCoresOn() const = 0;
85 virtual PartDefinition *copy() const = 0;
86 virtual int getNumberOfCoresConsumed() const = 0;
88 YACS::BASES::AutoConstRefCnt<PlayGround> _pg;
89 int _nbOfCoresPerComp;
92 class YACSLIBENGINE_EXPORT ContigPartDefinition : public PartDefinition
95 ContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, int zeStart, int zeStop);
96 ContigPartDefinition(const ContigPartDefinition& other);
97 std::string printSelf() const;
98 std::vector<bool> getCoresOn() const;
99 int getStart() const { return _start; }
100 int getStop() const { return _stop; }
101 ContigPartDefinition *copy() const;
102 int getNumberOfCoresConsumed() const;
104 ~ContigPartDefinition() { }
110 class YACSLIBENGINE_EXPORT NonContigPartDefinition : public PartDefinition
113 NonContigPartDefinition(const PlayGround *pg, int nbOfCoresPerComp, const std::vector<int>& ids);
114 NonContigPartDefinition(const ContigPartDefinition& other);
115 std::string printSelf() const;
116 std::vector<bool> getCoresOn() const;
117 std::vector<int> getIDs() const { return _ids; }
118 NonContigPartDefinition *copy() const;
119 int getNumberOfCoresConsumed() const;
121 void checkOKIds() const;
122 ~NonContigPartDefinition() { }
124 std::vector<int> _ids;
127 class AllPartDefinition : public PartDefinition
130 AllPartDefinition(const PlayGround *pg, int nbOfCoresPerComp):PartDefinition(pg,nbOfCoresPerComp) { }
131 AllPartDefinition(const AllPartDefinition& other);
132 std::string printSelf() const;
133 std::vector<bool> getCoresOn() const;
134 AllPartDefinition *copy() const;
135 int getNumberOfCoresConsumed() const;
137 ~AllPartDefinition() { }
140 class ForTestOmlyHPContCls
145 void setContainerType(const std::string& ct) { _container_type=ct; }
146 void setPD(YACS::BASES::AutoConstRefCnt<PartDefinition> pd) { _pd=pd; }
147 void setIDS(const std::vector<std::size_t>& ids) { _ids=ids; }
149 std::string getContainerType() const { return _container_type; }
150 const PartDefinition *getPD() const { return _pd; }
151 std::vector<int> getIDS() const;
153 std::string _container_type;
154 YACS::BASES::AutoConstRefCnt<PartDefinition> _pd;
155 std::vector<std::size_t> _ids;