From: Anthony Geay Date: Tue, 17 Jan 2023 14:18:45 +0000 (+0100) Subject: Integration of Ovidiu\'s feedback X-Git-Tag: V9_11_0a1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50279484737f21694323aad8c08ff0b3257aa162;p=tools%2Fydefx.git Integration of Ovidiu\'s feedback --- diff --git a/src/pydefx/configuration.py b/src/pydefx/configuration.py index 260cb3e..210a205 100644 --- a/src/pydefx/configuration.py +++ b/src/pydefx/configuration.py @@ -35,6 +35,16 @@ def defaultNbBranches(resource): 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 defaultBaseDirectory(): """Return the default path to the root of any new result directory.""" @@ -53,7 +63,12 @@ def defaultWckey(resource="localhost"): return result def availableResources(): - """ Return the list of resources defined in the current catalog.""" + """ 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. + """ resManager = salome_proxy.getResourcesManager() params = salome_proxy.createSalomeParameters() params.resource_required.can_launch_batch_jobs = True diff --git a/src/pydefx/mpmcn.py b/src/pydefx/mpmcn.py index 12fcfc6..0c68003 100644 --- a/src/pydefx/mpmcn.py +++ b/src/pydefx/mpmcn.py @@ -19,8 +19,6 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com import pydefx -import salome -salome.salome_init() class Pool: def __init__(self, params): @@ -94,7 +92,7 @@ def _exec({}): exc.tmp_dir = self.getResultDirectory() raise exc else: - raise RuntimeError("Error during job submission or during the driver execution (that should never happend)") + raise RuntimeError( "Error during job submission or during the driver execution (that should never happend). Internal error : {}".format(self.myStudy.getResult().getErrors()) ) def __enter__(self): self.myStudy = pydefx.PyStudy() @@ -113,27 +111,6 @@ def _exec({}): pass pass -def getResourcesAbleToLaunchJobs(): - """ - 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. - """ - import LifeCycleCORBA - params = LifeCycleCORBA.ResourceParameters(can_launch_batch_jobs=True) - # ask to resource manager to filter among all resources listed in CatalogResources those able to launch job. - return salome.rm.GetFittingResources(params) - -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.rm.GetFittingResources(params) - return sum( [salome.rm.GetResourceDefinition(res).nb_proc_per_node for res in resources] ) - def init(resourceName, resultDirectory = "/tmp"): """ Instanciate a pydefx.Parameters intance that can be overriden right after. @@ -167,10 +144,11 @@ def init(resourceName, resultDirectory = "/tmp"): :return: a pydefx.Parameters instance """ myParams = pydefx.Parameters() - if resourceName not in getResourcesAbleToLaunchJobs(): - raise RuntimeError("Resource \"{}\" is not existing or not declared as able to launch job. Available resources are : {}".format(resourceName,str(getResourcesAbleToLaunchJobs()))) + from pydefx import configuration + if resourceName not in configuration.availableResources(): + raise RuntimeError("Resource \"{}\" is not existing or not declared as able to launch job. Available resources are : {}".format(resourceName,str(configuration.availableResources()))) myParams.configureResource(resourceName) myParams.createResultDirectory(resultDirectory) if resourceName == "localhost": - myParams.nb_branches = getNumberOfCoresForLocalhost() + myParams.nb_branches = configuration.getNumberOfCoresForLocalhost() return myParams