]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader_swig/Test/testHPDecorator.py
Salome HOME
aa15b60df74a734dcf2f036da15af3aae202801f
[modules/yacs.git] / src / yacsloader_swig / Test / testHPDecorator.py
1 # Copyright (C) 2006-2016  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 import pilot
21 import SALOMERuntime
22 import unittest
23
24 class TestHPDecortator(unittest.TestCase):
25     def test0(self):
26         """ First test coming from the big boss."""
27         SALOMERuntime.RuntimeSALOME.setRuntime()
28         r=SALOMERuntime.getSALOMERuntime()
29         pg=pilot.PlayGround()
30         pg.loadFromKernelCatalog()
31         assert(len(pg.getData())!=0)
32         p=r.createProc("p0")
33         td=p.createType("double","double")
34         tdd=p.createSequenceTc("seqdouble","seqdouble",td)
35         hp1=p.createContainer("HP1","HPSalome")
36         hp4=p.createContainer("HP4","HPSalome")
37         #
38         n0=r.createScriptNode("Salome","n0")
39         n0.setExecutionMode("remote")
40         out0_0=n0.edAddOutputPort("o1",tdd)
41         n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
42         n0.setContainer(hp4)
43         p.edAddChild(n0)
44         #
45         n1_0=r.createForEachLoop("n1_0",td)
46         p.edAddChild(n1_0)
47         p.edAddCFLink(n0,n1_0)
48         p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
49         ##
50         n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
51         n1_0.edAddChild(n1_0_sc)
52         n1_0_sc.setExecutionMode("remote")
53         n1_0_sc.setScript("""2*i1""")
54         i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
55         p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
56         n1_0_sc.setContainer(hp4)
57         ##
58         #
59         n1_1=r.createForEachLoop("n1_1",td)
60         p.edAddChild(n1_1)
61         p.edAddCFLink(n0,n1_1)
62         p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort())
63         ##
64         n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
65         n1_1.edAddChild(n1_1_sc)
66         n1_1_sc.setExecutionMode("remote")
67         n1_1_sc.setScript("""3*i1""")
68         i1_1_sc=n1_1_sc.edAddInputPort("i1",td)
69         p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc)
70         n1_1_sc.setContainer(hp1)
71         ##
72         hp1.setProperty("nb_proc_per_node","1")
73         hp4.setProperty("nb_proc_per_node","4")
74         pg.setData([("m0",8),("m1",8),("m2",8),("m3",8)]) # virtual machine with 32 cores spread over 4 nodes
75         assert(n1_0.getWeight()==1.)
76         assert(n1_1.getWeight()==1.)
77         p.fitToPlayGround(pg)########### ZE CALL
78         fyto=pilot.ForTestOmlyHPContCls()
79         assert(hp4.getSizeOfPool()==8)# 32/4
80         n1_0_sc.getContainer().forYourTestsOnly(fyto)
81         assert(fyto.getContainerType()=="HPContainerShared")
82         pd=fyto.getPD()
83         assert(isinstance(pd,pilot.ContigPartDefinition))
84         assert(pd.getStart()==0 and pd.getStop()==16)
85         assert(fyto.getIDS()==(0,1,2,3))
86         #
87         assert(hp1.getSizeOfPool()==32)# 32/1
88         fyto=pilot.ForTestOmlyHPContCls()
89         n1_1_sc.getContainer().forYourTestsOnly(fyto)
90         assert(fyto.getContainerType()=="HPContainerShared")
91         pd=fyto.getPD()
92         assert(isinstance(pd,pilot.ContigPartDefinition))
93         assert(pd.getStart()==16 and pd.getStop()==32)
94         assert(fyto.getIDS()==(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31))
95         assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4)
96         assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16)
97         #
98         fyto=pilot.ForTestOmlyHPContCls()
99         n0.getContainer().forYourTestsOnly(fyto)
100         assert(fyto.getContainerType()=="HPContainerShared")
101         pd=fyto.getPD()
102         assert(isinstance(pd,pilot.AllPartDefinition))
103         assert(list(fyto.getIDS())==range(8))
104         #############################
105         #  Change weight of ForEach #
106         #############################
107         n1_0.setWeight(2)
108         p.fitToPlayGround(pg)########### ZE CALL
109         assert(hp4.getSizeOfPool()==8)# 32/4
110         n1_0_sc.getContainer().forYourTestsOnly(fyto)
111         assert(fyto.getContainerType()=="HPContainerShared")
112         pd=fyto.getPD()
113         assert(isinstance(pd,pilot.ContigPartDefinition))
114         assert(pd.getStart()==0 and pd.getStop()==21)
115         assert(fyto.getIDS()==(0,1,2,3,4))
116         assert(hp1.getSizeOfPool()==32)# 32/1
117         fyto=pilot.ForTestOmlyHPContCls()
118         n1_1_sc.getContainer().forYourTestsOnly(fyto)
119         assert(fyto.getContainerType()=="HPContainerShared")
120         pd=fyto.getPD()
121         assert(isinstance(pd,pilot.ContigPartDefinition))
122         assert(pd.getStart()==21 and pd.getStop()==32)
123         assert(fyto.getIDS()==(21,22,23,24,25,26,27,28,29,30,31))
124         assert(n1_0.edGetNbOfBranchesPort().getPyObj()==6)
125         assert(n1_1.edGetNbOfBranchesPort().getPyObj()==11)
126         #
127         fyto=pilot.ForTestOmlyHPContCls()
128         n0.getContainer().forYourTestsOnly(fyto)
129         assert(fyto.getContainerType()=="HPContainerShared")
130         pd=fyto.getPD()
131         assert(isinstance(pd,pilot.AllPartDefinition))
132         assert(list(fyto.getIDS())==range(8))
133         pass
134
135     def test1(self):
136         """ Second test as test0 + script node in // with 2 FE"""
137         SALOMERuntime.RuntimeSALOME.setRuntime()
138         r=SALOMERuntime.getSALOMERuntime()
139         pg=pilot.PlayGround()
140         pg.loadFromKernelCatalog()
141         assert(len(pg.getData())!=0)
142         p=r.createProc("p0")
143         td=p.createType("double","double")
144         tdd=p.createSequenceTc("seqdouble","seqdouble",td)
145         hp1=p.createContainer("HP1","HPSalome")
146         hp4=p.createContainer("HP4","HPSalome")
147         #
148         n0=r.createScriptNode("Salome","n0")
149         n0.setExecutionMode("remote")
150         out0_0=n0.edAddOutputPort("o1",tdd)
151         n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
152         n0.setContainer(hp4)
153         p.edAddChild(n0)
154         #
155         n1_0=r.createForEachLoop("n1_0",td)
156         p.edAddChild(n1_0)
157         p.edAddCFLink(n0,n1_0)
158         p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
159         ##
160         n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
161         n1_0.edAddChild(n1_0_sc)
162         n1_0_sc.setExecutionMode("remote")
163         n1_0_sc.setScript("""2*i1""")
164         i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
165         p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
166         n1_0_sc.setContainer(hp4)
167         ##
168         #
169         n1_1=r.createForEachLoop("n1_1",td)
170         p.edAddChild(n1_1)
171         p.edAddCFLink(n0,n1_1)
172         p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort())
173         ##
174         n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
175         n1_1.edAddChild(n1_1_sc)
176         n1_1_sc.setExecutionMode("remote")
177         n1_1_sc.setScript("""3*i1""")
178         i1_1_sc=n1_1_sc.edAddInputPort("i1",td)
179         p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc)
180         n1_1_sc.setContainer(hp1)
181         #
182         n1_2=r.createScriptNode("Salome","n1_2")
183         p.edAddChild(n1_2)
184         n1_2.setExecutionMode("remote")
185         n1_2.setContainer(hp4)
186         n1_2.setScript("""my_container""")
187         p.edAddCFLink(n0,n1_2)
188         ##
189         hp1.setProperty("nb_proc_per_node","1")
190         hp4.setProperty("nb_proc_per_node","4")
191         pg.setData([("m0",8),("m1",8),("m2",8),("m3",8)]) # virtual machine with 32 cores spread over 4 nodes
192         assert(n1_0.getWeight()==1.)
193         assert(n1_1.getWeight()==1.)
194         p.fitToPlayGround(pg)########### ZE CALL
195         assert(hp4.getSizeOfPool()==8)# 32/4
196         fyto=pilot.ForTestOmlyHPContCls()
197         n1_0_sc.getContainer().forYourTestsOnly(fyto)
198         assert(fyto.getContainerType()=="HPContainerShared")
199         pd=fyto.getPD()
200         assert(isinstance(pd,pilot.ContigPartDefinition))
201         assert(pd.getStart()==0 and pd.getStop()==16)
202         assert(fyto.getIDS()==(0,1,2,3))
203         #
204         assert(hp1.getSizeOfPool()==32)# 32/1
205         fyto=pilot.ForTestOmlyHPContCls()
206         n1_1_sc.getContainer().forYourTestsOnly(fyto)
207         assert(fyto.getContainerType()=="HPContainerShared")
208         pd=fyto.getPD()
209         assert(isinstance(pd,pilot.ContigPartDefinition))
210         assert(pd.getStart()==16 and pd.getStop()==32)
211         assert(fyto.getIDS()==(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31))
212         assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4)
213         assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16)
214         #
215         fyto=pilot.ForTestOmlyHPContCls()
216         n0.getContainer().forYourTestsOnly(fyto)
217         assert(fyto.getContainerType()=="HPContainerShared")
218         pd=fyto.getPD()
219         assert(isinstance(pd,pilot.AllPartDefinition))
220         assert(list(fyto.getIDS())==range(8))
221         fyto=pilot.ForTestOmlyHPContCls()
222         n1_2.getContainer().forYourTestsOnly(fyto)
223         assert(fyto.getContainerType()=="HPContainerShared")
224         pd=fyto.getPD()
225         assert(isinstance(pd,pilot.AllPartDefinition))
226         assert(list(fyto.getIDS())==range(8))
227         pass
228
229     @unittest.skip("requires 2 machines in catalog")
230     def test2(self):
231         """ This test is desactivated because it requires multi nodes. To be moved at the right place to support this.
232         This test is not launched here because it requires 2 machines in catalog"""
233         m1="dsp0764200"
234         m2="dsp0764412"
235         SALOMERuntime.RuntimeSALOME.setRuntime()
236         r=SALOMERuntime.getSALOMERuntime()
237         pg=pilot.PlayGround()
238         pg.loadFromKernelCatalog()
239         assert(len(pg.getData())!=0)
240         p=r.createProc("p0")
241         td=p.createType("double","double")
242         tdd=p.createSequenceTc("seqdouble","seqdouble",td)
243         hp1=p.createContainer("HP1","HPSalome")
244         #
245         n0=r.createScriptNode("Salome","n0")
246         n0.setExecutionMode("remote")
247         out0_0=n0.edAddOutputPort("o1",tdd)
248         n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
249         n0.setContainer(hp1)
250         p.edAddChild(n0)
251         ##
252         n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
253         p.edAddChild(n1_0_sc)
254         p.edAddCFLink(n0,n1_0_sc)
255         n1_0_sc.setExecutionMode("remote")
256         n1_0_sc.setScript("""assert(my_container.getHostName()=="%s")"""%m1)
257         n1_0_sc.setContainer(hp1)
258         ##
259         n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
260         p.edAddChild(n1_1_sc)
261         p.edAddCFLink(n0,n1_1_sc)
262         n1_1_sc.setExecutionMode("remote")
263         n1_1_sc.setScript("""assert(my_container.getHostName()=="%s")"""%m2)
264         n1_1_sc.setContainer(hp1)
265         ##
266         hp1.setProperty("nb_proc_per_node","1")
267         pg.setData([(m1,8),(m2,8)])
268         p.fitToPlayGround(pg)########### ZE CALL
269         assert(hp1.getSizeOfPool()==16)# 16/1
270         fyto=pilot.ForTestOmlyHPContCls()
271         n1_0_sc.getContainer().forYourTestsOnly(fyto)
272         assert(fyto.getContainerType()=="HPContainerShared")
273         pd=fyto.getPD()
274         assert(isinstance(pd,pilot.ContigPartDefinition))
275         assert(pd.getStart()==0 and pd.getStop()==8)
276         assert(fyto.getIDS()==(0,1,2,3,4,5,6,7))
277         #
278         fyto=pilot.ForTestOmlyHPContCls()
279         n1_1_sc.getContainer().forYourTestsOnly(fyto)
280         assert(fyto.getContainerType()=="HPContainerShared")
281         pd=fyto.getPD()
282         assert(isinstance(pd,pilot.ContigPartDefinition))
283         assert(pd.getStart()==8 and pd.getStop()==16)
284         assert(fyto.getIDS()==(8,9,10,11,12,13,14,15))
285         #
286         exe=pilot.ExecutorSwig()
287         assert(p.getState()==pilot.READY)
288         exe.RunW(p,0)
289         assert(p.getState()==pilot.DONE)
290         pass
291
292     def test3(self):
293         """ First test coming from the big boss."""
294         SALOMERuntime.RuntimeSALOME.setRuntime()
295         r=SALOMERuntime.getSALOMERuntime()
296         pg=pilot.PlayGround()
297         pg.loadFromKernelCatalog()
298         assert(len(pg.getData())!=0)
299         p=r.createProc("p0")
300         td=p.createType("double","double")
301         tdd=p.createSequenceTc("seqdouble","seqdouble",td)
302         hp1=r.createContainer("HPSalome") ; hp1.setName("HP1")
303         #
304         n0=r.createScriptNode("Salome","n0")
305         n0.setExecutionMode("local")
306         out0_0=n0.edAddOutputPort("o1",tdd)
307         n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
308         p.edAddChild(n0)
309         #
310         n1_0=r.createForEachLoop("n1_0",td)
311         n2_0=r.createForEachLoop("n2_0",td)
312         p.edAddChild(n1_0)
313         p.edAddChild(n2_0)
314         p.edAddCFLink(n0,n1_0)
315         p.edAddCFLink(n1_0,n2_0)
316         p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
317         p.edAddLink(out0_0,n2_0.edGetSeqOfSamplesPort())
318         ##
319         n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
320         n1_0.edAddChild(n1_0_sc)
321         n1_0_sc.setExecutionMode("remote")
322         n1_0_sc.setScript("""2*i1""")
323         i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
324         p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
325         n1_0_sc.setContainer(hp1)
326         ##
327         n2_0_sc=r.createScriptNode("Salome","n2_0_sc")
328         n2_0.edAddChild(n2_0_sc)
329         n2_0_sc.setExecutionMode("remote")
330         n2_0_sc.setScript("""2*i1""")
331         i2_0_sc=n2_0_sc.edAddInputPort("i1",td)
332         p.edAddLink(n2_0.edGetSamplePort(),i2_0_sc)
333         n2_0_sc.setContainer(hp1)
334         ##
335         hp1.setProperty("nb_proc_per_node","1")
336         pg.setData([("localhost",3)])
337         p.fitToPlayGround(pg)########### ZE CALL
338         assert(hp1.getSizeOfPool()==3)
339         fyto=pilot.ForTestOmlyHPContCls()
340         n1_0_sc.getContainer().forYourTestsOnly(fyto)
341         assert(fyto.getContainerType()=="HPContainerShared")
342         pd=fyto.getPD()
343         assert(isinstance(pd,pilot.AllPartDefinition))
344         assert(fyto.getIDS()==(0,1,2))
345         fyto=pilot.ForTestOmlyHPContCls()
346         n2_0_sc.getContainer().forYourTestsOnly(fyto)
347         assert(fyto.getContainerType()=="HPContainerShared")
348         pd=fyto.getPD()
349         assert(isinstance(pd,pilot.AllPartDefinition))
350         assert(fyto.getIDS()==(0,1,2))
351         assert(n1_0.edGetNbOfBranchesPort().getPyObj()==3)
352         assert(n2_0.edGetNbOfBranchesPort().getPyObj()==3)
353         #
354         exe=pilot.ExecutorSwig()
355         assert(p.getState()==pilot.READY)
356         exe.RunW(p,0)
357         assert(len(set(hp1.getKernelContainerNames()))==3)
358         pass
359     
360     pass
361
362 if __name__ == '__main__':
363     unittest.main()