Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/superv.git] / examples / GraphCpuUsed.py
1
2 # Generated python file of Graph GraphCpuUsed
3
4 from SuperV import *
5 # Graph creation 
6 GraphCpuUsed = Graph( 'GraphCpuUsed' )
7 GraphCpuUsed.SetName( 'GraphCpuUsed' )
8 GraphCpuUsed.SetAuthor( '' )
9 GraphCpuUsed.SetComment( '' )
10 GraphCpuUsed.Coords( 0 , 0 )
11
12 # Creation of Factory Nodes
13
14 sigma = GraphCpuUsed.FNode( 'FactorialComponent' , 'FactorialComponent' , 'sigma' )
15 sigma.SetName( 'sigma' )
16 sigma.SetAuthor( 'JR' )
17 sigma.SetContainer( 'localhost/FactoryServerPy' )
18 sigma.SetComment( 'sigma from FactorialComponent' )
19 sigma.Coords( 214 , 172 )
20
21 Sigma = GraphCpuUsed.FNode( 'AddComponent' , 'AddComponent' , 'Sigma' )
22 Sigma.SetName( 'Sigma' )
23 Sigma.SetAuthor( '' )
24 Sigma.SetContainer( 'localhost/FactoryServer' )
25 Sigma.SetComment( 'Sigma from AddComponent' )
26 Sigma.Coords( 418 , 21 )
27
28 # Creation of InLine Nodes
29 PyAdd = []
30 PyAdd.append( 'from time import *       ' )
31 PyAdd.append( 'def Add(a,b) :           ' )
32 PyAdd.append( '    print "Add will wait 5 seconds"         ' )
33 PyAdd.append( '    d = dir()        ' )
34 PyAdd.append( '    print "Add",d        ' )
35 PyAdd.append( '    d = dir(sleep)        ' )
36 PyAdd.append( '    print "Add",d        ' )
37 PyAdd.append( '    sleep(5)         ' )
38 PyAdd.append( '    print "Add waited"         ' )
39 PyAdd.append( '    n = 0     ' )
40 PyAdd.append( '    while n < 10000 :     ' )
41 PyAdd.append( '        i = 0     ' )
42 PyAdd.append( '        s = 0     ' )
43 PyAdd.append( '        while i <= b :     ' )
44 PyAdd.append( '            s = s + i     ' )
45 PyAdd.append( '            i = i + 1     ' )
46 PyAdd.append( '        n = n + 1     ' )
47 PyAdd.append( '    return s          ' )
48 PyAdd.append( '' )
49 Add = GraphCpuUsed.INode( 'Add' , PyAdd )
50 Add.InPort( 'a' , 'long' )
51 Add.InPort( 'b' , 'long' )
52 Add.OutPort( 'f' , 'long' )
53 Add.SetName( 'Add' )
54 Add.SetAuthor( '' )
55 Add.SetComment( 'Python function' )
56 Add.Coords( 214 , 0 )
57
58 PySub = []
59 PySub.append( 'def Sub(a,b) : ' )
60 PySub.append( '    return a-b ' )
61 PySub.append( '' )
62 Sub = GraphCpuUsed.INode( 'Sub' , PySub )
63 Sub.InPort( 'a' , 'long' )
64 Sub.InPort( 'b' , 'long' )
65 Sub.OutPort( 'f' , 'long' )
66 Sub.SetName( 'Sub' )
67 Sub.SetAuthor( '' )
68 Sub.SetComment( 'Python function' )
69 Sub.Coords( 0 , 139 )
70
71 PyCompare = []
72 PyCompare.append( 'def Compare( Add , sigma , Sigma ) :  ' )
73 PyCompare.append( '     Result = "Good" ' )
74 PyCompare.append( '     if Add != sigma :  ' )
75 PyCompare.append( '             Result = "Bad" ' )
76 PyCompare.append( '     if Add != Sigma :  ' )
77 PyCompare.append( '             Result = "Bad" ' )
78 PyCompare.append( '     return Result  ' )
79 PyCompare.append( '' )
80 Compare = GraphCpuUsed.INode( 'Compare' , PyCompare )
81 Compare.InPort( 'Add' , 'long' )
82 Compare.InPort( 'Sigma' , 'long' )
83 Compare.InPort( 'sigma' , 'long' )
84 Compare.OutPort( 'Result' , 'string' )
85 Compare.SetName( 'Compare' )
86 Compare.SetAuthor( '' )
87 Compare.SetComment( 'Compute Node' )
88 Compare.Coords( 419 , 184 )
89
90 # Creation of Links
91 Addf = Add.Port( 'f' )
92 CompareAdd = GraphCpuUsed.Link( Addf , Compare.Port( 'Add' ) )
93 CompareAdd.AddCoord( 1 , 411 , 265 )
94 CompareAdd.AddCoord( 2 , 411 , 169 )
95 CompareAdd.AddCoord( 3 , 617 , 169 )
96 CompareAdd.AddCoord( 4 , 618 , 8 )
97 CompareAdd.AddCoord( 5 , 401 , 8 )
98 CompareAdd.AddCoord( 6 , 400 , 80 )
99
100 Subf = Sub.Port( 'f' )
101 Addb = GraphCpuUsed.Link( Subf , Add.Port( 'b' ) )
102 Addb.AddCoord( 1 , 189 , 108 )
103 Addb.AddCoord( 2 , 191 , 220 )
104
105 sigman = GraphCpuUsed.Link( Subf , sigma.Port( 'n' ) )
106 sigman.AddCoord( 1 , 206 , 254 )
107 sigman.AddCoord( 2 , 206 , 220 )
108
109 Sigman = GraphCpuUsed.Link( Subf , Sigma.Port( 'n' ) )
110 Sigman.AddCoord( 1 , 389 , 101 )
111 Sigman.AddCoord( 2 , 390 , 160 )
112 Sigman.AddCoord( 3 , 190 , 161 )
113 Sigman.AddCoord( 4 , 190 , 220 )
114
115 sigmaf = sigma.Port( 'f' )
116 Comparesigma = GraphCpuUsed.Link( sigmaf , Compare.Port( 'sigma' ) )
117 Comparesigma.AddCoord( 1 , 386 , 323 )
118 Comparesigma.AddCoord( 2 , 385 , 253 )
119
120 Sigmaf = Sigma.Port( 'f' )
121 CompareSigma = GraphCpuUsed.Link( Sigmaf , Compare.Port( 'Sigma' ) )
122 CompareSigma.AddCoord( 1 , 400 , 295 )
123 CompareSigma.AddCoord( 2 , 400 , 153 )
124 CompareSigma.AddCoord( 3 , 595 , 153 )
125 CompareSigma.AddCoord( 4 , 595 , 102 )
126
127 # Creation of Input datas
128 Adda = Add.Input( 'a' , 1)
129 Suba = Sub.Input( 'a' , 1000)
130 Subb = Sub.Input( 'b' , 1)
131
132 # Creation of Output variables
133 CompareResult = Compare.Port( 'Result' )
134
135 GraphCpuUsed.Run()
136 GraphCpuUsed.DoneW()
137 GraphCpuUsed.PrintPorts()
138 print "sigma",sigma.CpuUsed(),"seconds"
139 print "Sigma",Sigma.CpuUsed(),"seconds"
140 print "Add",Add.CpuUsed(),"seconds"
141 print "Sub",Sub.CpuUsed(),"seconds"
142 print "Compare",Compare.CpuUsed(),"seconds"