Salome HOME
updated copyright message
[plugins/blsurfplugin.git] / tests / multithread.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-2023  CEA/DEN, EDF R&D
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 os
22 import sys
23 import salome
24 import time
25 import multiprocessing
26
27 salome.salome_init()
28
29 cpu_count = multiprocessing.cpu_count()
30
31 if cpu_count > 1:
32     print ("Running test on workstation with %d available cores" % cpu_count)
33
34     ###
35     ### GEOM component
36     ###
37
38     import GEOM
39     from salome.geom import geomBuilder
40     import math
41     import SALOMEDS
42
43     geompy = geomBuilder.New()
44
45     O = geompy.MakeVertex(0, 0, 0)
46     OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
47     OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
48     OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
49     flight_solid_brep_1 = geompy.ImportBREP(os.path.join(os.getenv("BLSURFPLUGIN_ROOT_DIR"),"share/salome/resources/blsurfplugin/flight_solid.brep"))
50     geompy.addToStudy( O, 'O' )
51     geompy.addToStudy( OX, 'OX' )
52     geompy.addToStudy( OY, 'OY' )
53     geompy.addToStudy( OZ, 'OZ' )
54     geompy.addToStudy( flight_solid_brep_1, 'flight_solid.brep_1' )
55
56     ###
57     ### SMESH component
58     ###
59
60     import  SMESH, SALOMEDS
61     from salome.smesh import smeshBuilder
62
63     smesh = smeshBuilder.New()
64
65     Mesh_1 = smesh.Mesh(flight_solid_brep_1)
66     MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
67     MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
68     MG_CADSurf_Parameters_1.SetPhySize( 1 )
69     MG_CADSurf_Parameters_1.SetMaxSize( 1 )
70     MG_CADSurf_Parameters_1.SetGradation( 1.05 )
71     MG_CADSurf_Parameters_1.SetAngleMesh( 1 )
72     MG_CADSurf_Parameters_1.SetChordalError( 2.40018 )
73     # 4 procs are used by default
74     # => No need to set an option
75
76     time0 = time.time()
77     isDone = Mesh_1.Compute()
78     time1 = time.time()
79
80     time_multithread = time1-time0
81
82     print ("Time in multi thread (%d procs): %.3f s"%(cpu_count, time_multithread))
83
84     Mesh_2 = smesh.Mesh(flight_solid_brep_1)
85     MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf)
86     MG_CADSurf_Parameters_2 = MG_CADSurf.Parameters()
87     MG_CADSurf_Parameters_2.SetPhySize( 1 )
88     MG_CADSurf_Parameters_2.SetMaxSize( 1 )
89     MG_CADSurf_Parameters_2.SetGradation( 1.05 )
90     MG_CADSurf_Parameters_2.SetAngleMesh( 1 )
91     MG_CADSurf_Parameters_2.SetChordalError( 2.40018 )
92     # Use only one thread
93     MG_CADSurf_Parameters_2.SetMaxNumberOfThreads( 1 )
94
95     time2 = time.time()
96     isDone = Mesh_2.Compute()
97     time3 = time.time()
98
99     time_singlethread = time3-time2
100     print ("Time in single thread (1 proc): %.3f s"%(time_singlethread))
101
102     assert time_multithread < time_singlethread
103
104     if salome.sg.hasDesktop():
105       salome.sg.updateObjBrowser()
106 else:
107     print ("Warning: multithread test is disabled for %d cpu core(s)" % cpu_count)