From 3f27d28db82946920d0618c9ed5e76917731806b Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Tue, 17 Jan 2023 16:57:31 +0100 Subject: [PATCH] Code review. --- src/CMakeLists.txt | 1 + src/pydefx/CMakeLists.txt | 1 - src/pydefx/configuration.py | 35 +++++++++++++++++--------------- src/pytools/CMakeLists.txt | 23 +++++++++++++++++++++ src/{pydefx => pytools}/mpmcn.py | 2 +- 5 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 src/pytools/CMakeLists.txt rename src/{pydefx => pytools}/mpmcn.py (98%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb26fe4..6045f2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ ENDIF(SALOME_BUILD_TESTS) ADD_SUBDIRECTORY(cpp) ADD_SUBDIRECTORY(pydefx) +ADD_SUBDIRECTORY(pytools) IF(YDEFX_BUILD_GUI) ADD_SUBDIRECTORY(gui) ENDIF(YDEFX_BUILD_GUI) diff --git a/src/pydefx/CMakeLists.txt b/src/pydefx/CMakeLists.txt index 3617457..f5a2ca3 100644 --- a/src/pydefx/CMakeLists.txt +++ b/src/pydefx/CMakeLists.txt @@ -39,6 +39,5 @@ SET(SCRIPTS ) INSTALL(FILES ${SCRIPTS} DESTINATION ${SALOME_INSTALL_PYTHON}/pydefx) -install(FILES mpmcn.py DESTINATION ${SALOME_INSTALL_PYTHON}) ADD_SUBDIRECTORY(schemas) ADD_SUBDIRECTORY(plugins) diff --git a/src/pydefx/configuration.py b/src/pydefx/configuration.py index 210a205..6852b75 100644 --- a/src/pydefx/configuration.py +++ b/src/pydefx/configuration.py @@ -29,22 +29,26 @@ def defaultWorkingDir(resource): return resource_definition.working_directory def defaultNbBranches(resource): + """ + Return the number of cores available on a resource. + """ resManager = salome_proxy.getResourcesManager() resource_definition = resManager.GetResourceDefinition(resource) - ret = resource_definition.nb_node + ret = resource_definition.nb_node * resource_definition.nb_proc_per_node if ret < 1: ret = 1 return ret - -def getNumberOfCoresForLocalhost(): - """ - Return total number of cores for all resources marked as able to run containers ( "canRunContainers" attribute - set to true in the CatalogResources.xml ). - """ - import LifeCycleCORBA - params = LifeCycleCORBA.ResourceParameters(can_run_containers=True) - resources = salome_proxy.getResourcesManager().GetFittingResources(params) - return sum( [salome_proxy.getResourcesManager().GetResourceDefinition(res).nb_proc_per_node for res in resources] ) + +def allCoresAvailable(): + """ + Return the total number of cores of all resources that can run containers. + ( "canRunContainers" attribute set to true in CatalogResources.xml ) + """ + resManager = salome_proxy.getResourcesManager() + params = salome_proxy.createSalomeParameters() + params.resource_required.can_run_containers = True + resources = resManager.GetFittingResources(params.resource_required) + return sum([defaultNbBranches(res) for res in resources ]) def defaultBaseDirectory(): """Return the default path to the root of any new result directory.""" @@ -63,11 +67,10 @@ def defaultWckey(resource="localhost"): return result def availableResources(): - """ Return the list of resources defined in the current catalog. - - Regarding list of Resources in the CatalogResources.xml this method returns those able to launch jobs. - Ydefx engine delegate to a job encapsulating itself an execution of YACS graph with driver application. - Consequently, the resource to evaluate in parallel the function should one of those returned by this method. + """ + Return the list of resources defined in the current catalog that are able to + launch jobs. + Ydefx can launch the evaluations in a job on one of these resources. """ resManager = salome_proxy.getResourcesManager() params = salome_proxy.createSalomeParameters() diff --git a/src/pytools/CMakeLists.txt b/src/pytools/CMakeLists.txt new file mode 100644 index 0000000..57ac808 --- /dev/null +++ b/src/pytools/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright (C) 2023 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +SET(SCRIPTS +mpmcn.py +) + +INSTALL(FILES ${SCRIPTS} DESTINATION ${SALOME_INSTALL_PYTHON}) diff --git a/src/pydefx/mpmcn.py b/src/pytools/mpmcn.py similarity index 98% rename from src/pydefx/mpmcn.py rename to src/pytools/mpmcn.py index 0c68003..bbbb3a2 100644 --- a/src/pydefx/mpmcn.py +++ b/src/pytools/mpmcn.py @@ -150,5 +150,5 @@ def init(resourceName, resultDirectory = "/tmp"): myParams.configureResource(resourceName) myParams.createResultDirectory(resultDirectory) if resourceName == "localhost": - myParams.nb_branches = configuration.getNumberOfCoresForLocalhost() + myParams.nb_branches = configuration.allCoresAvailable() return myParams -- 2.39.2