From: ribes Date: Wed, 18 Nov 2009 15:14:55 +0000 (+0000) Subject: - EnvFile for all type of jobs X-Git-Tag: new_launcher_alpha_091119~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=26bc6e191cb8262d74cbc58f131d083abf47b537;p=modules%2Fkernel.git - EnvFile for all type of jobs - Job number counter is now thread safe --- diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 28c274115..729147f76 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -52,6 +52,9 @@ Launcher_cpp::Launcher_cpp() #if defined(_DEBUG_) || defined(_DEBUG) cerr << "Launcher_cpp constructor" << endl; #endif + _job_cpt = 0; + _job_cpt_mutex = new pthread_mutex_t(); + pthread_mutex_init(_job_cpt_mutex, NULL); } //============================================================================= @@ -75,6 +78,8 @@ Launcher_cpp::~Launcher_cpp() for(it_job = _launcher_job_map.begin(); it_job != _launcher_job_map.end(); it_job++) delete it_job->second; #endif + pthread_mutex_destroy(_job_cpt_mutex); + delete _job_cpt_mutex; } //============================================================================= @@ -1062,7 +1067,12 @@ Launcher_cpp::createJob(Launcher::Job * new_job) } } + // Final step - add job to the jobs map + pthread_mutex_lock(_job_cpt_mutex); + new_job->setNumber(_job_cpt); + _job_cpt++; + pthread_mutex_unlock(_job_cpt_mutex); std::map::const_iterator it_job = _launcher_job_map.find(new_job->getNumber()); if (it_job == _launcher_job_map.end()) _launcher_job_map[new_job->getNumber()] = new_job; diff --git a/src/Launcher/Launcher.hxx b/src/Launcher/Launcher.hxx index 91b110939..916b71cf5 100644 --- a/src/Launcher/Launcher.hxx +++ b/src/Launcher/Launcher.hxx @@ -33,6 +33,8 @@ #include #include +#include + class MpiImpl; namespace Batch{ @@ -101,6 +103,8 @@ protected: //! will contain the informations on the data type catalog(after parsing) ParserLauncherType _launch; + int _job_cpt; // job number counter + pthread_mutex_t * _job_cpt_mutex; // mutex for job counter }; #endif diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index ae96a88f5..9edbb2f4a 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -27,6 +27,7 @@ Launcher::Job::Job() _state = "CREATED"; _launch_date = getLaunchDate(); + _env_file = ""; _work_directory = ""; _local_directory = ""; _result_directory = ""; @@ -112,6 +113,18 @@ Launcher::Job::getMachineDefinition() return _machine_definition; } +void +Launcher::Job::setEnvFile(std::string & env_file) +{ + _env_file = env_file; +} + +std::string +Launcher::Job::getEnvFile() +{ + return _env_file; +} + void Launcher::Job::setWorkDirectory(const std::string & work_directory) { @@ -378,6 +391,10 @@ Launcher::Job::common_job_params() if (_result_directory == "") _result_directory = getenv("HOME"); + //Env file + if (_env_file != "") + add_in_file(_env_file); + // _in_files for(std::list::iterator it = _in_files.begin(); it != _in_files.end(); it++) { diff --git a/src/Launcher/Launcher_Job.hxx b/src/Launcher/Launcher_Job.hxx index 5c74b1a21..8405e0edb 100644 --- a/src/Launcher/Launcher_Job.hxx +++ b/src/Launcher/Launcher_Job.hxx @@ -69,6 +69,7 @@ namespace Launcher void setMaximumDuration(const std::string & maximum_duration); void setMachineRequiredParams(const machineParams & machine_required_params); void setQueue(const std::string & queue); + void setEnvFile(std::string & env_file); std::string getWorkDirectory(); std::string getLocalDirectory(); @@ -78,6 +79,7 @@ namespace Launcher std::string getMaximumDuration(); machineParams getMachineRequiredParams(); std::string getQueue(); + std::string getEnvFile(); std::string updateJobState(); @@ -97,6 +99,7 @@ namespace Launcher std::string _state; std::string _launch_date; + std::string _env_file; ParserResourcesType _machine_definition; diff --git a/src/Launcher/Launcher_Job_Command.cxx b/src/Launcher/Launcher_Job_Command.cxx index aa8d92811..2711fcf4c 100644 --- a/src/Launcher/Launcher_Job_Command.cxx +++ b/src/Launcher/Launcher_Job_Command.cxx @@ -23,7 +23,6 @@ Launcher::Job_Command::Job_Command(const std::string & command) { _command = command; - _env_file = ""; } Launcher::Job_Command::~Job_Command() {} @@ -40,18 +39,6 @@ Launcher::Job_Command::getCommand() return _command; } -void -Launcher::Job_Command::setEnvFile(std::string & env_file) -{ - _env_file = env_file; -} - -std::string -Launcher::Job_Command::getEnvFile() -{ - return _env_file; -} - void Launcher::Job_Command::update_job() { @@ -72,18 +59,6 @@ Launcher::Job_Command::update_job() std::string remote_file = _work_directory + "/" + _command.substr(found+1); params[INFILE] += Batch::Couple(local_file, remote_file); - // Copy env file - if (_env_file != "") - { - if (_env_file.substr(0, 1) == std::string("/")) - local_file = _env_file; - else - local_file = _local_directory + "/" + _env_file; - found = _env_file.find_last_of("/"); - remote_file = _work_directory + "/" + _env_file.substr(found+1); - params[INFILE] += Batch::Couple(local_file, remote_file); - } - params[EXECUTABLE] = buildCommandScript(params, _launch_date); _batch_job->setParametre(params); #endif diff --git a/src/Launcher/Launcher_Job_Command.hxx b/src/Launcher/Launcher_Job_Command.hxx index 9a7a8cb80..5171d4909 100644 --- a/src/Launcher/Launcher_Job_Command.hxx +++ b/src/Launcher/Launcher_Job_Command.hxx @@ -39,8 +39,6 @@ namespace Launcher // Specific parameters void setCommand(const std::string & command); std::string getCommand(); - void setEnvFile(std::string & env_file); - std::string getEnvFile(); virtual void update_job(); @@ -51,7 +49,6 @@ namespace Launcher private: std::string _command; - std::string _env_file; }; } diff --git a/src/Launcher/Launcher_Job_YACSFile.cxx b/src/Launcher/Launcher_Job_YACSFile.cxx index 3150c0342..6f2366567 100644 --- a/src/Launcher/Launcher_Job_YACSFile.cxx +++ b/src/Launcher/Launcher_Job_YACSFile.cxx @@ -100,6 +100,11 @@ Launcher::Job_YACSFile::buildSalomeCouplingScript(Batch::Parametre params) // Begin of script launch_script_stream << "#! /bin/sh -f" << std::endl; launch_script_stream << "cd " << work_directory << std::endl; + if (_env_file != "") + { + std::string::size_type last = _env_file.find_last_of("/"); + launch_script_stream << "source ./" << _env_file.substr(last+1) << std::endl; + } launch_script_stream << "export SALOME_TMP_DIR=" << work_directory << "/logs" << std::endl; // -- Generates Catalog Resources diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 3b5a30bf6..b6331bd0d 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -68,7 +68,6 @@ SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa _NS->Register(refContMan,_LauncherNameInNS); - _job_cpt = 0; MESSAGE("SALOME_Launcher constructor end"); } @@ -214,9 +213,6 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters) } Launcher::Job_Command * job = new Launcher::Job_Command(command); new_job = job; - - std::string env_file = job_parameters.env_file.in(); - job->setEnvFile(env_file); } else if (job_type == "yacs_file") { @@ -228,11 +224,6 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters) } new_job = new Launcher::Job_YACSFile(yacs_file); } - - // Not thread safe... TODO ! - new_job->setNumber(_job_cpt); - _job_cpt++; - // End Not thread safe // Directories std::string work_directory = job_parameters.work_directory.in(); @@ -243,6 +234,8 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters) new_job->setResultDirectory(result_directory); // Files + std::string env_file = job_parameters.env_file.in(); + new_job->setEnvFile(env_file); for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++) new_job->add_in_file(job_parameters.in_files[i].in()); for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++) diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index b574b1681..8f463a9f9 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -80,8 +80,6 @@ protected: SALOME_ResourcesManager *_ResManager; SALOME_NamingService *_NS; - int _job_cpt; - Launcher_cpp _l; };