load_leveller.h 1.67 KB
Newer Older
1
2
#pragma once

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

namespace load_leveller {
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	inline int merge_only(jobinfo job, const mc_factory& mccreator, int argc, char **argv) {
		for(size_t task_id = 0; task_id < job.task_names.size(); task_id++) {
			std::vector<evalable> evalables;
			std::unique_ptr<abstract_mc> sys{mccreator(job.jobfile_name, job.task_names[task_id])};
			sys->register_evalables(evalables);
			job.merge_task(task_id, evalables);

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

		return 0;
	}
	
	inline int run_mc(int (*starter)(jobinfo job, const mc_factory&, int argc, char **argv), mc_factory mccreator, int argc, char **argv) {
Lukas Weber's avatar
Lukas Weber committed
23
24
		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]);
25
26
27
			return -1;
		}

Lukas Weber's avatar
Lukas Weber committed
28
		std::string jobfile{argv[1]};
29
		jobinfo job{jobfile};
30

31
		return starter(std::move(job), mccreator, argc, argv);
32
33
34
35
36
	}

	// run this function from main() in your code.
	template <class mc_implementation>
	int run(int argc, char **argv) {
Lukas Weber's avatar
Lukas Weber committed
37
		auto mccreator = [&] (const std::string& jobfile, const std::string& taskname) -> abstract_mc* {return new mc_implementation(jobfile, taskname);};
38

Lukas Weber's avatar
Lukas Weber committed
39
		if(argc > 1 && std::string(argv[1]) == "merge") {
40
41
			
			return run_mc(merge_only, mccreator, argc-1, argv+1);
Lukas Weber's avatar
Lukas Weber committed
42
		} else if(argc > 1 && std::string(argv[1]) == "single") {
43
			return run_mc(runner_single_start, mccreator, argc-1, argv+1);
44
45
		}

46
		return run_mc(runner_mpi_start, mccreator, argc, argv);
47
48
	}
}