loadleveller.h 1.77 KB
Newer Older
1
2
#pragma once

3
#include "mc.h"
Lukas Weber's avatar
Lukas Weber committed
4
#include "merger.h"
5
6
7
#include "runner.h"
#include "runner_single.h"

8
9
namespace loadl {

10
inline int merge_only(jobinfo job, const mc_factory &, int, char **) {
11
	for(size_t task_id = 0; task_id < job.task_names.size(); task_id++) {
12
		job.merge_task(task_id);
13
14

		std::cout << fmt::format("-- {} merged\n", job.taskdir(task_id));
15
	}
16

17
18
	return 0;
}
19

20
21
22
template <typename mc_implementation>
int run_mc(int (*starter)(jobinfo job, const mc_factory &, int argc, char **argv),
                  int argc, char **argv) {
23
24
25
26
27
28
29
	if(argc < 2) {
		std::cerr << fmt::format(
		    "{0} JOBFILE\n{0} single JOBFILE\n{0} merge JOBFILE\n\n Without further flags, the MPI "
		    "scheduler is started. 'single' starts a single core scheduler (useful for debugging), "
		    "'merge' merges unmerged measurement results.\n",
		    argv[0]);
		return -1;
30
31
	}

32
	std::string jobfile{argv[1]};
33
34
35
	auto mccreator = [&](const parser &p) -> mc * { return new mc_implementation{p}; };

	jobinfo job{jobfile, &mc_implementation::register_evalables};
36

Lukas Weber's avatar
Lukas Weber committed
37
38
39
40
41
	// bad hack because hdf5 locking features will happily kill your
	// production run in the middle of writing measurements if you block
	// a writing lock by reading some measurement files.
	setenv("HDF5_USE_FILE_LOCKING", "FALSE", 1);

42
	int rc = starter(job, mccreator, argc, argv);
43

44
45
46
47
48
49
50
51
52
	job.concatenate_results();
	return rc;
}

// run this function from main() in your code.
template<class mc_implementation>
int run(int argc, char **argv) {

	if(argc > 1 && std::string(argv[1]) == "merge") {
53
		return run_mc<mc_implementation>(merge_only, argc - 1, argv + 1);
54
	} else if(argc > 1 && std::string(argv[1]) == "single") {
55
		return run_mc<mc_implementation>(runner_single_start, argc - 1, argv + 1);
56
	}
57

58
	return run_mc<mc_implementation>(runner_mpi_start, argc, argv);
59
}
60
}