KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Context.h
Go to the documentation of this file.
1
28#ifndef KIDS_Context_H
29#define KIDS_Context_H
30
31#include "kids/DataSet.h"
32#include "kids/Model.h"
33#include "kids/Param.h"
34#include "kids/Platform.h"
35#include "kids/RuleSet.h"
36#include "kids/Solver.h"
37#include "kids/System.h"
38
39namespace PROJECT_NS {
40
41class Context {
42 std::shared_ptr<Param> getParam() { return _param; }
43 std::shared_ptr<DataSet> getDataSet() { return _dataset; }
44 std::shared_ptr<RuleSet> getRuleSet() { return _ruleset; }
45 std::shared_ptr<System> getSystem() { return _system; }
46 std::shared_ptr<Model> getModel() { return _model; }
47 std::vector<std::shared_ptr<Solver>> getSolvers() { return _solvers; }
48 std::shared_ptr<Platform> getPlatfrom() { return _platform; }
49
51 auto begin = std::chrono::steady_clock::now();
52 Status stat;
53 {
54 for (auto& solver : _solvers) solver->setInputParam(_param);
55 for (auto& solver : _solvers) solver->setInputDataSet(_dataset);
56 solver->initializeKernel(stat); // @necessary?
57
58 // get Monte Carlo Dimension from Param
59 int M = PM->get_int("M", LOC(), 1);
60 std::string directory = PM->get_string("directory", LOC(), "default");
61 MPI_Guard guard(M);
62 MPI_Barrier(MPI_COMM_WORLD);
63 for (int icalc = guard.istart; icalc < guard.iend; ++icalc) {
64 stat.icalc = icalc;
65 solver->initializeKernel(stat);
66 solver->executeKernel(stat);
67 solver->finalizeKernel(stat);
68 }
69 MPI_Barrier(MPI_COMM_WORLD);
70
71 auto collect = solver->getRuleSet()->getResult(1).data();
72 auto reduced = solver->getRuleSet()->getResult(2).data();
73 for (int i = 0; i < collect.size(); ++i) {
74 std::cout << std::get<0>(collect[i]) << "\n";
75 std::cout << std::get<0>(reduced[i]) << "\n";
76 auto [key1, from_data, type1, size1, nframe1] = collect[i];
77 auto [key2, to_data, type2, size2, nframe2] = reduced[i];
78 MPI_Guard::reduce(std::make_tuple(type1, from_data, to_data, size1));
79 }
80 // report time cost
81 if (MPI_Guard::isroot) RuleSet::flush_all(directory, 2);
82 }
83 auto end = std::chrono::steady_clock::now();
84 double total_time = static_cast<std::chrono::duration<double>>(end - begin).count();
85 }
86
87 private:
88 std::shared_ptr<Param> _param;
89 std::shared_ptr<DataSet> _dataset;
90 std::shared_ptr<RuleSet> _ruleset;
91 std::shared_ptr<System> _system;
92 std::shared_ptr<Model> _model;
93 std::vector<std::shared_ptr<Solver>> _solver;
94 std::shared_ptr<Platform> _platform;
95};
96}; // namespace PROJECT_NS
97
98#endif // KIDS_Context_H
Declaration of the DataSet class and related classes.
Provide struct and interfaces for input parameters.
provide RuleSet class
provide Solver class
provide System class
std::shared_ptr< RuleSet > _ruleset
Definition Context.h:90
std::shared_ptr< System > _system
Definition Context.h:91
std::vector< std::shared_ptr< Solver > > _solver
Definition Context.h:93
std::shared_ptr< RuleSet > getRuleSet()
Definition Context.h:44
std::shared_ptr< DataSet > getDataSet()
Definition Context.h:43
std::vector< std::shared_ptr< Solver > > getSolvers()
Definition Context.h:47
std::shared_ptr< Param > _param
Definition Context.h:88
std::shared_ptr< DataSet > _dataset
Definition Context.h:89
std::shared_ptr< System > getSystem()
Definition Context.h:45
std::shared_ptr< Platform > getPlatfrom()
Definition Context.h:48
std::shared_ptr< Model > _model
Definition Context.h:92
std::shared_ptr< Platform > _platform
Definition Context.h:94
Status execute()
Definition Context.h:50
std::shared_ptr< Model > getModel()
Definition Context.h:46
std::shared_ptr< Param > getParam()
Definition Context.h:42
static int reduce(const std::tuple< kids_dtype, void *, void *, std::size_t > &info)
static void flush_all(const std::string &path, int level)
Flush data to all output files.
Definition RuleSet.cpp:42
#define LOC()
show the location information for debug
Definition fmt.h:49
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39