Commit 6f9d664e authored by Lukas Weber's avatar Lukas Weber
Browse files

only read jobfile once

parent e3c3cc8a
......@@ -50,15 +50,15 @@ def run():
label = 'Warning' if args_run.force else 'Error'
if binary_modtime > data_modtime:
print('{}: binary \'{}\' is newer than the checkpoint files.'.format(label, job.mc_binary))
if not args.force:
print('{}: binary \'{}\' is newer than the checkpoint files.'.format(label, job.jobconfig['mc_binary']))
if not args_run.force:
print('Use \'--restart\' to start from a blank run or use \'--force\' to proceed if you are sure\nthe changes you made are compatible.')
sys.exit(1)
except StopIteration:
pass
if args_run.single:
cmd = [job.mc_binary, 'single', jobname]
cmd = [job.jobconfig['mc_binary'], 'single', job.jobname]
print('$ '+' '.join(cmd))
subprocess.run(cmd)
else:
......@@ -66,10 +66,15 @@ def run():
def delete():
import shutil
print('$ rm -r {}.data'.format(job.jobname))
shutil.rmtree('{}.data'.format(job.jobname))
print('$ rm -r {}.results.yml'.format(job.jobname))
shutil.rmtree('{}.results.yml'.format(job.jobname))
datadir = '{}.data'.format(job.jobname)
results_file = '{}.results.yml'.format(job.jobname)
if os.path.exists(datadir):
print('$ rm -r {}'.format(datadir))
shutil.rmtree(datadir)
if os.path.exists(results_file):
print('$ rm {}'.format(results_file))
os.unlink(results_file)
def merge():
cmd = [job.jobconfig['mc_binary'], 'merge', job.jobname]
......@@ -78,7 +83,7 @@ def merge():
def status():
from loadleveller import jobstatus
rc = jobstatus.print_status(job, sys.args[3:])
rc = jobstatus.print_status(job, sys.argv[3:])
sys.exit(rc)
......
......@@ -70,7 +70,7 @@ def print_status(jobfile, args):
parser.add_argument('--need-restart', action='store_true', help='Return 1 if the job is not completed yet and 0 otherwise.')
parser.add_argument('--need-merge', action='store_true', help='Return 1 if the merged results are older than the raw data and 0 otherwise.')
args = parser.parse_args()
args = parser.parse_args(args)
try:
job_prog = JobProgress(jobfile)
......
......@@ -10,7 +10,7 @@ namespace loadl {
inline int merge_only(jobinfo job, const mc_factory &mccreator, int, char **) {
for(size_t task_id = 0; task_id < job.task_names.size(); task_id++) {
std::vector<evalable> evalables;
std::unique_ptr<mc> sys{mccreator(job.jobname, job.task_names[task_id])};
std::unique_ptr<mc> sys{mccreator(job.jobfile[job.task_names[task_id]])};
sys->register_evalables(evalables);
job.merge_task(task_id, evalables);
......@@ -43,8 +43,8 @@ inline int run_mc(int (*starter)(jobinfo job, const mc_factory &, int argc, char
// run this function from main() in your code.
template<class mc_implementation>
int run(int argc, char **argv) {
auto mccreator = [&](const std::string &jobfile, const std::string &taskname) -> mc * {
return new mc_implementation(jobfile, taskname);
auto mccreator = [&](const &parser p) -> mc * {
return new mc_implementation{p};
};
if(argc > 1 && std::string(argv[1]) == "merge") {
......
......@@ -2,8 +2,8 @@
namespace loadl {
mc::mc(const std::string &jobfile, const std::string &taskname)
: param{parser{jobfile}["tasks"][taskname]} {
mc::mc(const parser &p)
: param{p} {
therm_ = param.get<int>("thermalization");
}
......
......@@ -48,9 +48,9 @@ public:
bool is_thermalized();
measurements measure;
mc(const std::string &jobfile, const std::string &taskname);
mc(const parser& p);
virtual ~mc() = default;
};
typedef std::function<mc *(const std::string &, const std::string &)> mc_factory;
typedef std::function<mc *(const parser&)> mc_factory;
}
......@@ -54,7 +54,7 @@ parser::iterator parser::end() {
return iterator{filename_, content_.end()};
}
bool parser::defined(const std::string &key) {
bool parser::defined(const std::string &key) const {
if(!content_.IsMap()) {
return false;
}
......
......@@ -47,7 +47,7 @@ public:
}
// is key defined?
bool defined(const std::string &key);
bool defined(const std::string &key) const;
parser operator[](const std::string &key);
iterator begin();
......
......@@ -297,7 +297,7 @@ void runner_slave::start() {
int action = what_is_next(S_IDLE);
while(action != A_EXIT) {
if(action == A_NEW_JOB) {
sys_ = std::unique_ptr<mc>{mccreator_(job_.jobname, job_.task_names[task_id_])};
sys_ = std::unique_ptr<mc>{mccreator_(job_.jobfile[job_.task_names[task_id_]])};
if(!sys_->_read(job_.rundir(task_id_, run_id_))) {
sys_->_init();
// checkpointing();
......
......@@ -25,7 +25,7 @@ int runner_single::start() {
read();
task_id_ = get_new_task_id(task_id_);
while(task_id_ != -1 && !time_is_up()) {
sys_ = std::unique_ptr<mc>{mccreator_(job_.jobname, job_.task_names.at(task_id_))};
sys_ = std::unique_ptr<mc>{mccreator_(job_.jobfile[job_.task_names.at(task_id_)])};
if(!sys_->_read(job_.rundir(task_id_, 1))) {
sys_->_init();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment