1 # Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 class TestHPDecortator(unittest.TestCase):
26 """ First test coming from the big boss."""
27 SALOMERuntime.RuntimeSALOME.setRuntime()
28 r=SALOMERuntime.getSALOMERuntime()
30 pg.loadFromKernelCatalog()
31 assert(len(pg.getData())!=0)
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")
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)]""")
45 n1_0=r.createForEachLoop("n1_0",td)
47 p.edAddCFLink(n0,n1_0)
48 p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
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)
59 n1_1=r.createForEachLoop("n1_1",td)
61 p.edAddCFLink(n0,n1_1)
62 p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort())
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""")
69 i1_1_sc=n1_1_sc.edAddInputPort("i1",td)
70 p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc)
71 n1_1_sc.setContainer(hp1)
73 hp1.setProperty("nb_proc_per_node","1")
74 hp4.setProperty("nb_proc_per_node","4")
75 pg.setData([("m0",8),("m1",8),("m2",8),("m3",8)]) # virtual machine with 32 cores spread over 4 nodes
76 assert(n1_0.getWeight().getSimpleLoopWeight()==-1.)
77 assert(n1_1.getWeight().getSimpleLoopWeight()==4.)
78 p.fitToPlayGround(pg)########### ZE CALL
79 fyto=pilot.ForTestOmlyHPContCls()
80 assert(hp4.getSizeOfPool()==8)# 32/4
81 n1_0_sc.getContainer().forYourTestsOnly(fyto)
82 assert(fyto.getContainerType()=="HPContainerShared")
84 assert(isinstance(pd,pilot.ContigPartDefinition))
85 assert(pd.getStart()==0 and pd.getStop()==16)
86 assert(fyto.getIDS()==(0,1,2,3))
88 assert(hp1.getSizeOfPool()==32)# 32/1
89 fyto=pilot.ForTestOmlyHPContCls()
90 n1_1_sc.getContainer().forYourTestsOnly(fyto)
91 assert(fyto.getContainerType()=="HPContainerShared")
93 assert(isinstance(pd,pilot.ContigPartDefinition))
94 assert(pd.getStart()==16 and pd.getStop()==32)
95 assert(fyto.getIDS()==(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31))
96 assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4)
97 assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16)
99 fyto=pilot.ForTestOmlyHPContCls()
100 n0.getContainer().forYourTestsOnly(fyto)
101 assert(fyto.getContainerType()=="HPContainerShared")
103 assert(isinstance(pd,pilot.AllPartDefinition))
104 assert(list(fyto.getIDS())==list(range(8)))
105 #############################
106 # Change weight of ForEach #
107 #############################
109 p.fitToPlayGround(pg)########### ZE CALL
110 assert(hp4.getSizeOfPool()==8)# 32/4
111 n1_0_sc.getContainer().forYourTestsOnly(fyto)
112 assert(fyto.getContainerType()=="HPContainerShared")
114 assert(isinstance(pd,pilot.ContigPartDefinition))
115 assert(pd.getStart()==0 and pd.getStop()==16)
116 assert(fyto.getIDS()==(0,1,2,3))
117 assert(hp1.getSizeOfPool()==32)# 32/1
118 fyto=pilot.ForTestOmlyHPContCls()
119 n1_1_sc.getContainer().forYourTestsOnly(fyto)
120 assert(fyto.getContainerType()=="HPContainerShared")
122 assert(isinstance(pd,pilot.ContigPartDefinition))
123 assert(pd.getStart()==16 and pd.getStop()==32)
124 assert(fyto.getIDS()==(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31))
125 assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4)
126 assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16)
128 fyto=pilot.ForTestOmlyHPContCls()
129 n0.getContainer().forYourTestsOnly(fyto)
130 assert(fyto.getContainerType()=="HPContainerShared")
132 assert(isinstance(pd,pilot.AllPartDefinition))
133 assert(list(fyto.getIDS())==list(range(8)))
137 """ Second test as test0 + script node in // with 2 FE"""
138 SALOMERuntime.RuntimeSALOME.setRuntime()
139 r=SALOMERuntime.getSALOMERuntime()
140 pg=pilot.PlayGround()
141 pg.loadFromKernelCatalog()
142 assert(len(pg.getData())!=0)
144 td=p.createType("double","double")
145 tdd=p.createSequenceTc("seqdouble","seqdouble",td)
146 hp1=p.createContainer("HP1","HPSalome")
147 hp4=p.createContainer("HP4","HPSalome")
149 n0=r.createScriptNode("Salome","n0")
150 n0.setExecutionMode("remote")
151 out0_0=n0.edAddOutputPort("o1",tdd)
152 n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
156 n1_0=r.createForEachLoop("n1_0",td)
158 p.edAddCFLink(n0,n1_0)
159 p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
162 n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
163 n1_0.edAddChild(n1_0_sc)
164 n1_0_sc.setExecutionMode("remote")
165 n1_0_sc.setScript("""2*i1""")
166 i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
167 p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
168 n1_0_sc.setContainer(hp4)
171 n1_1=r.createForEachLoop("n1_1",td)
173 p.edAddCFLink(n0,n1_1)
174 p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort())
177 n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
178 n1_1.edAddChild(n1_1_sc)
179 n1_1_sc.setExecutionMode("remote")
180 n1_1_sc.setScript("""3*i1""")
181 i1_1_sc=n1_1_sc.edAddInputPort("i1",td)
182 p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc)
183 n1_1_sc.setContainer(hp1)
185 n1_2=r.createScriptNode("Salome","n1_2")
187 n1_2.setExecutionMode("remote")
188 n1_2.setContainer(hp4)
189 n1_2.setScript("""my_container""")
190 p.edAddCFLink(n0,n1_2)
192 hp1.setProperty("nb_proc_per_node","1")
193 hp4.setProperty("nb_proc_per_node","4")
194 pg.setData([("m0",8),("m1",8),("m2",8),("m3",8),("m4",4)]) # virtual machine with 32 cores spread over 4 nodes
195 assert(n1_0.getWeight().getSimpleLoopWeight()==1.)
196 assert(n1_1.getWeight().getSimpleLoopWeight()==4.)
197 p.fitToPlayGround(pg)########### ZE CALL
198 assert(hp4.getSizeOfPool()==9)# 36/4
199 fyto=pilot.ForTestOmlyHPContCls()
200 n1_0_sc.getContainer().forYourTestsOnly(fyto)
201 assert(fyto.getContainerType()=="HPContainerShared")
203 assert(isinstance(pd,pilot.ContigPartDefinition))
204 assert(pd.getStart()==0 and pd.getStop()==16)
205 assert(fyto.getIDS()==(0,1,2,3))
207 assert(hp1.getSizeOfPool()==36)# 36/1
208 fyto=pilot.ForTestOmlyHPContCls()
209 n1_1_sc.getContainer().forYourTestsOnly(fyto)
210 assert(fyto.getContainerType()=="HPContainerShared")
212 assert(isinstance(pd,pilot.ContigPartDefinition))
213 assert(pd.getStart()==20 and pd.getStop()==36)
214 assert(fyto.getIDS()==(20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35))
215 assert(n1_0.edGetNbOfBranchesPort().getPyObj()==4)
216 assert(n1_1.edGetNbOfBranchesPort().getPyObj()==16)
218 fyto=pilot.ForTestOmlyHPContCls()
219 n0.getContainer().forYourTestsOnly(fyto)
220 assert(fyto.getContainerType()=="HPContainerShared")
222 assert(isinstance(pd,pilot.AllPartDefinition))
223 assert(list(fyto.getIDS())==list(range(9)))
224 fyto=pilot.ForTestOmlyHPContCls()
225 n1_2.getContainer().forYourTestsOnly(fyto)
226 assert(fyto.getContainerType()=="HPContainerShared")
228 assert(isinstance(pd,pilot.ContigPartDefinition))
229 assert(list(fyto.getIDS())==[4])
232 @unittest.skip("requires 2 machines in catalog")
234 """ This test is desactivated because it requires multi nodes. To be moved at the right place to support this.
235 This test is not launched here because it requires 2 machines in catalog"""
238 SALOMERuntime.RuntimeSALOME.setRuntime()
239 r=SALOMERuntime.getSALOMERuntime()
240 pg=pilot.PlayGround()
241 pg.loadFromKernelCatalog()
242 assert(len(pg.getData())!=0)
244 td=p.createType("double","double")
245 tdd=p.createSequenceTc("seqdouble","seqdouble",td)
246 hp1=p.createContainer("HP1","HPSalome")
248 n0=r.createScriptNode("Salome","n0")
249 n0.setExecutionMode("remote")
250 out0_0=n0.edAddOutputPort("o1",tdd)
251 n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
255 n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
256 p.edAddChild(n1_0_sc)
257 p.edAddCFLink(n0,n1_0_sc)
258 n1_0_sc.setExecutionMode("remote")
259 n1_0_sc.setScript("""assert(my_container.getHostName()=="%s")"""%m1)
260 n1_0_sc.setContainer(hp1)
262 n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
263 p.edAddChild(n1_1_sc)
264 p.edAddCFLink(n0,n1_1_sc)
265 n1_1_sc.setExecutionMode("remote")
266 n1_1_sc.setScript("""assert(my_container.getHostName()=="%s")"""%m2)
267 n1_1_sc.setContainer(hp1)
269 hp1.setProperty("nb_proc_per_node","1")
270 pg.setData([(m1,8),(m2,8)])
271 p.fitToPlayGround(pg)########### ZE CALL
272 assert(hp1.getSizeOfPool()==16)# 16/1
273 fyto=pilot.ForTestOmlyHPContCls()
274 n1_0_sc.getContainer().forYourTestsOnly(fyto)
275 assert(fyto.getContainerType()=="HPContainerShared")
277 assert(isinstance(pd,pilot.ContigPartDefinition))
278 assert(pd.getStart()==0 and pd.getStop()==8)
279 assert(fyto.getIDS()==(0,1,2,3,4,5,6,7))
281 fyto=pilot.ForTestOmlyHPContCls()
282 n1_1_sc.getContainer().forYourTestsOnly(fyto)
283 assert(fyto.getContainerType()=="HPContainerShared")
285 assert(isinstance(pd,pilot.ContigPartDefinition))
286 assert(pd.getStart()==8 and pd.getStop()==16)
287 assert(fyto.getIDS()==(8,9,10,11,12,13,14,15))
289 exe=pilot.ExecutorSwig()
290 assert(p.getState()==pilot.READY)
292 assert(p.getState()==pilot.DONE)
296 """ First test coming from the big boss."""
297 SALOMERuntime.RuntimeSALOME.setRuntime()
298 r=SALOMERuntime.getSALOMERuntime()
299 pg=pilot.PlayGround()
300 pg.loadFromKernelCatalog()
301 assert(len(pg.getData())!=0)
303 td=p.createType("double","double")
304 tdd=p.createSequenceTc("seqdouble","seqdouble",td)
305 hp1=r.createContainer("HPSalome") ; hp1.setName("HP1")
307 n0=r.createScriptNode("Salome","n0")
308 n0.setExecutionMode("local")
309 out0_0=n0.edAddOutputPort("o1",tdd)
310 n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
313 n1_0=r.createForEachLoop("n1_0",td)
314 n2_0=r.createForEachLoop("n2_0",td)
317 p.edAddCFLink(n0,n1_0)
318 p.edAddCFLink(n1_0,n2_0)
319 p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
320 p.edAddLink(out0_0,n2_0.edGetSeqOfSamplesPort())
322 n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
323 n1_0.edAddChild(n1_0_sc)
324 n1_0_sc.setExecutionMode("remote")
325 n1_0_sc.setScript("""2*i1""")
326 i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
327 p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
328 n1_0_sc.setContainer(hp1)
330 n2_0_sc=r.createScriptNode("Salome","n2_0_sc")
331 n2_0.edAddChild(n2_0_sc)
332 n2_0_sc.setExecutionMode("remote")
333 n2_0_sc.setScript("""2*i1""")
334 i2_0_sc=n2_0_sc.edAddInputPort("i1",td)
335 p.edAddLink(n2_0.edGetSamplePort(),i2_0_sc)
336 n2_0_sc.setContainer(hp1)
338 hp1.setProperty("nb_proc_per_node","1")
339 pg.setData([("localhost",3)])
340 p.fitToPlayGround(pg)########### ZE CALL
341 assert(hp1.getSizeOfPool()==3)
342 fyto=pilot.ForTestOmlyHPContCls()
343 n1_0_sc.getContainer().forYourTestsOnly(fyto)
344 assert(fyto.getContainerType()=="HPContainerShared")
346 assert(isinstance(pd,pilot.AllPartDefinition))
347 assert(fyto.getIDS()==(0,1,2))
348 fyto=pilot.ForTestOmlyHPContCls()
349 n2_0_sc.getContainer().forYourTestsOnly(fyto)
350 assert(fyto.getContainerType()=="HPContainerShared")
352 assert(isinstance(pd,pilot.AllPartDefinition))
353 assert(fyto.getIDS()==(0,1,2))
354 assert(n1_0.edGetNbOfBranchesPort().getPyObj()==3)
355 assert(n2_0.edGetNbOfBranchesPort().getPyObj()==3)
357 exe=pilot.ExecutorSwig()
358 assert(p.getState()==pilot.READY)
360 assert(len(set(hp1.getKernelContainerNames()))==3)
364 """ two branch whose on with one elementary node and on foreach"""
365 SALOMERuntime.RuntimeSALOME.setRuntime()
366 r=SALOMERuntime.getSALOMERuntime()
367 pg=pilot.PlayGround()
368 pg.loadFromKernelCatalog()
369 assert(len(pg.getData())!=0)
371 td=p.createType("double","double")
372 tdd=p.createSequenceTc("seqdouble","seqdouble",td)
373 hp1=p.createContainer("HP1","HPSalome")
376 n0=r.createScriptNode("Salome","n0")
377 n0.setExecutionMode("remote")
378 out0_0=n0.edAddOutputPort("o1",tdd)
379 n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
383 b0 = r.createBloc("Bloc0")
387 n1_0=r.createForEachLoop("n1_0",td)
389 p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
392 n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
393 n1_0.edAddChild(n1_0_sc)
394 n1_0_sc.setExecutionMode("remote")
395 n1_0_sc.setScript("""2*i1""")
396 i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
397 p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
398 n1_0_sc.setContainer(hp1)
400 n1_0_1=r.createScriptNode("Salome","n1_0_1")
401 n1_0_1.setExecutionMode("remote")
402 n1_0_1.setScript("""a=2""")
403 b0.edAddChild(n1_0_1)
404 p.edAddCFLink(n1_0,n1_0_1)
405 n1_0_1.setContainer(hp1)
406 n1_0_1.setWeight(20.)
409 n1_1=r.createForEachLoop("n1_1",td)
411 p.edAddCFLink(n0,n1_1)
412 p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort())
415 n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
416 n1_1.edAddChild(n1_1_sc)
417 n1_1_sc.setExecutionMode("remote")
418 n1_1_sc.setScript("""3*i1""")
419 i1_1_sc=n1_1_sc.edAddInputPort("i1",td)
420 p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc)
421 n1_1_sc.setContainer(hp1)
423 hp1.setProperty("nb_proc_per_node","1")
424 pg.setData([("m0",12)])
425 w=pilot.ComplexWeight()
426 b0.getWeightRegardingDPL(w)
427 assert(w.getElementaryWeight()==20.)
428 assert(w.calculateTotalLength(1)==30.)
429 assert(w.calculateTotalLength(2)==25.)
430 p.fitToPlayGround(pg)########### ZE CALL
431 assert(n1_0.edGetNbOfBranchesPort().getPyObj()==7)
432 assert(n1_1.edGetNbOfBranchesPort().getPyObj()==5)
434 fyto=pilot.ForTestOmlyHPContCls()
435 n1_0_sc.getContainer().forYourTestsOnly(fyto)
436 assert(fyto.getContainerType()=="HPContainerShared")
438 assert(isinstance(pd,pilot.ContigPartDefinition))
439 print (pd.getStart(),pd.getStop())
440 assert(pd.getStart()==0 and pd.getStop()==7)
442 #########################
443 ## change HPcontainer
444 ## very important: if you change HPcontainer you have to reload the graph
445 #########################
447 n0=r.createScriptNode("Salome","n0")
448 n0.setExecutionMode("remote")
449 out0_0=n0.edAddOutputPort("o1",tdd)
450 n0.setScript("""o1=[float(i)+0.1 for i in range(1000)]""")
454 b0 = r.createBloc("Bloc0")
458 n1_0=r.createForEachLoop("n1_0",td)
460 p.edAddLink(out0_0,n1_0.edGetSeqOfSamplesPort())
462 n1_0_sc=r.createScriptNode("Salome","n1_0_sc")
463 n1_0.edAddChild(n1_0_sc)
464 n1_0_sc.setExecutionMode("remote")
465 n1_0_sc.setScript("""2*i1""")
466 i1_0_sc=n1_0_sc.edAddInputPort("i1",td)
467 p.edAddLink(n1_0.edGetSamplePort(),i1_0_sc)
468 n1_0_sc.setContainer(hp1)
470 n1_0_1=r.createForEachLoop("n1_0_1",td)
471 b0.edAddChild(n1_0_1)
472 p.edAddLink(out0_0,n1_0_1.edGetSeqOfSamplesPort())
473 p.edAddCFLink(n1_0,n1_0_1)
475 n1_0_1sc=r.createScriptNode("Salome","n1_0_1sc")
476 n1_0_1.edAddChild(n1_0_1sc)
477 n1_0_1sc.setExecutionMode("remote")
478 n1_0_1sc.setScript("""a=2""")
479 i1_0_1sc=n1_0_1sc.edAddInputPort("i1",td)
480 p.edAddLink(n1_0_1.edGetSamplePort(),i1_0_1sc)
483 n1_1=r.createForEachLoop("n1_1",td)
485 p.edAddCFLink(n0,n1_1)
486 p.edAddLink(out0_0,n1_1.edGetSeqOfSamplesPort())
488 n1_1_sc=r.createScriptNode("Salome","n1_1_sc")
489 n1_1.edAddChild(n1_1_sc)
490 n1_1_sc.setExecutionMode("remote")
491 n1_1_sc.setScript("""3*i1""")
492 i1_1_sc=n1_1_sc.edAddInputPort("i1",td)
493 p.edAddLink(n1_1.edGetSamplePort(),i1_1_sc)
494 n1_1_sc.setContainer(hp1)
497 hp4=p.createContainer("HP4","HPSalome")
498 hp4.setProperty("nb_proc_per_node","4")
502 n1_0_1sc.setContainer(hp4)
503 w=pilot.ComplexWeight()
504 b0.getWeightRegardingDPL(w)
505 assert(w.getElementaryWeight()==-1.)
506 assert(w.calculateTotalLength(4)==30.)
507 assert(w.calculateTotalLength(8)==15.)
508 pg.setData([("m0",120)])
509 p.fitToPlayGround(pg)########### ZE CALL
510 assert(n1_0.edGetNbOfBranchesPort().getPyObj()==64)
511 assert(n1_0_1.edGetNbOfBranchesPort().getPyObj()==16)
512 assert(n1_1.edGetNbOfBranchesPort().getPyObj()==56)
514 fyto=pilot.ForTestOmlyHPContCls()
515 n1_0_sc.getContainer().forYourTestsOnly(fyto)
516 assert(fyto.getContainerType()=="HPContainerShared")
518 assert(isinstance(pd,pilot.ContigPartDefinition))
519 assert(pd.getStart()==0 and pd.getStop()==64)
524 if __name__ == '__main__':