Salome HOME
Updated copyright comment
[modules/yacs.git] / src / yacsloader_swig / Test / testFEDyn.py
1 import pilot
2 import SALOMERuntime
3 import loader
4 import datetime
5
6 fname="testFEDyn.xml"
7 fname2="REtestFEDyn.xml"
8 SALOMERuntime.RuntimeSALOME.setRuntime()
9 l=loader.YACSLoader()
10 r=SALOMERuntime.getSALOMERuntime()
11 p=r.createProc("prTest1")
12 td=p.createType("double","double")
13 ti=p.createType("int","int")
14 cont=p.createContainer("gg","HPSalome")
15 cont.setProperty("nb_proc_per_node","1")
16 #
17 pg=pilot.PlayGround()
18 #pg.loadFromKernelCatalog()
19 pg.setData([("localhost",4)])
20 #
21 #cont.setSizeOfPool(4)
22 cont.setProperty("name","localhost")
23 cont.setProperty("hostname","localhost")
24 ti=p.createType("int","int")
25 tsi=p.createSequenceTc("seqint","seqint",ti)
26 # Level0
27 n0=r.createScriptNode("","n0")
28 o0=n0.edAddOutputPort("o0",tsi)
29 n0.setScript("o0=[ elt for elt in range(8) ]")
30 p.edAddChild(n0)
31 n1=r.createForEachLoopDyn("n1",ti)#Dyn
32 #n1.getInputPort("nbBranches").edInitPy(2)
33 n10=r.createScriptNode("","n10")
34 n10.setExecutionMode("remote")
35 n10.setContainer(cont)
36 n1.edAddChild(n10)
37 n10.setScript("""
38 import time
39 time.sleep(1)
40 o2=2*i1
41 """)
42 i1=n10.edAddInputPort("i1",ti)
43 o2=n10.edAddOutputPort("o2",ti)
44 p.edAddChild(n1)
45 p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
46 p.edAddLink(n1.edGetSamplePort(),i1)
47 p.edAddCFLink(n0,n1)
48 n2=r.createScriptNode("","n2")
49 n2.setScript("o4=i3")
50 i3=n2.edAddInputPort("i3",tsi)
51 i4=n2.edAddInputPort("i4",tsi)
52 o4=n2.edAddOutputPort("o4",tsi)
53 n2.setScript("o4=[a+b for a,b in zip(i3,i4)]")
54 p.edAddChild(n2)
55 p.edAddCFLink(n1,n2)
56 p.edAddLink(o2,i3)
57 # Second parallel foreach
58 n11=r.createForEachLoopDyn("n11",ti)
59 #n11.getInputPort("nbBranches").edInitPy(2)
60 n110=r.createScriptNode("","n110")
61 n110.setExecutionMode("remote")
62 n110.setContainer(cont)
63 n11.edAddChild(n110)
64 n110.setScript("""
65 import time
66 time.sleep(10)
67 o2=3*i1
68 """)
69 i1_1=n110.edAddInputPort("i1",ti)
70 o2_1=n110.edAddOutputPort("o2",ti)
71 p.edAddChild(n11)
72 p.edAddLink(o0,n11.edGetSeqOfSamplesPort())
73 p.edAddLink(n11.edGetSamplePort(),i1_1)
74 p.edAddCFLink(n0,n11)
75 p.edAddCFLink(n11,n2)
76 p.edAddLink(o2_1,i4)
77 #
78 p.saveSchema(fname)
79 p=l.load(fname)
80 p.saveSchema(fname2)
81 p.init()
82 p.propagePlayGround(pg)
83 ex=pilot.ExecutorSwig()
84 assert(p.getState()==pilot.READY)
85 stt = datetime.datetime.now()
86 ex.RunW(p,0)
87 print(str(datetime.datetime.now()-stt))
88 assert(p.getState()==pilot.DONE)
89 o4=p.getChildByName("n2").getOutputPort("o4")
90 assert(o4.getPyObj()==[0, 5, 10, 15, 20, 25, 30, 35])
91 # Ideal ForEachDyn time = 22 s
92 # ForEach time = 40 s"""