loadleveller.h 1.63 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 &mccreator, int, char **) {
11
12
	for(size_t task_id = 0; task_id < job.task_names.size(); task_id++) {
		std::vector<evalable> evalables;
Lukas Weber's avatar
Lukas Weber committed
13
		std::unique_ptr<mc> sys{mccreator(job.jobfile[job.task_names[task_id]])};
14
15
16
17
		sys->register_evalables(evalables);
		job.merge_task(task_id, evalables);

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

20
21
	return 0;
}
22

23
24
25
26
27
28
29
30
31
inline int run_mc(int (*starter)(jobinfo job, const mc_factory &, int argc, char **argv),
                  mc_factory mccreator, int argc, char **argv) {
	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;
32
33
	}

34
35
	std::string jobfile{argv[1]};
	jobinfo job{jobfile};
36

37
	int rc = starter(job, mccreator, argc, argv);
38

39
40
41
42
43
44
45
	job.concatenate_results();
	return rc;
}

// run this function from main() in your code.
template<class mc_implementation>
int run(int argc, char **argv) {
Lukas Weber's avatar
wrong &    
Lukas Weber committed
46
	auto mccreator = [&](const parser &p) -> mc * { return new mc_implementation{p}; };
47
48
49
50
51

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

	return run_mc(runner_mpi_start, mccreator, argc, argv);
}
56
}