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 462 : void WriteMetaData(std::string plot_file, Status status, int per)
18 : {
19 462 : if (amrex::ParallelDescriptor::IOProcessor())
20 : {
21 462 : amrex::ParmParse pp;
22 :
23 462 : std::chrono::time_point<std::chrono::system_clock> now_cr = std::chrono::system_clock::now();
24 462 : std::time_t now = std::chrono::system_clock::to_time_t(now_cr);
25 :
26 462 : if (!starttime)
27 : {
28 52 : starttime_cr = now_cr;
29 52 : starttime = now;
30 : }
31 :
32 462 : if (!hash)
33 : {
34 52 : std::stringstream ss;
35 52 : pp.dumpTable(ss);
36 52 : std::string dumptable = ss.str();
37 52 : hash = std::hash<std::string>{}(dumptable + std::ctime(&starttime));
38 52 : }
39 :
40 462 : if (per > percent) percent = per;
41 :
42 462 : std::ofstream metadatafile;
43 462 : metadatafile.open(plot_file+"/metadata",std::ios_base::out);
44 462 : metadatafile << "# COMPILATION DETAILS" << std::endl;
45 462 : metadatafile << "# ===================" << std::endl;
46 462 : metadatafile << "Git_commit_hash = " << METADATA_GITHASH << std::endl;
47 462 : metadatafile << "AMReX_version = " << amrex::Version() << std::endl;
48 462 : metadatafile << "Dimension = " << AMREX_SPACEDIM << std::endl;
49 462 : metadatafile << "User = " << METADATA_USER << std::endl;
50 462 : metadatafile << "Platform = " << METADATA_PLATFORM << std::endl;
51 462 : metadatafile << "Compiler = " << METADATA_COMPILER << std::endl;
52 462 : metadatafile << "Compilation_Date = " << METADATA_DATE << std::endl;
53 462 : metadatafile << "Compilation_Time = " << METADATA_TIME << std::endl;
54 462 : metadatafile << std::endl;
55 :
56 462 : metadatafile << "# PARAMETERS" << std::endl;
57 462 : metadatafile << "# ==========" << std::endl;
58 :
59 462 : pp.dumpTable(metadatafile,true);
60 :
61 462 : metadatafile << "# RUN DETAILS" << std::endl;
62 462 : metadatafile << "# ===========" << std::endl;
63 462 : metadatafile << "HASH = " << hash << std::endl;
64 : {
65 : char buffer [80];
66 462 : std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&starttime));
67 462 : std::string timefmt(buffer);
68 462 : metadatafile << "Simulation_start_time = " << timefmt << std::endl;
69 462 : }
70 462 : metadatafile << "Number_of_processors = " << amrex::ParallelDescriptor::NProcs() << std::endl;
71 462 : if (status == Status::Running) metadatafile << "Status = Running";
72 102 : 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 462 : if (percent>0) metadatafile << " (" << percent << "%)";
78 462 : metadatafile << std::endl;
79 :
80 462 : if (status != Status::Running)
81 : {
82 : char buffer[80];
83 102 : std::strftime(buffer,80,"%Y-%m-%d %H:%M:%S",std::localtime(&now));
84 102 : std::string timefmt(buffer);
85 102 : metadatafile << "Simulation_end_time = " << timefmt << std::endl;
86 102 : }
87 :
88 462 : auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now_cr - starttime_cr);
89 462 : 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 462 : std::ifstream src(GIT_DIFF_PATCH_OUTPUT,std::ios::binary);
102 462 : if (src.is_open())
103 : {
104 462 : std::ofstream dst(plot_file+"/diff.patch",std::ios::binary);
105 462 : dst << src.rdbuf();
106 462 : src.close();
107 462 : dst.close();
108 462 : }
109 : else
110 : {
111 0 : Util::Warning(INFO,"Could not open ",GIT_DIFF_PATCH_OUTPUT);
112 : }
113 :
114 462 : }
115 :
116 462 : metadatafile.close();
117 462 : }
118 462 : }
119 :
120 : }
|