]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/PlayGround.hxx
Salome HOME
63236663a89436907f2baecf40cef9e65678c901
[modules/yacs.git] / src / engine / PlayGround.hxx
1 // Copyright (C) 2006-2017  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
27 #include <vector>
28 #include <string>
29
30 namespace YACS
31 {
32   namespace ENGINE
33   {
34     class PartDefinition;
35     
36     class YACSLIBENGINE_EXPORT PlayGround : public RefCounter
37     {
38     public:
39       PlayGround(const std::vector< std::pair<std::string,int> >& defOfRes):_data(defOfRes) { checkCoherentInfo(); }
40       PlayGround() { }
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);
57     private:
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;
60     private:
61       void checkCoherentInfo() const;
62     private:
63       ~PlayGround();
64     private:
65       std::vector< std::pair<std::string,int> > _data;
66     };
67
68     class YACSLIBENGINE_EXPORT PartDefinition : public RefCounter
69     {
70     protected:
71       PartDefinition(const PlayGround *pg, int nbOfCoresPerComp);
72       PartDefinition(const PartDefinition& other);
73       virtual ~PartDefinition();
74     public:
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;
87     private:
88       YACS::BASES::AutoConstRefCnt<PlayGround> _pg;
89       int _nbOfCoresPerComp;
90     };
91
92     class YACSLIBENGINE_EXPORT ContigPartDefinition : public PartDefinition
93     {
94     public:
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;
103     private:
104       ~ContigPartDefinition() { }
105     private:
106       int _start;
107       int _stop;
108     };
109
110     class YACSLIBENGINE_EXPORT NonContigPartDefinition : public PartDefinition
111     {
112     public:
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;
120     private:
121       void checkOKIds() const;
122       ~NonContigPartDefinition() { }
123     private:
124       std::vector<int> _ids;
125     };
126       
127     class AllPartDefinition : public PartDefinition
128     {
129     public:
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;
136     private:
137       ~AllPartDefinition() { }
138     };
139
140     class ForTestOmlyHPContCls
141     {
142     public:
143
144 #ifndef SWIG
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; }
148 #endif
149       std::string getContainerType() const { return _container_type; }
150       const PartDefinition *getPD() const { return _pd; }
151       std::vector<int> getIDS() const;
152     private:
153       std::string _container_type;
154       YACS::BASES::AutoConstRefCnt<PartDefinition> _pd;
155       std::vector<std::size_t> _ids;
156     };
157   }
158 }
159
160 #endif