From b853321698465c51febc4dd0e4d1fb5d172cc775 Mon Sep 17 00:00:00 2001 From: barate Date: Mon, 23 Sep 2013 13:29:19 +0000 Subject: [PATCH] Add job parameter mem_per_cpu (EDF issue #2671) --- idl/SALOME_Launcher.idl | 3 +++ src/Launcher/Launcher_Job.cxx | 22 ++++++++++++++++++++++ src/Launcher/Launcher_Job.hxx | 3 +++ src/Launcher/SALOME_Launcher.cxx | 21 ++++++++++++++++++++- src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py | 8 ++++---- 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/idl/SALOME_Launcher.idl b/idl/SALOME_Launcher.idl index 8e8a014ed..92ecccb16 100644 --- a/idl/SALOME_Launcher.idl +++ b/idl/SALOME_Launcher.idl @@ -76,6 +76,9 @@ struct JobParameters //! Specifies if the job must run in exclusive mode (without sharing nodes with other jobs) boolean exclusive; + //! Specifies the memory limit per cpu (exclusive with resource_required.mem_mb) + unsigned long mem_per_cpu; + /*! Specific parameters for each type of job - optional */ diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 60e0dcba6..7ca6fd6b6 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -26,6 +26,8 @@ #include #endif +using namespace std; + Launcher::Job::Job() { _number = -1; @@ -53,6 +55,7 @@ Launcher::Job::Job() _queue = ""; _job_type = ""; _exclusive = false; + _mem_per_cpu = 0; // Parameters for COORM _launcher_file = ""; @@ -324,6 +327,12 @@ Launcher::Job::setExclusiveStr(const std::string & exclusiveStr) throw LauncherException(std::string("Invalid boolean value for exclusive: ") + exclusiveStr); } +void +Launcher::Job::setMemPerCpu(unsigned long mem_per_cpu) +{ + _mem_per_cpu = mem_per_cpu; +} + std::string Launcher::Job::getWorkDirectory() { @@ -396,6 +405,12 @@ Launcher::Job::getExclusiveStr() const return _exclusive ? "true" : "false"; } +unsigned long +Launcher::Job::getMemPerCpu() const +{ + return _mem_per_cpu; +} + void Launcher::Job::checkMaximumDuration(const std::string & maximum_duration) { @@ -530,6 +545,10 @@ Launcher::Job::common_job_params() { params[Batch::MAXRAMSIZE] = _resource_required_params.mem_mb; } + else if (_mem_per_cpu > 0) + { + params[Batch::MEMPERCPU] = (long)_mem_per_cpu; + } // We define a default directory based on user time if (_work_directory == "") @@ -683,6 +702,9 @@ Launcher::Job::addToXmlDocument(xmlNodePtr root_node) xmlNewChild(node, NULL, xmlCharStrdup("maximum_duration"), xmlCharStrdup(getMaximumDuration().c_str())); xmlNewChild(node, NULL, xmlCharStrdup("queue"), xmlCharStrdup(getQueue().c_str())); xmlNewChild(node, NULL, xmlCharStrdup("exclusive"), xmlCharStrdup(getExclusiveStr().c_str())); + ostringstream mem_per_cpu_stream; + mem_per_cpu_stream << _mem_per_cpu; + xmlNewChild(node, NULL, xmlCharStrdup("mem_per_cpu"), xmlCharStrdup(mem_per_cpu_stream.str().c_str())); // For COORM xmlNewChild(node, NULL, xmlCharStrdup("launcher_args"), xmlCharStrdup(getLauncherArgs().c_str())); diff --git a/src/Launcher/Launcher_Job.hxx b/src/Launcher/Launcher_Job.hxx index 39c999f1d..42ac55d0e 100644 --- a/src/Launcher/Launcher_Job.hxx +++ b/src/Launcher/Launcher_Job.hxx @@ -80,6 +80,7 @@ namespace Launcher void setEnvFile(const std::string & env_file); void setExclusive(bool exclusive); void setExclusiveStr(const std::string & exclusiveStr); + void setMemPerCpu(unsigned long mem_per_cpu); // For COORM void setLauncherFile(const std::string & launcher_file); void setLauncherArgs(const std::string & launcher_args); @@ -98,6 +99,7 @@ namespace Launcher std::string getJobType(); bool getExclusive(); std::string getExclusiveStr() const; + unsigned long getMemPerCpu() const; // For COORM std::string getLauncherFile(); @@ -155,6 +157,7 @@ namespace Launcher resourceParams _resource_required_params; std::string _queue; bool _exclusive; + unsigned long _mem_per_cpu; // Parameters for COORM std::string _launcher_file; diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index a0eb7e5f6..1832b9639 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -160,6 +160,9 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters) // Exclusive new_job->setExclusive(job_parameters.exclusive); + // Memory required per CPU + new_job->setMemPerCpu(job_parameters.mem_per_cpu); + // Resources requirements try { @@ -496,6 +499,7 @@ SALOME_Launcher::getJobParameters(CORBA::Long job_id) job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str()); job_parameters->queue = CORBA::string_dup(job->getQueue().c_str()); job_parameters->exclusive = job->getExclusive(); + job_parameters->mem_per_cpu = job->getMemPerCpu(); resourceParams resource_params = job->getResourceRequiredParams(); job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str()); @@ -714,11 +718,13 @@ SALOME_Launcher::loadJobs(const char* jobs_file) xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node); xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node); xmlNodePtr exclusive_node = xmlNextElementSibling(queue_node); - xmlNodePtr launcher_args_node = xmlNextElementSibling(exclusive_node); + xmlNodePtr mem_per_cpu_node = xmlNextElementSibling(exclusive_node); + xmlNodePtr launcher_args_node = xmlNextElementSibling(mem_per_cpu_node); if (res_node == NULL || maximum_duration_node == NULL || queue_node == NULL || exclusive_node == NULL || + mem_per_cpu_node == NULL || // For COORM launcher_args_node == NULL ) @@ -731,6 +737,7 @@ SALOME_Launcher::loadJobs(const char* jobs_file) xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) || xmlStrcmp(queue_node->name, xmlCharStrdup("queue")) || xmlStrcmp(exclusive_node->name, xmlCharStrdup("exclusive")) || + xmlStrcmp(mem_per_cpu_node->name, xmlCharStrdup("mem_per_cpu")) || // For COORM xmlStrcmp(launcher_args_node->name, xmlCharStrdup("launcher_args")) ) @@ -770,6 +777,18 @@ SALOME_Launcher::loadJobs(const char* jobs_file) } xmlFree(exclusive); + xmlChar* mem_per_cpu_str = xmlNodeGetContent(mem_per_cpu_node); + std::istringstream mem_per_cpu_stream((const char *)mem_per_cpu_str); + unsigned long mem_per_cpu = 0; + if (!(mem_per_cpu_stream >> mem_per_cpu)) + { + INFOS("A bad job is found, mem_per_cpu parameter is not correct"); + delete new_job; + break; + } + else + new_job->setMemPerCpu(mem_per_cpu); + // For COORM xmlChar* launcher_args = xmlNodeGetContent(launcher_args_node); new_job->setLauncherArgs(std::string((const char *)launcher_args)); diff --git a/src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py b/src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py index ad90b186e..f308536f1 100644 --- a/src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py @@ -56,12 +56,12 @@ class ResourceParameters (Engines.ResourceParameters): class JobParameters (Engines.JobParameters): def __init__(self, job_name="", job_type="", job_file="", env_file="", in_files=[], out_files=[], work_directory="", local_directory="", result_directory="", maximum_duration="", - resource_required=None, queue="", exclusive = False, specific_parameters=[], - launcher_file = "", launcher_args = ""): + resource_required=None, queue="", exclusive = False, mem_per_cpu = 0, + specific_parameters=[], launcher_file = "", launcher_args = ""): Engines.JobParameters.__init__(self, job_name, job_type, job_file, env_file, in_files, out_files, work_directory, local_directory, result_directory, maximum_duration, - resource_required, queue, exclusive, specific_parameters, - launcher_file, launcher_args) + resource_required, queue, exclusive, mem_per_cpu, + specific_parameters, launcher_file, launcher_args) class ResourceDefinition(Engines.ResourceDefinition): def __init__(self, name="", hostname="", protocol="rsh", username="", applipath="", componentList=[], -- 2.39.2