Line data Source code
1 : #include "WriteMetaData.H"
2 : #include <sstream>
3 : #include <functional>
4 : #include "Util/Util.H"
5 :
6 : /// \todo We need to update ParmParse so that the FORMATTED input file gets recorded permanently.
7 :
8 : namespace IO
9 : {
10 :
11 : // GLOBAL VARIABLES
12 : unsigned long hash = 0;
13 : std::chrono::time_point<std::chrono::system_clock> starttime_cr;
14 : std::time_t starttime = 0;
15 : int percent = -1;
16 :
17 306 : void WriteMetaData(std::string plot_file, Status status, int per)
18 : {
19 306 : if (amrex::ParallelDescriptor::IOProcessor())
20 : {
21 306 : amrex::ParmParse pp;
22 :
23 306 : std::chrono::time_point<std::chrono::system_clock> now_cr = std::chrono::system_clock::now();
24 306 : std::time_t now = std::chrono::system_clock::to_time_t(now_cr);
25 :
26 306 : if (!starttime)
27 : {
28 39 : starttime_cr = now_cr;
29 39 : starttime = now;
30 : }
31 :
32 306 : if (!hash)
33 : {
34 39 : std::stringstream ss;
35 39 : pp.dumpTable(ss);
36 39 : std::string dumptable = ss.str();
37 39 : hash = std::hash<std::string>{}(dumptable + std::ctime(&starttime));
38 39 : }
39 :
40 306 : if (per > percent) percent = per;
41 :
42 306 : std::ofstream metadatafile;
43 306 : metadatafile.open(plot_file+"/metadata",std::ios_base::out);
44 306 : metadatafile << "# COMPILATION DETAILS" << std::endl;
45 306 : metadatafile << "# ===================" << std::endl;
46 306 : metadatafile << "Git_commit_hash = " << METADATA_GITHASH << std::endl;
47 306 : metadatafile << "AMReX_version = " << amrex::Version() << std::endl;
48 306 : metadatafile << "Dimension = " << AMREX_SPACEDIM << std::endl;
49 306 : metadatafile << "User = " << METADATA_USER << std::endl;
50 306 : metadatafile << "Platform = " << METADATA_PLATFORM << std::endl;
51 306 : metadatafile << "Compiler = " << METADATA_COMPILER << std::endl;
52 306 : metadatafile << "Compilation_Date = " << METADATA_DATE << std::endl;
53 306 : metadatafile << "Compilation_Time = " << METADATA_TIME << std::endl;
54 306 : metadatafile << std::endl;
55 :
56 306 : metadatafile << "# PARAMETERS" << std::endl;
57 306 : metadatafile << "# ==========" << std::endl;
58 :
59 306 : pp.dumpTable(metadatafile,true);
60 :
61 306 : metadatafile << "# RUN DETAILS" << std::endl;
62 306 : metadatafile << "# ===========" << std::endl;
63 306 : metadatafile << "HASH = " << hash << std::endl;
64 : {
65 : char buffer [80];
66 306 : std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&starttime));
67 306 : std::string timefmt(buffer);
68 306 : metadatafile << "Simulation_start_time = " << timefmt << std::endl;
69 306 : }
70 306 : metadatafile << "Number_of_processors = " << amrex::ParallelDescriptor::NProcs() << std::endl;
71 306 : if (status == Status::Running) metadatafile << "Status = Running";
72 76 : else if (status == Status::Complete) metadatafile << "Status = Complete";
73 0 : else if (status == Status::Abort) metadatafile << "Status = Abort";
74 0 : else if (status == Status::Segfault) metadatafile << "Status = Segfault";
75 0 : else if (status == Status::Interrupt) metadatafile << "Status = Interrupt";
76 :
77 306 : if (percent>0) metadatafile << " (" << percent << "%)";
78 306 : metadatafile << std::endl;
79 :
80 306 : if (status != Status::Running)
81 : {
82 : char buffer[80];
83 76 : std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&now));
84 76 : std::string timefmt(buffer);
85 76 : metadatafile << "Simulation_end_time = " << timefmt << std::endl;
86 76 : }
87 :
88 306 : auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now_cr - starttime_cr);
89 306 : metadatafile << "Simulation_run_time = " << (float)milliseconds.count()/1000.0 << " " << std::endl;
90 :
91 : #ifdef GIT_DIFF_OUTPUT
92 : {
93 : std::ifstream src(GIT_DIFF_OUTPUT,std::ios::binary);
94 : std::ofstream dst(plot_file+"/diff.html",std::ios::binary);
95 : dst << src.rdbuf();
96 : src.close();
97 : dst.close();
98 : }
99 : #endif
100 : {
101 306 : std::ifstream src(GIT_DIFF_PATCH_OUTPUT,std::ios::binary);
102 306 : if (src.is_open())
103 : {
104 306 : std::ofstream dst(plot_file+"/diff.patch",std::ios::binary);
105 306 : dst << src.rdbuf();
106 306 : src.close();
107 306 : dst.close();
108 306 : }
109 : else
110 : {
111 0 : Util::Warning(INFO,"Could not open ",GIT_DIFF_PATCH_OUTPUT);
112 : }
113 :
114 306 : }
115 :
116 306 : metadatafile.close();
117 306 : }
118 306 : }
119 :
120 : }
|