KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1#include <gflags/gflags.h>
2#include <glog/logging.h>
3// #include <gperftools/profiler.h>
4
5#include <iomanip>
6#include <iostream>
7
8#include "Handler.h"
9#include "ghc/filesystem.hpp"
10#include "kids/Param.h"
11#include "version.h"
12
13DEFINE_bool(w, false, "Enables rewritting the output");
14DEFINE_string(p, "param.json", "paramemter inputs");
15
16DEFINE_string(handler, //
17 "parallel", //
18 "Specifies the handler type"
19 "\n[parallel | single | single_mpi | sampling | help | help_param | help_dataset ]");
20DEFINE_string(d, "default", "Specifies the output directory");
21DEFINE_string(load, "", "Specifies the dataset file to load");
22DEFINE_string(dump, "", "Specifies the dataset file to dump");
23DEFINE_double(backup_time, -1.0, "Specifies the timestep for backup (/1h)");
24DEFINE_bool(timing, false, "Enables profiling for time costs");
25
26using namespace PROJECT_NS;
27namespace fs = ghc::filesystem;
28
29int main(int argc, char* argv[]) {
30 /* profiling settings */
31 // ProfilerStart("demo.prof");
32
33 // plSetFilename("record.pltraw");
34 // plInitAndStart("opendf", PL_MODE_STORE_IN_FILE);
35 // plDeclareThread("Main");
36
37 /* setup gflags */
38 gflags::SetVersionString(repo_version);
39 gflags::SetUsageMessage("Kernel Integrated Dynamics Simulator");
40 gflags::ParseCommandLineFlags(&argc, &argv, true);
41
42 /* read parameter file (json format) */
43 std::shared_ptr<Param> PM = std::shared_ptr<Param>(new Param(FLAGS_p, Param::fromFile));
44 auto&& j = *(PM->pjson());
45
46 j["directory"] = FLAGS_d;
47 j["timing"] = FLAGS_timing;
48 j["handler"] = FLAGS_handler;
49 j["backup_time"] = FLAGS_backup_time;
50 if (FLAGS_load != "") j["load"] = FLAGS_load;
51 if (FLAGS_dump != "") j["dump"] = FLAGS_dump;
52
53 /* creat directory for simulation */
54 if (fs::exists(FLAGS_d) && FLAGS_w == false) {
55 throw std::runtime_error(
56 utils::concat("Working directory = [", FLAGS_d, "] already exists. Please specify -w to force start.\n"));
57 }
58 try {
59 fs::create_directory(FLAGS_d); // sometime it raise bugs
60 } catch (std::runtime_error& e) {
61 throw std::runtime_error("create_directory failed");
62 std::cout << "some error!!!\n";
63 }
64
65 if (j.count("model_file") > 0 && j.count("model_id") > 0) {
66 Param TEMP(j["model_file"].as_string(), Param::fromFile);
67 j["model_param"] = (*(TEMP.pjson()))[j["model_id"].as_string()];
68 }
69 if (j.count("solver_file") > 0 && j.count("solver_id") > 0) {
70 Param TEMP(j["solver_file"].as_string(), Param::fromFile);
71 j["solver_param"] = (*(TEMP.pjson()))[j["solver_id"].as_string()];
72 }
73
74 /* setup glog */
75 google::InitGoogleLogging(argv[0]);
76 google::SetStderrLogging(google::GLOG_INFO);
77 google::SetLogDestination(google::GLOG_INFO, utils::concat("./", FLAGS_d, "/").c_str());
78 google::SetLogFilenameExtension(".log");
79 // FLAGS_timestamp_in_logfile_name = false;
80 // FLAGS_log_prefix = false;
81 // FLAGS_colorlogtostderr = true; // Set log color
82 FLAGS_logtostderr = 0;
83 FLAGS_alsologtostderr = 0;
84 FLAGS_logbufsecs = 0; // Set log output speed(s)
85 FLAGS_max_log_size = 5; // Set max log file size
86 FLAGS_stop_logging_if_full_disk = true; // If disk is full
87
88 /* task block */
89 std::string model_name = PM->get_string("model", LOC());
90 std::string solver_name = PM->get_string("solver", LOC());
91 std::string handler_name = PM->get_string("handler", LOC(), "single");
92
93 Handler myhandler = Handler(solver_name, model_name);
94 myhandler.run(PM);
95
96 /* finalize */
97 gflags::ShutDownCommandLineFlags();
98 google::ShutdownGoogleLogging();
99
100 // ProfilerStop();
101 // plStopAndUninit();
102
103 return 0;
104}
Provide struct and interfaces for input parameters.
this class provides a control of simulation
Definition Handler.h:13
int run(std::shared_ptr< Param > &PM)
Definition Handler.cpp:23
this class provides an interface wrapper for the parameter data.
Definition Param.h:82
@ fromFile
construct Param from file
Definition Param.h:91
std::shared_ptr< JSON > pjson()
Definition Param.cpp:44
#define LOC()
show the location information for debug
Definition fmt.h:49
int main(int argc, char *argv[])
Definition main.cc:29
DEFINE_string(p, "param.json", "paramemter inputs")
DEFINE_double(backup_time, -1.0, "Specifies the timestep for backup (/1h)")
DEFINE_bool(w, false, "Enables rewritting the output")
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)
Definition concat.h:242
const std::string repo_version
Definition version.h:8