2 # Copyright (C) 2023 CEA, EDF
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
30 class TestYacsPerf0(unittest.TestCase):
33 [EDF28531] : Perf to check when number of threads in charge scheduler side is lower than number of // tasks
35 NB_OF_PARALLEL_NODES = 100
36 NB_OF_PARALLEL_THREADS = 10
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")
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)
62 fe = r.createForEachLoopDyn("fe",pyobj)
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("""
72 fe.edSetNode(internalNode)
73 ix = internalNode.edAddInputPort("ppp",pyobj)
74 oret = internalNode.edAddOutputPort("ret",pyobj)
75 p.edAddLink( fe.edGetSamplePort(), ix )
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""")
84 p.edAddCFLink(fe,endNode)
85 p.edAddLink( oret, izeret )
87 fname = "PerfTest0.xml"
93 print("Start computation")
95 st = datetime.datetime.now()
96 ex=pilot.ExecutorSwig()
97 ex.setMaxNbOfThreads(NB_OF_PARALLEL_THREADS)
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")
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 !")