Salome HOME
[EDF15946] bug with playground when nb of cores is small
[modules/yacs.git] / src / engine / ComplexWeight.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 __COMPLEXWEIGHT_HXX__
21 #define __COMPLEXWEIGHT_HXX__
22
23 #include <vector>
24
25 namespace YACS
26 {
27   namespace ENGINE
28   {
29     class ComplexWeight
30     {
31     public:
32       ComplexWeight();
33       ComplexWeight(double elementaryWeight, double loopWeight, int nbCoresByIteration);
34       ComplexWeight(const ComplexWeight& other) {_bootWeight=other._bootWeight; _loopWeight=other._loopWeight; _elementaryWeight=other._elementaryWeight;}
35       ~ComplexWeight() {};
36       std::vector<std::pair<double,int> > getLoopWeight() const {return _loopWeight;}
37       double getSimpleLoopWeight() const;
38       double getElementaryWeight() const {return _elementaryWeight;}
39       double calculateTotalLength(int nbOfCoresAllocated) const;
40       void setDefaultElementary() {setToZero(); setLoopWeight(0.,0);}
41       void setDefaultLoop() {setToZero(); setElementaryWeight(0.);}
42       bool isDefaultValue() const { return ((isDefaultValueElementary()) && (isDefaultValueLoop()));}
43       bool isUnsetLoopWeight() const {return ((*(_loopWeight.begin())).second==0);}
44       bool isUnsetElementaryWeight() const {return (_elementaryWeight==0);}
45       bool hasValidLoopWeight() const { return (((*(_loopWeight.begin())).first>0) && ((*(_loopWeight.begin())).second!=-1));}
46       bool hasValidElementaryWeight() const { return (_elementaryWeight>=0);}
47       void setLoopWeight(double loopWeight, int nbCoresByIteration);
48       void setElementaryWeight(double elementaryWeight) {_bootWeight=false; _elementaryWeight=elementaryWeight;}
49       void setToZero() {_bootWeight=true; unsetElementary(); unsetLoop(); }
50       int getNbCoresConsoLoopMax() const;
51       void max(ComplexWeight &other);
52       ComplexWeight& addWeight(const ComplexWeight *other);
53     protected:
54       bool _bootWeight;
55       // _loopWeight: vect<pair(weight,nbcorePerIteration)>, for first element of vector: nbcorePerIteration<0 -> unset, nbcorePerIteration==0 -> no loopweight (means no loop inside)
56       std::vector<std::pair<double,int> > _loopWeight; 
57       double _elementaryWeight;
58     private:
59       void unsetLoop() {_loopWeight.clear(); _loopWeight.push_back(std::pair<double,int>(-1.,-1));}
60       void unsetElementary(){_elementaryWeight=-1.;}
61       bool isDefaultValueLoop() const {return ((*(_loopWeight.begin())).second==-1);}
62       bool isDefaultValueElementary() const {return (_elementaryWeight<0);}
63     };
64   }
65 }
66
67 #endif
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82