]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader_swig/Test/testYacsPerfTest0.py
Salome HOME
296e436307a9c78d71106235835a9fcdada8bd71
[modules/yacs.git] / src / yacsloader_swig / Test / testYacsPerfTest0.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2023  CEA, EDF
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import unittest
22 import tempfile
23 import os
24
25 import pilot
26 import SALOMERuntime
27 import loader
28 import salome
29
30 class TestYacsPerf0(unittest.TestCase):
31     def test0(self):
32         """
33         [EDF28531] : Perf to check when number of threads in charge scheduler side is lower than number of // tasks
34         """
35         NB_OF_PARALLEL_NODES = 100
36         NB_OF_PARALLEL_THREADS = 10
37         salome.salome_init()
38         SALOMERuntime.RuntimeSALOME.setRuntime()
39         r=SALOMERuntime.getSALOMERuntime()
40         p=r.createProc("PerfTest0")
41         p.setProperty("executor","workloadmanager") # important line here to avoid that gg container treat several tasks in //.
42         ti=p.createType("int","int")
43         td=p.createType("double","double")
44         tdd=p.createSequenceTc("seqdouble","seqdouble",td)
45         tddd=p.createSequenceTc("seqseqdouble","seqseqdouble",tdd)
46         tdddd=p.createSequenceTc("seqseqseqdouble","seqseqseqdouble",tddd)
47         pyobj=p.createInterfaceTc("python:obj:1.0","pyobj",[])
48         seqpyobj=p.createSequenceTc("list[pyobj]","list[pyobj]",pyobj)
49         cont=p.createContainer("gg","Salome")
50         cont.setProperty("nb_parallel_procs","1")
51         cont.setAttachOnCloningStatus(True)
52         cont.setProperty("attached_on_cloning","1")
53         cont.setProperty("type","multi")
54         cont.setProperty("container_name","gg")
55         ######## Level 0
56         startNode = r.createScriptNode("Salome","start")
57         startNode.setExecutionMode("local")
58         startNode.setScript("""o2 = list(range({}))""".format(NB_OF_PARALLEL_NODES))
59         po2 = startNode.edAddOutputPort("o2",seqpyobj)
60         p.edAddChild(startNode)
61         #
62         fe = r.createForEachLoopDyn("fe",pyobj)
63         p.edAddChild(fe)
64         p.edAddCFLink(startNode,fe)
65         p.edAddLink(po2,fe.edGetSeqOfSamplesPort())
66         internalNode = r.createScriptNode("Salome","internalNode")
67         internalNode.setExecutionMode("remote")
68         internalNode.setContainer(cont)
69         internalNode.setScript("""
70 ret = 3*ppp
71 """)
72         fe.edSetNode(internalNode)
73         ix = internalNode.edAddInputPort("ppp",pyobj)
74         oret = internalNode.edAddOutputPort("ret",pyobj)
75         p.edAddLink( fe.edGetSamplePort(), ix )
76         #
77         endNode = r.createScriptNode("Salome","end")
78         endNode.setExecutionMode("local")
79         endNode.setContainer(None)
80         ozeret = endNode.edAddOutputPort("ozeret",seqpyobj)
81         izeret = endNode.edAddInputPort("izeret",seqpyobj)
82         endNode.setScript("""ozeret = izeret""")
83         p.edAddChild(endNode)
84         p.edAddCFLink(fe,endNode)
85         p.edAddLink( oret, izeret )
86         if False:
87             fname = "PerfTest0.xml"
88             p.saveSchema(fname)
89             
90             import loader
91             l=loader.YACSLoader()
92             p=l.load(fname)
93         print("Start computation")
94         import datetime
95         st = datetime.datetime.now()
96         ex=pilot.ExecutorSwig()
97         ex.setMaxNbOfThreads(NB_OF_PARALLEL_THREADS)
98         ex.RunW(p,0)
99         salome.cm.ShutdownContainers()
100         print("End of computation {}".format( str(datetime.datetime.now()-st) ) )
101         if p.getChildByName("end").getOutputPort("ozeret").getPyObj() != [3*i for i in range(NB_OF_PARALLEL_NODES)]:
102             raise RuntimeError("Ooops")
103
104 if __name__ == '__main__':
105   with tempfile.TemporaryDirectory() as dir_test:
106     file_test = os.path.join(dir_test,"UnitTestsResult")
107     with open(file_test, 'a') as f:
108         f.write("  --- TEST src/yacsloader: testYacsPerfTest0.py\n")
109         suite = unittest.makeSuite(TestYacsPerf0)
110         result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
111         if not result.wasSuccessful():
112            raise RuntimeError("Test failed !")