#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);
}
//=============================================================================
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;
}
//=============================================================================
}
}
+
// 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<int, Launcher::Job *>::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;
#include <string>
#include <vector>
+#include <pthread.h>
+
class MpiImpl;
namespace Batch{
//! 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
_state = "CREATED";
_launch_date = getLaunchDate();
+ _env_file = "";
_work_directory = "";
_local_directory = "";
_result_directory = "";
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)
{
if (_result_directory == "")
_result_directory = getenv("HOME");
+ //Env file
+ if (_env_file != "")
+ add_in_file(_env_file);
+
// _in_files
for(std::list<std::string>::iterator it = _in_files.begin(); it != _in_files.end(); it++)
{
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();
std::string getMaximumDuration();
machineParams getMachineRequiredParams();
std::string getQueue();
+ std::string getEnvFile();
std::string updateJobState();
std::string _state;
std::string _launch_date;
+ std::string _env_file;
ParserResourcesType _machine_definition;
Launcher::Job_Command::Job_Command(const std::string & command)
{
_command = command;
- _env_file = "";
}
Launcher::Job_Command::~Job_Command() {}
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()
{
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
// Specific parameters
void setCommand(const std::string & command);
std::string getCommand();
- void setEnvFile(std::string & env_file);
- std::string getEnvFile();
virtual void update_job();
private:
std::string _command;
- std::string _env_file;
};
}
// 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
_NS->Register(refContMan,_LauncherNameInNS);
- _job_cpt = 0;
MESSAGE("SALOME_Launcher constructor end");
}
}
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")
{
}
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();
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++)
SALOME_ResourcesManager *_ResManager;
SALOME_NamingService *_NS;
- int _job_cpt;
-
Launcher_cpp _l;
};