Salome HOME
[EDF30062] and [EDF30014] : addition of --activate-custom-overrides parameter in...
[modules/yacs.git] / src / engine_swig / PlayGround.i
1 // Copyright (C) 2006-2024  CEA, EDF
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 %include <std_vector.i>
20 %template()              std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *>;
21 %template(vecppdd)       std::vector< std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *> >;
22
23 %newobject YACS::ENGINE::PlayGround::copy;
24
25 %{
26 PyObject *convertPartDefinition(YACS::ENGINE::PartDefinition *pd)
27 {
28   if(!pd)
29     return SWIG_NewPointerObj(SWIG_as_voidptr(pd),SWIGTYPE_p_YACS__ENGINE__PartDefinition, SWIG_POINTER_OWN | 0 );
30   YACS::ENGINE::ContigPartDefinition *pd1(dynamic_cast<YACS::ENGINE::ContigPartDefinition *>(pd));
31   if(pd1)
32     return SWIG_NewPointerObj(SWIG_as_voidptr(pd1),SWIGTYPE_p_YACS__ENGINE__ContigPartDefinition, SWIG_POINTER_OWN | 0 );
33   YACS::ENGINE::NonContigPartDefinition *pd2(dynamic_cast<YACS::ENGINE::NonContigPartDefinition *>(pd));
34   if(pd2)
35     return SWIG_NewPointerObj(SWIG_as_voidptr(pd2),SWIGTYPE_p_YACS__ENGINE__NonContigPartDefinition, SWIG_POINTER_OWN | 0 );
36   YACS::ENGINE::AllPartDefinition *pd3(dynamic_cast<YACS::ENGINE::AllPartDefinition *>(pd));
37   if(pd3)
38     return SWIG_NewPointerObj(SWIG_as_voidptr(pd3),SWIGTYPE_p_YACS__ENGINE__AllPartDefinition, SWIG_POINTER_OWN | 0 );
39   return SWIG_NewPointerObj(SWIG_as_voidptr(pd),SWIGTYPE_p_YACS__ENGINE__PartDefinition, SWIG_POINTER_OWN | 0 );
40   
41 }
42 %}
43
44 %typemap(out) std::vector< YACS::BASES::AutoRefCnt<YACS::ENGINE::PartDefinition> >
45 {
46   std::size_t sz($1.size());
47   std::vector< YACS::BASES::AutoRefCnt<YACS::ENGINE::PartDefinition> >::iterator it($1.begin());
48   $result = PyList_New($1.size());
49   for (std::size_t i=0; i<sz; i++,it++)
50     PyList_SetItem($result,i,convertPartDefinition((*it).retn())); 
51 }
52
53 namespace YACS
54 {
55   namespace ENGINE
56   {
57     class PartDefinition;
58     
59     class PlayGround : public RefCounter
60     {
61     public:
62       PlayGround();
63       void loadFromKernelCatalog();
64       PlayGround(const std::vector< std::pair<std::string,int> >& defOfRes);
65       std::string printSelf() const;
66       std::vector< std::pair<std::string,int> > getData() const;
67       void setData(const std::vector< std::pair<std::string,int> >& defOfRes);
68       int getNumberOfCoresAvailable() const;
69       int getMaxNumberOfContainersCanBeHostedWithoutOverlap(int nbCoresPerCont) const;
70       std::string deduceMachineFrom(int workerId, int nbProcPerNode) const;
71       %extend
72          {
73            std::string __str__() const
74            {
75              return self->printSelf();
76            }
77
78            std::vector< YACS::BASES::AutoRefCnt<YACS::ENGINE::PartDefinition> > partition(const std::vector< std::pair< YACS::ENGINE::PartDefinition *, YACS::ENGINE::ComplexWeight *> >& parts, const std::vector<int> &nbCoresPerShot) const
79            {
80              std::size_t sz(parts.size());
81              std::vector< std::pair< const YACS::ENGINE::PartDefinition *, const YACS::ENGINE::ComplexWeight *> > partsCpp(sz);
82              for(std::size_t i=0;i<sz;i++)
83                partsCpp[i]=std::pair<const YACS::ENGINE::PartDefinition *, const YACS::ENGINE::ComplexWeight *>(parts[i].first, parts[i].second);
84              return self->partition(partsCpp, nbCoresPerShot);
85            }
86          }
87     private:
88       ~PlayGround();
89     };
90
91     class PartDefinition : public RefCounter
92     {
93     public:
94       virtual PartDefinition *copy() const;
95       virtual std::string printSelf() const;
96       virtual int getNumberOfCoresConsumed() const;
97     protected:
98       PartDefinition();
99       ~PartDefinition();
100     };
101
102     class ContigPartDefinition : public PartDefinition
103     {
104     public:
105       ContigPartDefinition(const PlayGround *pg, int zeStart, int zeStop);
106       int getStart() const;
107       int getStop() const;
108       %extend
109          {
110            std::string __str__() const
111            {
112              return self->printSelf();
113            }
114          }
115     private:
116       ~ContigPartDefinition();
117     };
118
119     class NonContigPartDefinition : public PartDefinition
120     {
121     public:
122       NonContigPartDefinition(const PlayGround *pg, const std::vector<int>& ids);
123       std::vector<int> getIDs() const;
124       %extend
125          {
126            std::string __str__() const
127            {
128              return self->printSelf();
129            }
130          }
131     private:
132       ~NonContigPartDefinition();
133     };
134
135     class AllPartDefinition : public PartDefinition
136     {
137     public:
138       AllPartDefinition(const PlayGround *pg);
139       %extend
140          {
141            std::string __str__() const
142            {
143              return self->printSelf();
144            }
145          }
146     private:
147       ~AllPartDefinition();
148     };
149
150     class PartDefinition;
151     
152     class ForTestOmlyHPContCls
153     {
154     public:
155       std::string getContainerType() const;
156       std::vector<int> getIDS() const;
157     %extend
158        {
159          PyObject *getPD() const
160          {
161            const PartDefinition *ret(self->getPD());
162            if(ret)
163              ret->incrRef();
164            return convertPartDefinition(const_cast<PartDefinition *>(ret));
165          }
166        }
167     };
168   }
169 }