1 // Copyright (C) 2006-2019 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"
26 #include "ComplexWeight.hxx"
38 class YACSLIBENGINE_EXPORT PlayGround : public RefCounter
41 PlayGround(const std::vector< std::pair<std::string,int> >& defOfRes):_data(defOfRes) { checkCoherentInfo(); }
43 std::string printSelf() const;
44 void loadFromKernelCatalog();
45 std::vector< std::pair<std::string,int> > getData() const { return _data; }
46 void setData(const std::vector< std::pair<std::string,int> >& defOfRes);
47 int getNumberOfCoresAvailable() const;
48 int getMaxNumberOfContainersCanBeHostedWithoutOverlap(int nbCoresPerCont) const;
49 std::vector<int> computeOffsets() const;
50 std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< std::pair<const PartDefinition *, const ComplexWeight *> >& parts, const std::vector<int> &nbCoresPerShot) const;
51 int fromWorkerIdToResId(int workerId, int nbProcPerNode) const;
52 std::string deduceMachineFrom(int workerId, int nbProcPerNode) const;
53 int getNumberOfWorkers(int nbCoresPerWorker) const;
54 void highlightOnIds(const std::vector<int>& coreIds, std::vector<bool>& v) const;
55 std::vector<bool> getFetchedCores(int nbCoresPerWorker) const;
56 std::vector<std::size_t> getWorkerIdsFullyFetchedBy(int nbCoresPerComp, const std::vector<bool>& coreFlags) const;
57 static std::vector<int> BuildVectOfIdsFromVecBool(const std::vector<bool>& v);
58 static std::vector<int> GetIdsMatching(const std::vector<bool>& bigArr, const std::vector<bool>& pat);
60 std::vector< std::pair <const ComplexWeight *, int> > bigToTiny(const std::vector< std::pair <const ComplexWeight *, int> > &weights, std::map<int,int> &saveOrder) const;
61 std::vector< std::vector<int> > backToOriginalOrder(const std::vector< std::vector<int> > &disorderVec, const std::map<int,int> &saveOrder) const;
62 int getCriticalPath(const std::vector<std::pair <const ComplexWeight *, int > >& weights, const std::vector<int>& maxNbOfCores) const;
63 std::vector< std::vector<int> > splitIntoParts(const std::vector<int>& coreIds, const std::vector<std::pair <const ComplexWeight *, int> >& weights) const;
64 std::vector<int> takePlace(int maxNbOfCoresToAlloc, int nbCoresPerShot, std::vector<bool>& distributionOfCores, bool lastOne=false) const;
66 void checkCoherentInfo() const;
70 std::vector< std::pair<std::string,int> > _data;
73 class YACSLIBENGINE_EXPORT PartDefinition : public RefCounter
76 PartDefinition(const PlayGround *pg);
77 PartDefinition(const PartDefinition& other);
78 virtual ~PartDefinition();
80 //std::vector< YACS::BASES::AutoRefCnt<PartDefinition> > partition(const std::vector< const ComplexWeight *>& wgs) const;
81 static YACS::BASES::AutoRefCnt<PartDefinition> BuildFrom(const PlayGround *pg, const std::vector<int>& coreIds);
82 const PlayGround *getPlayGround() const { return _pg; }
83 int getSpaceSize() const { return _pg->getNumberOfCoresAvailable(); }
84 void stashPart(int nbCoresStashed, double weightOfRemain, YACS::BASES::AutoRefCnt<PartDefinition>& pdStashed, YACS::BASES::AutoRefCnt<PartDefinition>& pdRemain) const;
85 std::vector<std::size_t> computeWorkerIdsCovered(int nbCoresPerComp) const;
86 virtual std::string printSelf() const = 0;
87 virtual std::vector<bool> getCoresOn() const = 0;
88 virtual PartDefinition *copy() const = 0;
89 virtual int getNumberOfCoresConsumed() const = 0;
91 YACS::BASES::AutoConstRefCnt<PlayGround> _pg;
94 class YACSLIBENGINE_EXPORT ContigPartDefinition : public PartDefinition
97 ContigPartDefinition(const PlayGround *pg, int zeStart, int zeStop);
98 ContigPartDefinition(const ContigPartDefinition& other);
99 std::string printSelf() const;
100 std::vector<bool> getCoresOn() const;
101 int getStart() const { return _start; }
102 int getStop() const { return _stop; }
103 ContigPartDefinition *copy() const;
104 int getNumberOfCoresConsumed() const;
106 ~ContigPartDefinition() { }
112 class YACSLIBENGINE_EXPORT NonContigPartDefinition : public PartDefinition
115 NonContigPartDefinition(const PlayGround *pg, const std::vector<int>& ids);
116 NonContigPartDefinition(const ContigPartDefinition& other);
117 std::string printSelf() const;
118 std::vector<bool> getCoresOn() const;
119 std::vector<int> getIDs() const { return _ids; }
120 NonContigPartDefinition *copy() const;
121 int getNumberOfCoresConsumed() const;
123 void checkOKIds() const;
124 ~NonContigPartDefinition() { }
126 std::vector<int> _ids;
129 class YACSLIBENGINE_EXPORT AllPartDefinition : public PartDefinition
132 AllPartDefinition(const PlayGround *pg):PartDefinition(pg) { }
133 AllPartDefinition(const AllPartDefinition& other);
134 std::string printSelf() const;
135 std::vector<bool> getCoresOn() const;
136 AllPartDefinition *copy() const;
137 int getNumberOfCoresConsumed() const;
139 ~AllPartDefinition() { }
142 class YACSLIBENGINE_EXPORT ForTestOmlyHPContCls
147 void setContainerType(const std::string& ct) { _container_type=ct; }
148 void setPD(YACS::BASES::AutoConstRefCnt<PartDefinition> pd) { _pd=pd; }
149 void setIDS(const std::vector<std::size_t>& ids) { _ids=ids; }
151 std::string getContainerType() const { return _container_type; }
152 const PartDefinition *getPD() const { return _pd; }
153 std::vector<int> getIDS() const;
155 std::string _container_type;
156 YACS::BASES::AutoConstRefCnt<PartDefinition> _pd;
157 std::vector<std::size_t> _ids;