Salome HOME
Error management in py2yacs.
[modules/yacs.git] / src / engine / PlayGround.hxx
1 // Copyright (C) 2006-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __PLAYGROUND_HXX__
21 #define __PLAYGROUND_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "RefCounter.hxx"
25 #include "AutoRefCnt.hxx"
26 #include "ComplexWeight.hxx"
27
28 #include <vector>
29 #include <string>
30 #include <map>
31
32 namespace YACS
33 {
34   namespace ENGINE
35   {
36     class PartDefinition;   
37     
38     class YACSLIBENGINE_EXPORT PlayGround : public RefCounter
39     {
40     public:
41       PlayGround(const std::vector< std::pair<std::string,int> >& defOfRes):_data(defOfRes) { checkCoherentInfo(); }
42       PlayGround() { }
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);
59     private:
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;
65     private:
66       void checkCoherentInfo() const;
67     private:
68       ~PlayGround();
69     private:
70       std::vector< std::pair<std::string,int> > _data;
71     };
72
73     class YACSLIBENGINE_EXPORT PartDefinition : public RefCounter
74     {
75     protected:
76       PartDefinition(const PlayGround *pg);
77       PartDefinition(const PartDefinition& other);
78       virtual ~PartDefinition();
79     public:
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;
90     private:
91       YACS::BASES::AutoConstRefCnt<PlayGround> _pg;
92     };
93
94     class YACSLIBENGINE_EXPORT ContigPartDefinition : public PartDefinition
95     {
96     public:
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;
105     private:
106       ~ContigPartDefinition() { }
107     private:
108       int _start;
109       int _stop;
110     };
111
112     class YACSLIBENGINE_EXPORT NonContigPartDefinition : public PartDefinition
113     {
114     public:
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;
122     private:
123       void checkOKIds() const;
124       ~NonContigPartDefinition() { }
125     private:
126       std::vector<int> _ids;
127     };
128       
129     class YACSLIBENGINE_EXPORT AllPartDefinition : public PartDefinition
130     {
131     public:
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;
138     private:
139       ~AllPartDefinition() { }
140     };
141
142     class YACSLIBENGINE_EXPORT ForTestOmlyHPContCls
143     {
144     public:
145
146 #ifndef SWIG
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; }
150 #endif
151       std::string getContainerType() const { return _container_type; }
152       const PartDefinition *getPD() const { return _pd; }
153       std::vector<int> getIDS() const;
154     private:
155       std::string _container_type;
156       YACS::BASES::AutoConstRefCnt<PartDefinition> _pd;
157       std::vector<std::size_t> _ids;
158     };
159   }
160 }
161
162 #endif